TreeKey Class Reference

#include <treekey.h>

Inheritance diagram for TreeKey:
Inheritance graph
[legend]
Collaboration diagram for TreeKey:
Collaboration graph
[legend]

List of all members.

Classes

class  PositionChangeListener

Public Member Functions

virtual void append ()=0
virtual void appendChild ()=0
virtual void assureKeyPath (const char *keyPath=0)
virtual void clearBound () const
virtual SWKeyclone () const
virtual int compare (const SWKey &ikey)
virtual int compare (const SWKey &ikey)=0
virtual void copyFrom (const SWKey &ikey)
virtual void decrement (int steps=1)=0
virtual bool equals (const SWKey &ikey)
SWDEPRECATED char Error ()
virtual bool firstChild ()=0
const SWClassgetClass () const
virtual long getIndex () const
virtual int getLevel ()
char * getLocale () const
virtual const char * getLocalName ()=0
virtual unsigned long getOffset () const =0
virtual const char * getOSISRefRangeText () const
virtual const char * getRangeText () const
virtual const char * getShortText () const
virtual const char * getText () const =0
virtual const char * getUserData (int *size=0) const =0
virtual bool hasChildren ()=0
virtual void increment (int steps=1)=0
virtual void insertBefore ()=0
virtual bool isBoundSet () const
bool isPersist () const
virtual bool isTraversable () const
virtual bool nextSibling ()=0
virtual bool parent ()=0
SWDEPRECATED char Persist (signed char ipersist)
SWDEPRECATED char Persist () const
virtual char popError ()
virtual void positionFrom (const SWKey &ikey)
virtual bool previousSibling ()=0
virtual void remove ()=0
virtual void root ()=0
virtual void save ()
virtual void setError (char err)
virtual void setIndex (long iindex)
void setLocale (const char *name)
virtual const char * setLocalName (const char *)=0
virtual void setOffset (unsigned long offset)=0
void setPersist (bool ipersist)
virtual void setPosition (SW_POSITION p)=0
void setPositionChangeListener (PositionChangeListener *pcl)
virtual void setText (const char *ikey)=0
virtual void setUserData (const char *userData, int size=0)=0
 TreeKey ()
 ~TreeKey ()

Public Attributes

class
TreeKey::PositionChangeListener
posChangeListener
__u64 userData

Protected Member Functions

SWLocalegetPrivateLocale () const
void positionChanged ()

Protected Attributes

bool boundSet
char error
char * keytext
char * localeName
SWClassmyclass
bool persist
char * rangeText
SWBuf unsnappedKeyText

Private Member Functions

void init ()

Static Private Attributes

static SWClass classdef

Detailed Description

Class TreeKey The base class for all tree-based key implementations in Sword.

Definition at line 37 of file treekey.h.


Constructor & Destructor Documentation

TreeKey::TreeKey (  )  [inline]

Definition at line 68 of file treekey.h.

00068 { init(); };

TreeKey::~TreeKey (  )  [inline]

Definition at line 69 of file treekey.h.

00069 {};


Member Function Documentation

virtual void TreeKey::append (  )  [pure virtual]

Implemented in TreeKeyIdx.

virtual void TreeKey::appendChild (  )  [pure virtual]

Implemented in TreeKeyIdx.

void TreeKey::assureKeyPath ( const char *  keyPath = 0  )  [virtual]

Set the key to this path. If the path doesn't exist, then nodes are created as necessary

Parameters:
keyPath path to set/create; if unsupplied, then use any unsnapped setText value.

Definition at line 39 of file treekey.cpp.

