ListKey Class Reference

#include <listkey.h>

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

List of all members.

Public Member Functions

virtual void add (const SWKey &ikey)
virtual void clear ()
virtual void clearBound () const
virtual void ClearList ()
virtual SWKeyclone () const
virtual int compare (const SWKey &ikey)
virtual void copyFrom (const SWKey &ikey)
virtual void copyFrom (const ListKey &ikey)
virtual int Count ()
virtual void decrement (int step=1)
virtual bool equals (const SWKey &ikey)
SWDEPRECATED char Error ()
const SWClassgetClass () const
virtual SWKeyGetElement (int pos=-1)
virtual SWKeygetElement (int pos=-1)
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 step=1)
virtual bool isBoundSet () const
bool isPersist () const
virtual bool isTraversable () const
 ListKey (ListKey const &k)
 ListKey (const char *ikey=0)
ListKeyoperator<< (const SWKey &ikey)
SWKEY_OPERATORS ListKeyoperator= (const ListKey &key)
SWDEPRECATED char Persist (signed char ipersist)
SWDEPRECATED char Persist () const
virtual char popError ()
virtual void positionFrom (const SWKey &ikey)
virtual void Remove ()
virtual void setError (char err)
virtual void setIndex (long index)
void setLocale (const char *name)
void setPersist (bool ipersist)
virtual void setPosition (SW_POSITION pos)
virtual void setText (const char *ikey)
virtual char SetToElement (int ielement, SW_POSITION=TOP)
virtual void sort ()
virtual ~ListKey ()

Public Attributes

__u64 userData

Protected Member Functions

SWLocalegetPrivateLocale () const

Protected Attributes

SWKey ** array
int arraycnt
int arraymax
int arraypos
bool boundSet
char error
char * keytext
char * localeName
SWClassmyclass
bool persist
char * rangeText

Private Member Functions

void init ()

Static Private Attributes

static SWClass classdef

Detailed Description

ListKey is the basis for all types of keys that have lists of specified indexes (e.g. a list of verses, place, etc.)

Definition at line 38 of file listkey.h.


Constructor & Destructor Documentation

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

initializes instance of ListKey

Parameters:
ikey text key

Definition at line 41 of file listkey.cpp.

00041                                 : SWKey(ikey) {
00042     arraymax = 0;
00043     ClearList();
00044     init();
00045 }

ListKey::ListKey ( ListKey const &  k  ) 

Definition at line 48 of file listkey.cpp.

00048                                  : SWKey(k.keytext) {
00049     arraymax = k.arraymax;
00050     arraypos = k.arraypos;
00051     arraycnt = k.arraycnt;
00052     array = (arraymax)?(SWKey **)malloc(k.arraymax * sizeof(SWKey *)):0;
00053     for (int i = 0; i < arraycnt; i++)
00054         array[i] = k.array[i]->clone();
00055     init();
00056 }

ListKey::~ListKey (  )  [virtual]

cleans up instance of ListKey

Definition at line 75 of file listkey.cpp.

00076 {
00077     ClearList();
00078 }


Member Function Documentation

void ListKey::add ( const SWKey ikey  )  [virtual]

Definition at line 126 of file listkey.cpp.

00126                                    {
00127     if (++arraycnt > arraymax) {
00128         array = (SWKey **) ((array) ? realloc(array, (arraycnt + 32) * sizeof(SWKey *)) : calloc(arraycnt + 32, sizeof(SWKey *)));
00129         arraymax = arraycnt + 32;
00130     }
00131     array[arraycnt-1] = ikey.clone();
00132     SetToElement(arraycnt-1);
00133 }

void ListKey::clear (  )  [virtual]

Clears out elements of list

Definition at line 85 of file listkey.cpp.

00086 {
00087     int loop;
00088 
00089     if (arraymax) {
00090         for (loop = 0; loop < arraycnt; loop++)
00091             delete array[loop];
00092 
00093         free(array);
00094         arraymax  = 0;
00095     }
00096     arraycnt  = 0;
00097     arraypos  = 0;
00098     array     = 0;
00099 }

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

Definition at line 181 of file swkey.h.

00181 { boundSet = false; }

virtual void ListKey::ClearList (  )  [inline, virtual]

deprecated, use clear(), instead

Definition at line 70 of file listkey.h.

00070 { clear(); }

SWKey * ListKey::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 from SWKey.

Definition at line 66 of file listkey.cpp.

00067 {
00068     return new ListKey(*this);
00069 }

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 void ListKey::copyFrom ( const SWKey ikey  )  [inline, virtual]

Definition at line 109 of file listkey.h.

00109 { SWKey::copyFrom(ikey); }

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

Equates this ListKey to another ListKey object

Parameters:
ikey other ListKey object

Reimplemented from SWKey.

Definition at line 108 of file listkey.cpp.

