The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TreeKey Class Referenceabstract

#include <treekey.h>

+ Inheritance diagram for TreeKey:
+ Collaboration diagram for TreeKey:

Classes

class  PositionChangeListener
 

Public Member Functions

virtual void append ()=0
 
virtual void appendChild ()=0
 
virtual void assureKeyPath (const char *keyPath=0)
 
virtual void clearBounds () const
 
virtual SWKeyclone () const
 
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 char getError () 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 * getShortRangeText () 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 () const
 
SWDEPRECATED char Persist (signed char ipersist)
 
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
 
SW_u64 userData
 

Protected Member Functions

SWLocalegetPrivateLocale () const
 
void positionChanged ()
 

Protected Attributes

bool boundSet
 
char error
 
char * keytext
 
char * localeName
 
const SWClassmyClass
 
bool persist
 
char * rangeText
 
SWBuf unsnappedKeyText
 

Private Member Functions

void init ()
 

Detailed Description

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

Definition at line 38 of file treekey.h.

Constructor & Destructor Documentation

TreeKey::TreeKey ( )
inline

Definition at line 69 of file treekey.h.

69 { init(); };
void init()
Definition: treekey.cpp:34
TreeKey::~TreeKey ( )
inline

Definition at line 70 of file treekey.h.

70 {};

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
keyPathpath to set/create; if unsupplied, then use any unsnapped setText value.

Definition at line 41 of file treekey.cpp.

41  {
42 
43  if (!keyBuffer) {
44  keyBuffer = unsnappedKeyText;
45  //assert we have something to do before setting root
46  if (!*keyBuffer)
47  return;
48  }
49 
50  char *keybuf = 0;
51  stdstr(&keybuf, keyBuffer);
52 
53  root();
54 
55  // TODO: change to NOT use strtok. strtok is dangerous.
56  SWBuf tok = strtok(keybuf, "/");
57  tok.trim();
58  while (tok.size()) {
59  bool foundkey = false;
60  if (hasChildren()) {
61  firstChild();
62  if (tok == getLocalName()) {
63  foundkey = true;
64  }
65  else {
66  while (nextSibling()) {
67  if (getLocalName()) {
68  if (tok == getLocalName()) {
69  foundkey = true;
70  break;
71  }
72  }
73  }
74  }
75  if (!foundkey) {
76  append();
77  setLocalName(tok);
78  save();
79  }
80  }
81  else {
82  appendChild();
83  setLocalName(tok);
84  save();
85  }
86 
87 #ifdef DEBUG
88 // std::cout << getLocalName() << " : " << tok << std::endl;
89 #endif
90 
91  tok = strtok(0, "/");
92  tok.trim();
93 
94  }
95  delete [] keybuf;
96 }
Definition: swbuf.h:47
virtual const char * setLocalName(const char *)=0
virtual void append()=0
virtual const char * getLocalName()=0
SWBuf unsnappedKeyText
Definition: treekey.h:47
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
SWBuf & trim()
Definition: swbuf.h:443
virtual void root()=0
virtual bool hasChildren()=0
unsigned long size() const
Definition: swbuf.h:185
virtual bool nextSibling()=0
virtual void appendChild()=0
virtual void save()
Definition: treekey.h:135
virtual bool firstChild()=0
virtual void SWKey::clearBounds ( ) const
inlinevirtualinherited

Reimplemented in VerseKey.

Definition at line 190 of file swkey.h.

190 { boundSet = false; }
bool boundSet
Definition: swkey.h:104
SWKey * SWKey::clone ( ) const
virtualinherited

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 VerseKey, VerseTreeKey, TreeKeyIdx, and ListKey.

Definition at line 75 of file swkey.cpp.

76 {
77  return new SWKey(*this);
78 }
SWKey(const char *ikey=0)
Definition: swkey.cpp:43
virtual int TreeKey::compare ( const SWKey ikey)
pure virtual

Compares this key object to another SWKey object

Parameters
ikeykey 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

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

void SWKey::copyFrom ( const SWKey ikey)
virtualinherited

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

Parameters
ikeyother SWKey object from which to copy

Reimplemented in VerseKey, ListKey, and TreeKeyIdx.

Definition at line 173 of file swkey.cpp.

173  {
174 // not desirable Persist(ikey.Persist());
175  setLocale(ikey.getLocale());
176  setText((const char *)ikey);
177 }
virtual void setText(const char *ikey)
Definition: swkey.cpp:162
void setLocale(const char *name)
Definition: swkey.h:225
char * getLocale() const
Definition: swkey.h:224
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
stepsNumber of entries to jump backward

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