00039                                                  {
00040 
00041     if (!keyBuffer) {
00042         keyBuffer = unsnappedKeyText;
00043         //assert we have something to do before setting root
00044         if (!*keyBuffer)
00045             return;
00046     }
00047 
00048     char *keybuf = 0;
00049     stdstr(&keybuf, keyBuffer);
00050 
00051     root();
00052 
00053     // TODO: change to NOT use strtok. strtok is dangerous.
00054     SWBuf tok = strtok(keybuf, "/");
00055     tok.trim();
00056     while (tok.size()) {
00057         bool foundkey = false;
00058         if (hasChildren()) {
00059             firstChild();
00060             if (tok == getLocalName()) {
00061                 foundkey = true;
00062             }
00063             else {
00064                 while (nextSibling()) {
00065                     if (getLocalName()) {
00066                         if (tok == getLocalName()) {
00067                             foundkey = true;
00068                             break;
00069                         }
00070                     }
00071                 }
00072             }
00073             if (!foundkey) {
00074                 append();
00075                 setLocalName(tok);
00076                 save();     
00077             }
00078         }
00079         else {
00080             appendChild();
00081             setLocalName(tok);
00082             save();
00083         }
00084 
00085 #ifdef DEBUG
00086 //      std::cout << getLocalName() << " : " << tok << std::endl;
00087 #endif
00088 
00089         tok = strtok(0, "/");
00090         tok.trim();
00091 
00092     }
00093     delete [] keybuf;
00094 }

virtual void SWKey::clearBound (  )  const [inline, virtual, inherited]

Definition at line 181 of file swkey.h.

00181 { boundSet = false; }

SWKey * SWKey::clone (  )  const [virtual, inherited]

Returns a new exact clone of this SWKey object. This allocates a new SWKey which must be deleted by the caller

Returns:
new clone of this key

Reimplemented in ListKey, TreeKeyIdx, VerseKey, and VerseTreeKey.

Definition at line 74 of file swkey.cpp.

00075 {
00076     return new SWKey(*this);
00077 }

int SWKey::compare ( const SWKey ikey  )  [virtual, inherited]

Compares this key object to another SWKey object

Parameters:
ikey key to compare with this one
Returns:
>0 if this key is greater than compare key; <0 if this key is smaller than compare key; 0 if the keys are the same

Definition at line 217 of file swkey.cpp.

00218 {
00219     return strcmp((const char *)*this, (const char *)ikey);
00220 }

virtual int TreeKey::compare ( const SWKey ikey  )  [pure virtual]

Implemented in TreeKeyIdx.

void SWKey::copyFrom ( const SWKey ikey  )  [virtual, inherited]

Copies as much info (position, range, etc.) as possible from another SWKey object

Parameters:
ikey other SWKey object from which to copy

Reimplemented in ListKey, TreeKeyIdx, and VerseKey.

Definition at line 172 of file swkey.cpp.

00172                                       {
00173 // not desirable    Persist(ikey.Persist());
00174     setLocale(ikey.getLocale());
00175     setText((const char *)ikey);
00176 }

virtual void TreeKey::decrement ( int  steps = 1  )  [pure virtual]

Decrements key a number of entry positions This is only valid if isTraversable is true

Parameters:
steps Number of entries to jump backward

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

virtual bool SWKey::equals ( const SWKey ikey  )  [inline, virtual, inherited]

test equality of this SWKey object's position with another SWKey

Parameters:
ikey key to compare with this one
Returns:
true if the key positions are equal

Definition at line 195 of file swkey.h.

00195 { return !compare(ikey); }

SWDEPRECATED char SWKey::Error (  )  [inline, inherited]

Gets and clears error status

Returns:
error status

Definition at line 159 of file swkey.h.

00159 { return popError(); }

virtual bool TreeKey::firstChild (  )  [pure virtual]

Go to the first child of the current node

Returns:
success or failure

Implemented in TreeKeyIdx.

const SWClass* SWObject::getClass (  )  const [inline, inherited]

Use this to get the class definition and inheritance order.

Returns:
The class definition of this object

Definition at line 59 of file swobject.h.

00059                                      {
00060         return myclass;
00061     }

virtual long TreeKey::getIndex (  )  const [inline, virtual]

Use this function to get an index position within a module.

Reimplemented from SWKey.

Definition at line 126 of file treekey.h.

00126 { return getOffset(); }

virtual int TreeKey::getLevel (  )  [inline, virtual]

Reimplemented in TreeKeyIdx.

Definition at line 75 of file treekey.h.

00075 { long bm = getOffset(); int level = 0; do { level++; } while (parent()); setOffset(bm); return level; }