00108                                           {
00109     ClearList();
00110 
00111     arraymax = ikey.arraymax;
00112     arraypos = ikey.arraypos;
00113     arraycnt = ikey.arraycnt;
00114     array = (arraymax)?(SWKey **)malloc(ikey.arraymax * sizeof(SWKey *)):0;
00115     for (int i = 0; i < arraycnt; i++)
00116         array[i] = ikey.array[i]->clone();
00117 
00118     SetToElement(0);
00119 }

int ListKey::Count (  )  [virtual]

Returns number of elements in list

Returns:
number of elements in list

Definition at line 209 of file listkey.cpp.

00209                    {
00210     return arraycnt;
00211 }

void ListKey::decrement ( int  step = 1  )  [virtual]

Decrements a number of elements

Reimplemented from SWKey.

Definition at line 185 of file listkey.cpp.

00185                                 {
00186     if (step < 0) {
00187         increment(step*-1);
00188         return;
00189     }
00190     popError();     // clear error
00191     for(; step && !popError(); step--) {
00192         if (arraypos > -1 && arraycnt) {
00193             if (array[arraypos]->isBoundSet())
00194                 (*(array[arraypos]))--;
00195             if ((array[arraypos]->popError()) || (!array[arraypos]->isBoundSet())) {
00196                 SetToElement(arraypos-1, BOTTOM);
00197             }
00198             else SWKey::setText((const char *)(*array[arraypos]));
00199         }
00200         else error = KEYERR_OUTOFBOUNDS;
00201     }
00202 }

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(); }

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 SWKey* ListKey::GetElement ( int  pos = -1  )  [inline, virtual]

Definition at line 96 of file listkey.h.

00096 { return getElement(pos); }

SWKey * ListKey::getElement ( int  pos = -1  )  [virtual]

Gets a key element number

Parameters:
pos element number to get (or default current)
Returns:
Key or null on error

Definition at line 257 of file listkey.cpp.

00257                                   {
00258     if (pos < 0)
00259         pos = arraypos;
00260         
00261     if (pos >=arraycnt)
00262         error = KEYERR_OUTOFBOUNDS;
00263 
00264     return (error) ? 0:array[pos];
00265 }

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

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

Reimplemented from SWKey.

Definition at line 127 of file listkey.h.

00127 { return arraypos; }

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

Definition at line 215 of file swkey.h.

00215 { return localeName; }

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

Reimplemented from SWKey.

Definition at line 306 of file listkey.cpp.

00306                                                {
00307     char *buf = new char[(arraycnt + 1) * 255];
00308     buf[0] = 0;
00309     for (int i = 0; i < arraycnt; i++) {
00310         strcat(buf, array[i]->getOSISRefRangeText());
00311         if (i < arraycnt-1)
00312             strcat(buf, ";");
00313     }
00314     stdstr(&rangeText, buf);
00315     delete [] buf;
00316     return rangeText;
00317 }

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 * ListKey::getRangeText (  )  const [virtual]

Reimplemented from SWKey.

Definition at line 288 of file listkey.cpp.

00288                                         {
00289     char *buf = new char[(arraycnt + 1) * 255];
00290     buf[0] = 0;
00291     for (int i = 0; i < arraycnt; i++) {
00292         strcat(buf, array[i]->getRangeText());
00293         if (i < arraycnt-1)
00294             strcat(buf, "; ");
00295     }
00296     stdstr(&rangeText, buf);
00297     delete [] buf;
00298     return rangeText;
00299 }

const char * ListKey::getShortText (  )  const [virtual]

Reimplemented from SWKey.

Definition at line 330 of file listkey.cpp.

00330                                         {
00331     int pos = arraypos;
00332     SWKey *key = (pos >= arraycnt || !arraycnt) ? 0:array[pos];
00333     return (key) ? key->getShortText() : keytext;
00334 }

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

returns string representation of this key

Reimplemented from SWKey.

Definition at line 324 of file listkey.cpp.

00324                                    {
00325     int pos = arraypos;
00326     SWKey *key = (pos >= arraycnt || !arraycnt) ? 0:array[pos];
00327     return (key) ? key->getText() : keytext;
00328 }

void ListKey::increment ( int  step = 1  )  [virtual]

Increments a number of elements

Reimplemented from SWKey.

Definition at line 161 of file listkey.cpp.

00161                                 {
00162     if (step < 0) {
00163         decrement(step*-1);
00164         return;
00165     }
00166     popError();     // clear error
00167     for(; step && !popError(); step--) {
00168         if (arraypos < arraycnt && arraycnt) {
00169             if (array[arraypos]->isBoundSet())
00170                 (*(array[arraypos]))++;
00171             if ((array[arraypos]->popError()) || (!array[arraypos]->isBoundSet())) {
00172                 SetToElement(arraypos+1);
00173             }
00174             else SWKey::setText((const char *)(*array[arraypos]));
00175         }
00176         else error = KEYERR_OUTOFBOUNDS;
00177     }
00178 }

void ListKey::init (  )  [private]

Reimplemented from SWKey.

Definition at line 59 of file listkey.cpp.

