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

#include <swkey.h>

+ Inheritance diagram for SWKey:
+ Collaboration diagram for SWKey:

Classes

class  LocaleCache
 

Public Member Functions

virtual void clearBounds () const
 
virtual SWKeyclone () const
 
virtual int compare (const SWKey &ikey)
 
virtual void copyFrom (const SWKey &ikey)
 
virtual void decrement (int steps=1)
 
virtual bool equals (const SWKey &ikey)
 
SWDEPRECATED char Error ()
 
const SWClassgetClass () const
 
virtual char getError () const
 
virtual long getIndex () const
 
char * getLocale () const
 
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
 
virtual void increment (int steps=1)
 
virtual bool isBoundSet () const
 
bool isPersist () const
 
virtual bool isTraversable () const
 
SWDEPRECATED char Persist () const
 
SWDEPRECATED char Persist (signed char ipersist)
 
virtual char popError ()
 
virtual void positionFrom (const SWKey &ikey)
 
virtual void setError (char err)
 
virtual void setIndex (long iindex)
 
void setLocale (const char *name)
 
void setPersist (bool ipersist)
 
virtual void setPosition (SW_POSITION)
 
virtual void setText (const char *ikey)
 
 SWKey (const char *ikey=0)
 
 SWKey (const SWKey &k)
 
virtual ~SWKey ()
 

Public Attributes

SW_u64 userData
 

Protected Member Functions

SWLocalegetPrivateLocale () const
 

Protected Attributes

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

Private Member Functions

void init ()
 

Private Attributes

long index
 
SWLocalelocale
 

Static Private Attributes

static LocaleCache localeCache
 

Detailed Description

SWKey is used for positioning an SWModule to a specific entry. It always represents a possible location into a module and can additionally represent a domain of entries (e.g. "John 3:16" in the domain "John 1:1 - Mark 5:25")

Definition at line 77 of file swkey.h.

Constructor & Destructor Documentation

SWKey::SWKey ( const char *  ikey = 0)

initializes instance of SWKey from a string All keys can be reduced to a string representation which should be able to be used to again set the key to the same position

Parameters
ikeystring to use for initializing this new key

Definition at line 43 of file swkey.cpp.

44 {
45  init();
46  index = 0;
47  persist = 0;
48  keytext = 0;
49  rangeText = 0;
50  error = 0;
51  userData = 0;
52  stdstr(&keytext, ikey);
53 }
char * keytext
Definition: swkey.h:102
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void init()
Definition: swkey.cpp:68
long index
Definition: swkey.h:97
static const SWClass classdef(classes)
bool persist
Definition: swkey.h:105
SWObject(const SWClass &classdef)
Definition: swobject.cpp:61
char * rangeText
Definition: swkey.h:103
char error
Definition: swkey.h:106
SW_u64 userData
Definition: swkey.h:115
SWKey::SWKey ( const SWKey k)

Copy Constructor

Parameters
kThe SWKey object to copy.

Definition at line 55 of file swkey.cpp.

56 {
57  init();
59  index = k.index;
60  persist = k.persist;
61  userData = k.userData;
62  keytext = 0;
63  rangeText = 0;
64  error = k.error;
65  setText(k.getText());
66 }
virtual void setText(const char *ikey)
Definition: swkey.cpp:162
char * localeName
Definition: swkey.h:108
char * keytext
Definition: swkey.h:102
virtual const char * getText() const
Definition: swkey.cpp:184
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void init()
Definition: swkey.cpp:68
long index
Definition: swkey.h:97
static const SWClass classdef(classes)
bool persist
Definition: swkey.h:105
SWObject(const SWClass &classdef)
Definition: swobject.cpp:61
char * rangeText
Definition: swkey.h:103
char error
Definition: swkey.h:106
SW_u64 userData
Definition: swkey.h:115
SWKey::~SWKey ( )
virtual

Destructor, cleans up this instance of SWKey

Definition at line 84 of file swkey.cpp.

84  {
85  delete [] keytext;
86  delete [] rangeText;
87  delete [] localeName;
88 }
char * localeName
Definition: swkey.h:108
char * keytext
Definition: swkey.h:102
char * rangeText
Definition: swkey.h:103

Member Function Documentation

virtual void SWKey::clearBounds ( ) const
inlinevirtual

Reimplemented in VerseKey.

Definition at line 190 of file swkey.h.

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

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
int SWKey::compare ( const SWKey ikey)
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 in VerseKey, TreeKey, and TreeKeyIdx.

Definition at line 218 of file swkey.cpp.

219 {
220  return strcmp((const char *)*this, (const char *)ikey);
221 }
void SWKey::copyFrom ( const SWKey ikey)
virtual

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
void SWKey::decrement ( int  steps = 1)
virtual

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

Parameters
stepsNumber of entries to jump backward

Reimplemented in VerseKey, ListKey, TreeKey, TreeKeyIdx, and VerseTreeKey.

Definition at line 261 of file swkey.cpp.