char* SWKey::getLocale (  )  const [inline, inherited]

Definition at line 215 of file swkey.h.

00215 { return localeName; }

virtual const char* TreeKey::getLocalName (  )  [pure virtual]

Implemented in TreeKeyIdx.

virtual unsigned long TreeKey::getOffset (  )  const [pure virtual]

Implemented in TreeKeyIdx.

const char * SWKey::getOSISRefRangeText (  )  const [virtual, inherited]

Reimplemented in ListKey, and VerseKey.

Definition at line 202 of file swkey.cpp.

00202                                              {
00203     return getRangeText();
00204 }

SWLocale * SWKey::getPrivateLocale (  )  const [protected, inherited]

Definition at line 110 of file swkey.cpp.

00110                                         {
00111     if (!locale) {
00112         if ((!localeCache.name) || (strcmp(localeCache.name, localeName))) {
00113             stdstr(&(localeCache.name), localeName);
00114             // this line is the entire bit of work we're trying to avoid with the cache
00115             // worth it?  compare time examples/cmdline/search KJV "God love world" to
00116             // same with this method reduced to:
00117             // if (!local) local = ... (call below); return locale;
00118             localeCache.locale = LocaleMgr::getSystemLocaleMgr()->getLocale(localeName);
00119         }
00120         locale = localeCache.locale;
00121     }
00122     return locale;
00123 }

const char * SWKey::getRangeText (  )  const [virtual, inherited]

Reimplemented in ListKey, and VerseKey.

Definition at line 192 of file swkey.cpp.

00192                                       {
00193     stdstr(&rangeText, keytext);
00194     return rangeText;
00195 }

virtual const char* SWKey::getShortText (  )  const [inline, virtual, inherited]

Reimplemented in ListKey, and VerseKey.

Definition at line 177 of file swkey.h.

00177 { return getText(); }

virtual const char* TreeKey::getText (  )  const [pure virtual]

returns string representation of this key

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

virtual const char* TreeKey::getUserData ( int *  size = 0  )  const [pure virtual]

Implemented in TreeKeyIdx.

virtual bool TreeKey::hasChildren (  )  [pure virtual]

Does the current node have children?

Returns:
whether or not it does

Implemented in TreeKeyIdx.

virtual void TreeKey::increment ( int  steps = 1  )  [pure virtual]

Increments key a number of entry positions This is only valid if isTraversable is true

Parameters:
steps Number of entries to jump forward

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

void TreeKey::init (  )  [private]

Reimplemented from SWKey.

Reimplemented in TreeKeyIdx.

Definition at line 32 of file treekey.cpp.

00032                    {
00033     myclass = &classdef;
00034     unsnappedKeyText = "";
00035     posChangeListener = 0;
00036 }

virtual void TreeKey::insertBefore (  )  [pure virtual]

Implemented in TreeKeyIdx.

virtual bool SWKey::isBoundSet (  )  const [inline, virtual, inherited]

Definition at line 180 of file swkey.h.

00180 { return boundSet; }

bool SWKey::isPersist (  )  const [inherited]

Gets whether this key should persist in any module to which it is set otherwise just a copy will be used in the module.

Returns:
1 - persists in module; 0 - a copy is attempted

Definition at line 98 of file swkey.cpp.

00099 {
00100     return persist;
00101 }

virtual bool TreeKey::isTraversable (  )  const [inline, virtual]

Whether or not this key can be ++ -- incremented

Reimplemented from SWKey.

Reimplemented in TreeKeyIdx.

Definition at line 125 of file treekey.h.

00125 { return true; }

virtual bool TreeKey::nextSibling (  )  [pure virtual]

Go to the next sibling of the current node

Returns:
success or failure

Implemented in TreeKeyIdx.

virtual bool TreeKey::parent (  )  [pure virtual]

Go to the parent of the current node

Returns:
success or failure

Implemented in TreeKeyIdx.

SWDEPRECATED char SWKey::Persist ( signed char  ipersist  )  [inline, inherited]

Sets whether this key should persist in any module to which it is set otherwise just a copy will be used in the module.