virtual bool SWKey::equals ( const SWKey ikey)
inlinevirtualinherited

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

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

Definition at line 204 of file swkey.h.

204 { return !compare(ikey); }
virtual int compare(const SWKey &ikey)
Definition: swkey.cpp:218
SWDEPRECATED char SWKey::Error ( )
inlineinherited
Deprecated:
Use popError and getError instead

Definition at line 169 of file swkey.h.

169 { return popError(); }
virtual char popError()
Definition: swkey.cpp:147
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
inlineinherited

Use this to get the class definition and inheritance order.

Returns
The class definition of this object

Definition at line 63 of file swobject.h.

63  {
64  return myClass;
65  }
const SWClass * myClass
Definition: swobject.h:55
virtual char SWKey::getError ( ) const
inlinevirtualinherited

Definition at line 164 of file swkey.h.

164 { return error; }
char error
Definition: swkey.h:106
virtual long TreeKey::getIndex ( ) const
inlinevirtual

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

Reimplemented from SWKey.

Definition at line 127 of file treekey.h.

127 { return getOffset(); }
virtual unsigned long getOffset() const =0
virtual int TreeKey::getLevel ( )
inlinevirtual

Reimplemented in TreeKeyIdx.

Definition at line 76 of file treekey.h.

76 { long bm = getOffset(); int level = 0; do { level++; } while (parent()); setOffset(bm); return level; }
virtual bool parent()=0
virtual unsigned long getOffset() const =0
virtual void setOffset(unsigned long offset)=0
char* SWKey::getLocale ( ) const
inlineinherited

Definition at line 224 of file swkey.h.

224 { return localeName; }
char * localeName
Definition: swkey.h:108
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
virtualinherited

Reimplemented in VerseKey, and ListKey.

Definition at line 203 of file swkey.cpp.

203  {
204  return getRangeText();
205 }
virtual const char * getRangeText() const
Definition: swkey.cpp:193
SWLocale * SWKey::getPrivateLocale ( ) const
protectedinherited

Definition at line 111 of file swkey.cpp.

111  {
112  if (!locale) {
113  if ((!localeCache.name) || (strcmp(localeCache.name, localeName))) {
115  // this line is the entire bit of work we're trying to avoid with the cache
116  // worth it? compare time examples/cmdline/search KJV "God love world" to
117  // same with this method reduced to:
118  // if (!local) local = ... (call below); return locale;
120  }
122  }
123  return locale;
124 }
SWLocale * locale
Definition: swkey.h:82
char * localeName
Definition: swkey.h:108
char * name
Definition: swkey.h:81
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
virtual SWLocale * getLocale(const char *name)
Definition: localemgr.cpp:210
static LocaleMgr * getSystemLocaleMgr()
Definition: localemgr.cpp:54
SWLocale * locale
Definition: swkey.h:94
static LocaleCache localeCache
Definition: swkey.h:92
const char * SWKey::getRangeText ( ) const
virtualinherited

Reimplemented in VerseKey, and ListKey.

Definition at line 193 of file swkey.cpp.

193  {
195  return rangeText;
196 }
char * keytext
Definition: swkey.h:102
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
char * rangeText
Definition: swkey.h:103
virtual const char* SWKey::getShortRangeText ( ) const
inlinevirtualinherited

Reimplemented in VerseKey, and ListKey.

Definition at line 187 of file swkey.h.

187 { return getRangeText(); }
virtual const char * getRangeText() const
Definition: swkey.cpp:193
virtual const char* SWKey::getShortText ( ) const
inlinevirtualinherited

Reimplemented in VerseKey, and ListKey.

Definition at line 185 of file swkey.h.

185 { return getText(); }
virtual const char * getText() const
Definition: swkey.cpp:184
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
stepsNumber of entries to jump forward

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

void TreeKey::init ( )
private

Definition at line 34 of file treekey.cpp.

34  {
35  myClass = &classdef;
36  unsnappedKeyText = "";
38 }
const SWClass * myClass
Definition: swobject.h:55
SWBuf unsnappedKeyText
Definition: treekey.h:47
static const SWClass classdef(classes)
class TreeKey::PositionChangeListener * posChangeListener
virtual void TreeKey::insertBefore ( )
pure virtual

Implemented in TreeKeyIdx.

