SWKey Class Reference

#include <swkey.h>

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

List of all members.

Classes

class  LocaleCache

Public Member Functions

virtual void clearBound () 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 long getIndex () const
char * getLocale () const
virtual const char * getOSISRefRangeText () const
virtual const char * getRangeText () 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 (signed char ipersist)
SWDEPRECATED char Persist () const
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 (SWKey const &k)
 SWKey (const char *ikey=0)
virtual ~SWKey ()

Public Attributes

__u64 userData

Protected Member Functions

SWLocalegetPrivateLocale () const

Protected Attributes

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

Private Member Functions

void init ()

Private Attributes

long index
SWLocalelocale

Static Private Attributes

static SWClass classdef
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:
ikey string to use for initializing this new key

Definition at line 41 of file swkey.cpp.

00042 {
00043     init();
00044     index     = 0;
00045     persist   = 0;
00046     keytext   = 0;
00047     rangeText = 0;
00048     error     = 0;
00049     userData  = 0;
00050     stdstr(&keytext, ikey);
00051 }

SWKey::SWKey ( SWKey const &  k  ) 

Copy Constructor

Parameters:
k The SWKey object to copy.

Definition at line 53 of file swkey.cpp.

00054 {
00055     init();
00056     stdstr(&localeName, k.localeName);
00057     index     = k.index;
00058     persist   = k.persist;
00059     userData  = k.userData;
00060     keytext   = 0;
00061     rangeText = 0;
00062     error     = k.error;
00063     setText(k.getText());
00064 }

SWKey::~SWKey (  )  [virtual]

Destructor, cleans up this instance of SWKey

Definition at line 83 of file swkey.cpp.

00083               {
00084     delete [] keytext;
00085     delete [] rangeText;
00086     delete [] localeName;
00087 }


Member Function Documentation

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

Definition at line 181 of file swkey.h.

00181 { boundSet = false; }

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 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]

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 }

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

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 }

void SWKey::decrement ( int  steps = 1  )  [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 in ListKey, TreeKey, TreeKeyIdx, VerseKey, and VerseTreeKey.

Definition at line 260 of file swkey.cpp.

00260                          {
00261     error = KEYERR_OUTOFBOUNDS;
00262 }

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

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]

Gets and clears error status

Returns:
error status

Definition at line 159 of file swkey.h.

00159 { return popError(); }

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 SWKey::getIndex (  )  const [inline, virtual]

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

Reimplemented in ListKey, TreeKey, and VerseKey.

Definition at line 220 of file swkey.h.

00220 { return index; }

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

Definition at line 215 of file swkey.h.

00215 { return localeName; }

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

Reimplemented in ListKey, and VerseKey.

Definition at line 202 of file swkey.cpp.

00202                                              {
00203     return getRangeText();
00204 }

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

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]

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]

Reimplemented in ListKey, and VerseKey.

Definition at line 177 of file swkey.h.

00177 { return getText(); }

const char * SWKey::getText (  )  const [virtual]

returns string representation of this key

Reimplemented in ListKey, TreeKey, TreeKeyIdx, and VerseKey.

Definition at line 183 of file swkey.cpp.

00183                                  {
00184     return keytext;
00185 }

void SWKey::increment ( int  steps = 1  )  [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 in ListKey, TreeKey, TreeKeyIdx, VerseKey, and VerseTreeKey.

Definition at line 247 of file swkey.cpp.

00247                          {
00248     error = KEYERR_OUTOFBOUNDS;
00249 }

void SWKey::init (  )  [private]

Reimplemented in ListKey, StrKey, TreeKey, and TreeKeyIdx.

Definition at line 66 of file swkey.cpp.

00066                  {
00067     myclass = &classdef;
00068     boundSet = false;
00069     locale = 0;
00070     localeName = 0;
00071     setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
00072 }

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

Definition at line 180 of file swkey.h.

00180 { return boundSet; }

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 98 of file swkey.cpp.

00099 {
00100     return persist;
00101 }

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

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

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

Definition at line 213 of file swkey.h.

00213 { return false; }

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

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]

Definition at line 146 of file swkey.h.

00146 { return isPersist(); }

char SWKey::popError (  )  [virtual]

Definition at line 146 of file swkey.cpp.

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

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

Definition at line 172 of file swkey.h.

00172 { copyFrom(ikey); }

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

Definition at line 161 of file swkey.h.

00161 { error = err; }

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

See documentation for Index()

Reimplemented in ListKey, TreeKey, and VerseKey.

Definition at line 224 of file swkey.h.

00224 { index = iindex; }

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

Definition at line 216 of file swkey.h.

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

void SWKey::setPersist ( bool  ipersist  ) 

Definition at line 134 of file swkey.cpp.

00135 {
00136     persist = ipersist;
00137 }

void SWKey::setPosition ( SW_POSITION  p  )  [virtual]

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

Definition at line 227 of file swkey.cpp.

00227                                      {
00228     switch (p) {
00229     case POS_TOP:
00230 //      *this = "";
00231         break;
00232     case POS_BOTTOM:
00233 //      *this = "zzzzzzzzz";
00234         break;
00235     } 
00236 }

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

Sets this SWKey with a character string

Parameters:
ikey string used to set this key

Reimplemented in ListKey, TreeKey, TreeKeyIdx, and VerseKey.

Definition at line 161 of file swkey.cpp.

00161                                     {
00162     stdstr(&keytext, ikey);
00163 }


Member Data Documentation

bool SWKey::boundSet [mutable, protected]

Definition at line 105 of file swkey.h.

SWClass SWKey::classdef [static, private]

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

Definition at line 98 of file swkey.h.

char SWKey::error [protected]

Definition at line 107 of file swkey.h.

long SWKey::index [private]

Definition at line 97 of file swkey.h.

char* SWKey::keytext [protected]

Definition at line 103 of file swkey.h.

SWLocale* SWKey::locale [mutable, private]

Definition at line 94 of file swkey.h.

Definition at line 92 of file swkey.h.

char* SWKey::localeName [protected]

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]

Definition at line 106 of file swkey.h.

char* SWKey::rangeText [mutable, protected]

Definition at line 104 of file swkey.h.

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