Parameters:
ipersist value which to set persist;
Returns:
1 - persists in module; 0 - a copy is attempted

Definition at line 153 of file swkey.h.

00153 { setPersist(ipersist); return isPersist(); }

SWDEPRECATED char SWKey::Persist (  )  const [inline, inherited]

Definition at line 146 of file swkey.h.

00146 { return isPersist(); }

char SWKey::popError (  )  [virtual, inherited]

Definition at line 146 of file swkey.cpp.

00147 {
00148     char retval = error;
00149 
00150     error = 0;
00151     return retval;
00152 }

void TreeKey::positionChanged (  )  [inline, protected]

Definition at line 49 of file treekey.h.

virtual void SWKey::positionFrom ( const SWKey ikey  )  [inline, virtual, inherited]

Definition at line 172 of file swkey.h.

00172 { copyFrom(ikey); }

virtual bool TreeKey::previousSibling (  )  [pure virtual]

Go to the previous sibling of the current node

Returns:
success or failure

Implemented in TreeKeyIdx.

virtual void TreeKey::remove (  )  [pure virtual]

Implemented in TreeKeyIdx.

virtual void TreeKey::root (  )  [pure virtual]

Go to the root node

Implemented in TreeKeyIdx.

virtual void TreeKey::save (  )  [inline, virtual]

Reimplemented in TreeKeyIdx.

Definition at line 134 of file treekey.h.

00134 {}

virtual void SWKey::setError ( char  err  )  [inline, virtual, inherited]

Definition at line 161 of file swkey.h.

00161 { error = err; }

virtual void TreeKey::setIndex ( long  iindex  )  [inline, virtual]

See documentation for Index()

Reimplemented from SWKey.

Definition at line 127 of file treekey.h.

00127 { setOffset(iindex); }

void SWKey::setLocale ( const char *  name  )  [inline, inherited]

Definition at line 216 of file swkey.h.

00216 { stdstr(&localeName, name); locale = 0;    } // this will force an on demand lookup of our locale

virtual const char* TreeKey::setLocalName ( const char *   )  [pure virtual]

Implemented in TreeKeyIdx.

virtual void TreeKey::setOffset ( unsigned long  offset  )  [pure virtual]

Implemented in TreeKeyIdx.

void SWKey::setPersist ( bool  ipersist  )  [inherited]

Definition at line 134 of file swkey.cpp.

00135 {
00136     persist = ipersist;
00137 }

virtual void TreeKey::setPosition ( SW_POSITION  p  )  [pure virtual]

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

void TreeKey::setPositionChangeListener ( PositionChangeListener pcl  )  [inline]

Definition at line 63 of file treekey.h.

virtual void TreeKey::setText ( const char *  ikey  )  [pure virtual]

Sets this SWKey with a character string

Parameters:
ikey string used to set this key

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

virtual void TreeKey::setUserData ( const char *  userData,
int  size = 0 
) [pure virtual]

Implemented in TreeKeyIdx.


Member Data Documentation

bool SWKey::boundSet [mutable, protected, inherited]

Definition at line 105 of file swkey.h.

SWClass TreeKey::classdef [static, private]

Reimplemented from SWKey.

Reimplemented in TreeKeyIdx.

Definition at line 38 of file treekey.h.

char SWKey::error [protected, inherited]

Definition at line 107 of file swkey.h.

char* SWKey::keytext [protected, inherited]

Definition at line 103 of file swkey.h.

char* SWKey::localeName [protected, inherited]

Definition at line 109 of file swkey.h.

SWClass* SWObject::myclass [protected, inherited]

Definition at line 53 of file swobject.h.

bool SWKey::persist [protected, inherited]

Definition at line 106 of file swkey.h.

char* SWKey::rangeText [mutable, protected, inherited]

Definition at line 104 of file swkey.h.

SWBuf TreeKey::unsnappedKeyText [mutable, protected]

Definition at line 45 of file treekey.h.

__u64 SWKey::userData [inherited]

Definition at line 116 of file swkey.h.


The documentation for this class was generated from the following files:

Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1