261  {
263 }
#define KEYERR_OUTOFBOUNDS
Definition: swkey.h:35
char error
Definition: swkey.h:106
virtual bool SWKey::equals ( const SWKey ikey)
inlinevirtual

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 ( )
inline
Deprecated:
Use popError and getError instead

Definition at line 169 of file swkey.h.

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

Definition at line 164 of file swkey.h.

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

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

Reimplemented in VerseKey, ListKey, and TreeKey.

Definition at line 229 of file swkey.h.

229 { return index; }
long index
Definition: swkey.h:97
char* SWKey::getLocale ( ) const
inline

Definition at line 224 of file swkey.h.

224 { return localeName; }
char * localeName
Definition: swkey.h:108
const char * SWKey::getOSISRefRangeText ( ) const
virtual

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
protected

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
virtual

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
inlinevirtual

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
inlinevirtual

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
const char * SWKey::getText ( ) const
virtual

returns string representation of this key

Reimplemented in VerseKey, ListKey, TreeKey, and TreeKeyIdx.

Definition at line 184 of file swkey.cpp.

184  {
185  return keytext;
186 }
char * keytext
Definition: swkey.h:102
void SWKey::increment ( int  steps = 1)
virtual

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

Parameters
stepsNumber of entries to jump forward

Reimplemented in VerseKey, ListKey, TreeKey, TreeKeyIdx, and VerseTreeKey.

Definition at line 248 of file swkey.cpp.

248  {
250 }
#define KEYERR_OUTOFBOUNDS
Definition: swkey.h:35
char error
Definition: swkey.h:106
void SWKey::init ( )
private

Definition at line 68 of file swkey.cpp.

68  {
69  boundSet = false;
70  locale = 0;
71  localeName = 0;
72  setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
73 }
char * localeName
Definition: swkey.h:108
bool boundSet
Definition: swkey.h:104
static LocaleMgr * getSystemLocaleMgr()
Definition: localemgr.cpp:54
SWLocale * locale
Definition: swkey.h:94
void setLocale(const char *name)
Definition: swkey.h:225
virtual bool SWKey::isBoundSet ( ) const
inlinevirtual

Definition at line 189 of file swkey.h.

189 { return boundSet; }
bool boundSet
Definition: swkey.h:104
bool SWKey::isPersist ( ) const

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 SWKey::isTraversable ( ) const
inlinevirtual

Whether or not this key can be ++ – incremented

Reimplemented in VerseKey, ListKey, TreeKey, TreeKeyIdx, and VerseTreeKey.

Definition at line 222 of file swkey.h.

222 { return false; }
SWDEPRECATED char SWKey::Persist ( ) const
inline
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)
inline
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 ( )
virtual

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
virtual void SWKey::positionFrom ( const SWKey ikey)
inlinevirtual

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 void SWKey::setError ( char  err)
inlinevirtual

Definition at line 165 of file swkey.h.

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

See documentation for Index()

Reimplemented in VerseKey, ListKey, and TreeKey.

Definition at line 233 of file swkey.h.

233 { index = iindex; }
long index
Definition: swkey.h:97
void SWKey::setLocale ( const char *  name)
inline

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
void SWKey::setPersist ( bool  ipersist)

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
void SWKey::setPosition ( SW_POSITION  p)
virtual

Reimplemented in VerseKey, ListKey, TreeKey, VerseTreeKey, and TreeKeyIdx.

Definition at line 228 of file swkey.cpp.

228  {
229  switch (p) {
230  case POS_TOP:
231 // *this = "";
232  break;
233  case POS_BOTTOM:
234 // *this = "zzzzzzzzz";
235  break;
236  }
237 }
#define POS_TOP
Definition: swkey.h:65
#define POS_BOTTOM
Definition: swkey.h:66
void SWKey::setText ( const char *  ikey)
virtual

Sets this SWKey with a character string

Parameters
ikeystring used to set this key

Reimplemented in VerseKey, ListKey, TreeKey, and TreeKeyIdx.

Definition at line 162 of file swkey.cpp.

162  {
163  stdstr(&keytext, ikey);
164 }
char * keytext
Definition: swkey.h:102
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44

Member Data Documentation

bool SWKey::boundSet
mutableprotected

Definition at line 104 of file swkey.h.

char SWKey::error
mutableprotected

Definition at line 106 of file swkey.h.

long SWKey::index
private

Definition at line 97 of file swkey.h.

char* SWKey::keytext
protected

Definition at line 102 of file swkey.h.

SWLocale* SWKey::locale
mutableprivate

Definition at line 94 of file swkey.h.

SWKey::LocaleCache SWKey::localeCache
staticprivate

Definition at line 92 of file swkey.h.

char* SWKey::localeName
protected

Definition at line 108 of file swkey.h.

const SWClass* SWObject::myClass
protectedinherited

Definition at line 55 of file swobject.h.

bool SWKey::persist
protected

Definition at line 105 of file swkey.h.

char* SWKey::rangeText
mutableprotected

Definition at line 103 of file swkey.h.

SW_u64 SWKey::userData

Definition at line 115 of file swkey.h.


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