virtual bool SWKey::isBoundSet ( ) const
inlinevirtualinherited

Definition at line 189 of file swkey.h.

189 { return boundSet; }
bool boundSet
Definition: swkey.h:104
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 99 of file swkey.cpp.

100 {
101  return persist;
102 }
bool persist
Definition: swkey.h:105
virtual bool TreeKey::isTraversable ( ) const
inlinevirtual

Whether or not this key can be ++ – incremented

Reimplemented from SWKey.

Reimplemented in TreeKeyIdx.

Definition at line 126 of file treekey.h.

126 { 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 ( ) const
inlineinherited
Deprecated:
Use isPersist

Definition at line 148 of file swkey.h.

148 { return isPersist(); }
bool isPersist() const
Definition: swkey.cpp:99
SWDEPRECATED char SWKey::Persist ( signed char  ipersist)
inlineinherited
Deprecated:
Use setPersist and isPersist instead.

Definition at line 158 of file swkey.h.

158 { setPersist(ipersist!=0); return isPersist(); }
void setPersist(bool ipersist)
Definition: swkey.cpp:135
bool isPersist() const
Definition: swkey.cpp:99
char SWKey::popError ( )
virtualinherited

Gets and clears error status

Returns
error status

Definition at line 147 of file swkey.cpp.

148 {
149  char retval = error;
150 
151  error = 0;
152  return retval;
153 }
char error
Definition: swkey.h:106
void TreeKey::positionChanged ( )
inlineprotected

Definition at line 51 of file treekey.h.

virtual void positionChanged()=0
class TreeKey::PositionChangeListener * posChangeListener
virtual void SWKey::positionFrom ( const SWKey ikey)
inlinevirtualinherited

Reimplemented in VerseKey.

Definition at line 180 of file swkey.h.

180 { copyFrom(ikey); }
virtual void copyFrom(const SWKey &ikey)
Definition: swkey.cpp:173
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 ( )
inlinevirtual

Reimplemented in TreeKeyIdx.

Definition at line 135 of file treekey.h.

135 {}
virtual void SWKey::setError ( char  err)
inlinevirtualinherited

Definition at line 165 of file swkey.h.

165 { error = err; }
char error
Definition: swkey.h:106
virtual void TreeKey::setIndex ( long  iindex)
inlinevirtual

See documentation for Index()

Reimplemented from SWKey.

Definition at line 128 of file treekey.h.

128 { setOffset(iindex); }
virtual void setOffset(unsigned long offset)=0
void SWKey::setLocale ( const char *  name)
inlineinherited

Definition at line 225 of file swkey.h.

225 { stdstr(&localeName, name); locale = 0; } // this will force an on demand lookup of our locale
char * localeName
Definition: swkey.h:108
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
SWLocale * locale
Definition: swkey.h:94
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

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
ipersistvalue which to set persist;

Definition at line 135 of file swkey.cpp.

136 {
137  persist = ipersist;
138 }
bool persist
Definition: swkey.h:105
virtual void TreeKey::setPosition ( SW_POSITION  p)
pure virtual

Reimplemented from SWKey.

Implemented in TreeKeyIdx.

void TreeKey::setPositionChangeListener ( PositionChangeListener pcl)
inline

Definition at line 64 of file treekey.h.

class TreeKey::PositionChangeListener * posChangeListener
void setTreeKey(TreeKey *tk)
Definition: treekey.h:61
virtual void TreeKey::setText ( const char *  ikey)
pure virtual

Sets this SWKey with a character string

Parameters
ikeystring 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
mutableprotectedinherited

Definition at line 104 of file swkey.h.

char SWKey::error
mutableprotectedinherited

Definition at line 106 of file swkey.h.

char* SWKey::keytext
protectedinherited

Definition at line 102 of file swkey.h.

char* SWKey::localeName
protectedinherited

Definition at line 108 of file swkey.h.

const SWClass* SWObject::myClass
protectedinherited

Definition at line 55 of file swobject.h.

bool SWKey::persist
protectedinherited

Definition at line 105 of file swkey.h.

class TreeKey::PositionChangeListener * TreeKey::posChangeListener
char* SWKey::rangeText
mutableprotectedinherited

Definition at line 103 of file swkey.h.

SWBuf TreeKey::unsnappedKeyText
mutableprotected

Definition at line 47 of file treekey.h.

SW_u64 SWKey::userData
inherited

Definition at line 115 of file swkey.h.


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