00059                    {
00060     myclass = &classdef;
00061     // this is a listkey, bound is always set
00062     boundSet = true;
00063 }

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

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

Reimplemented from SWKey.

Definition at line 126 of file listkey.h.

00126 { return true; }

ListKey& ListKey::operator<< ( const SWKey ikey  )  [inline]

Adds an element to the list

Parameters:
ikey the element to add

Definition at line 101 of file listkey.h.

00101 { add(ikey); return *this; }

SWKEY_OPERATORS ListKey& ListKey::operator= ( const ListKey key  )  [inline]

Definition at line 142 of file listkey.h.

00142 { copyFrom(key); return *this; }

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 }

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

Definition at line 172 of file swkey.h.

00172 { copyFrom(ikey); }

void ListKey::Remove (  )  [virtual]

Removes current element from list

Definition at line 272 of file listkey.cpp.

00272                      {
00273     if ((arraypos > -1) && (arraypos < arraycnt)) {
00274         delete array[arraypos];
00275         if (arraypos < arraycnt - 1)
00276             memmove(&array[arraypos], &array[arraypos+1], (arraycnt - arraypos - 1) * sizeof(SWKey *));
00277         arraycnt--;
00278         
00279         SetToElement((arraypos)?arraypos-1:0);
00280     }
00281 }

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

Definition at line 161 of file swkey.h.

00161 { error = err; }

virtual void ListKey::setIndex ( long  index  )  [inline, virtual]

Returns the index for the new one given as as parameter. The first parameter is the new index.

Reimplemented from SWKey.

Definition at line 136 of file listkey.h.

00136 { SetToElement(index); }

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

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

Definition at line 134 of file swkey.cpp.

00135 {
00136     persist = ipersist;
00137 }

void ListKey::setPosition ( SW_POSITION  pos  )  [virtual]

Positions this key

Parameters:
pos position
Returns:
*this

Reimplemented from SWKey.

Definition at line 145 of file listkey.cpp.

00145                                        {
00146     switch (p) {
00147     case 1: // GCC won't compile P_TOP
00148         SetToElement(0, p);
00149         break;
00150     case 2: // GCC won't compile P_BOTTOM
00151         SetToElement(arraycnt-1, p);
00152         break;
00153     }
00154 }

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

Sets this SWKey with a character string

Parameters:
ikey string used to set this key

Reimplemented from SWKey.

Definition at line 337 of file listkey.cpp.

00337                                       {
00338     // at least try to set the current element to this text
00339     for (arraypos = 0; arraypos < arraycnt; arraypos++) {
00340         SWKey *key = array[arraypos];
00341         if (key) {
00342             if (key->isTraversable() && key->isBoundSet()) {
00343                 key->setText(ikey);
00344                 if (!key->popError())
00345                     break;
00346             }
00347             else {
00348                 if (!strcmp(key->getText(), ikey))
00349                     break;
00350             }
00351         }
00352     }
00353     if (arraypos >= arraycnt) {
00354         error = 1;
00355         arraypos = arraycnt-1;
00356     }
00357     
00358     SWKey::setText(ikey);
00359 }

char ListKey::SetToElement ( int  ielement,
SW_POSITION  pos = TOP 
) [virtual]

Sets key to element number

Parameters:
ielement element number to set to
Returns:
error status

Definition at line 222 of file listkey.cpp.

00222                                                         {
00223     arraypos = ielement;
00224     if (arraypos >= arraycnt) {
00225         arraypos = (arraycnt>0)?arraycnt - 1:0;
00226         error = KEYERR_OUTOFBOUNDS;
00227     }
00228     else {
00229         if (arraypos < 0) {
00230             arraypos = 0;
00231             error = KEYERR_OUTOFBOUNDS;
00232         }
00233         else {
00234             error = 0;
00235         }
00236     }
00237     
00238     if (arraycnt) {
00239         if (array[arraypos]->isBoundSet())
00240             (*array[arraypos]) = pos;
00241         SWKey::setText((const char *)(*array[arraypos]));
00242     }
00243     else SWKey::setText("");
00244     
00245     return error;
00246 }

void ListKey::sort (  )  [virtual]

Definition at line 362 of file listkey.cpp.

00362                    {
00363     for (int i = 0; i < arraycnt; i++) {
00364         for (int j = i; j < arraycnt; j++) {
00365             if (*array[j] < *array[i]) {
00366                 SWKey *tmp = array[i];
00367                 array[i] = array[j];
00368                 array[j] = tmp;
00369             }
00370         }
00371     }
00372 }


Member Data Documentation

SWKey** ListKey::array [protected]

Definition at line 47 of file listkey.h.

int ListKey::arraycnt [protected]

Definition at line 46 of file listkey.h.

int ListKey::arraymax [protected]

Definition at line 45 of file listkey.h.

int ListKey::arraypos [protected]

Definition at line 44 of file listkey.h.

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

Definition at line 105 of file swkey.h.

SWClass ListKey::classdef [static, private]

Reimplemented from SWKey.

Definition at line 40 of file listkey.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.

__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