Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ListKey Class Reference

ListKey is the basis for all types of keys that have lists of specified indexes (e.g. More...

#include <listkey.h>

Inheritance diagram for ListKey:

Inheritance graph
[legend]
Collaboration diagram for ListKey:

Collaboration graph
[legend]
List of all members.

Public Methods

 ListKey (const char *ikey=0)
 initializes instance of ListKey. More...

 ListKey (ListKey const &k)
virtual ~ListKey ()
 cleans up instance of ListKey.

virtual SWKeyclone () const
 Returns a copy of this SWKey object. More...

virtual void ClearList ()
 Clears out elements of list.

virtual int Count ()
 Returns number of elements in list. More...

virtual void Remove ()
 Removes current element from list.

virtual char SetToElement (int ielement, SW_POSITION=TOP)
 Sets key to element number. More...

virtual SWKeyGetElement (int pos=-1)
 Gets a key element number. More...

ListKey & operator<< (const SWKey &ikey)
 Adds an element to the list. More...

virtual void add (const SWKey &ikey)
virtual void copyFrom (const ListKey &ikey)
 Equates this ListKey to another ListKey object. More...

virtual void copyFrom (const SWKey &ikey)
 Equates this SWKey to another SWKey object. More...

virtual void setPosition (SW_POSITION)
 Positions this key. More...

virtual void decrement (int step)
 Decrements a number of elements.

virtual void increment (int step)
 Increments a number of elements.

virtual char Traversable ()
virtual long Index () const
 Use this function to get te current position withing a module. More...

virtual long Index (long index)
 Returns the index for the new one given as as parameter. More...

SWKEY_OPERATORS ListKey & operator= (const ListKey &key)

Protected Attributes

int arraypos
int arraymax
int arraycnt
SWKey ** array

Private Methods

void init ()

Static Private Attributes

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 36 of file listkey.h.


Constructor & Destructor Documentation

ListKey::ListKey const char *    ikey = 0
 

initializes instance of ListKey.

Parameters:
ikey  text key

Definition at line 22 of file listkey.cpp.

References ClearList().

Referenced by clone().

00022                                 : SWKey(ikey) {
00023         arraymax = 0;
00024         ClearList();
00025         init();
00026 }


Member Function Documentation

SWKey * ListKey::clone   const [virtual]
 

Returns a copy of this SWKey object.

This is useful to get a 1:1 copy of an SWKey based object.

Returns:
SWKey

Reimplemented from SWKey.

Definition at line 45 of file listkey.cpp.

References ListKey().

00046 {
00047         return new ListKey(*this);
00048 }

virtual void ListKey::copyFrom const SWKey   ikey [inline, virtual]
 

Equates this SWKey to another SWKey object.

Parameters:
ikey  other swkey object

Reimplemented from SWKey.

Definition at line 90 of file listkey.h.

References SWKey::copyFrom().

00090 { SWKey::copyFrom(ikey); }

void ListKey::copyFrom const ListKey &    ikey [virtual]
 

Equates this ListKey to another ListKey object.

Parameters:
ikey  other ListKey object

Definition at line 87 of file listkey.cpp.

References array, arraycnt, arraymax, arraypos, ClearList(), SWKey::clone(), and SetToElement().

00087                                           {
00088         ClearList();
00089 
00090         arraymax = ikey.arraymax;
00091         arraypos = ikey.arraypos;
00092         arraycnt = ikey.arraycnt;
00093         array = (arraymax)?(SWKey **)malloc(ikey.arraymax * sizeof(SWKey *)):0;
00094         for (int i = 0; i < arraycnt; i++)
00095                 array[i] = ikey.array[i]->clone();
00096 
00097         SetToElement(0);
00098 }

int ListKey::Count   [virtual]
 

Returns number of elements in list.

Returns:
number of elements in list

Definition at line 186 of file listkey.cpp.

Referenced by VerseKey::parse().

00186                    {
00187         return arraycnt;
00188 }

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 233 of file listkey.cpp.

00233                                   {
00234         if (pos >=0) {
00235                 if (pos >=arraycnt)
00236                         error = KEYERR_OUTOFBOUNDS;
00237         }
00238         else pos = arraypos;
00239         return (error) ? 0:array[pos];
00240 }

virtual long ListKey::Index 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 112 of file listkey.h.

References SWKey::Index().

00112 { SetToElement (index); return Index (); }

virtual long ListKey::Index   const [inline, virtual]
 

Use this function to get te current position withing a module.

Here's a small example how to use this function and Index(long). This function uses the GerLut module and chooses a random verse from the Bible and returns it.

 const char* randomVerse() {
   VerseKey vk;
   SWMgr mgr;
   LocaleMgr::systemLocaleMgr.setDefaultLocaleName("de");

   SWModule* module = mgr->Modules("GerLut");
   srand( time(0) );
   const double newIndex = (double(rand())/RAND_MAX)*(24108+8224);
   vk.Index(newIndex);
   module->SetKey(vk);

   char* text;
   sprintf(text, "%s: %s",(const char*)vk ,module->StripText(&vk));
   return text;

Reimplemented from SWKey.

Definition at line 106 of file listkey.h.

00106 { return arraypos; }

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

Adds an element to the list.

Parameters:
ikey  the element to add

Definition at line 82 of file listkey.h.

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

void ListKey::setPosition SW_POSITION    [virtual]
 

Positions this key.

Parameters:
p  position
Returns:
*this

Reimplemented from SWKey.

Definition at line 124 of file listkey.cpp.

References SetToElement().

00124                                        {
00125         switch (p) {
00126         case 1: // GCC won't compile P_TOP
00127                 SetToElement(0);
00128                 break;
00129         case 2: // GCC won't compile P_BOTTOM
00130                 SetToElement(arraycnt-1);
00131                 break;
00132         }
00133 }

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

Sets key to element number.

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

Definition at line 199 of file listkey.cpp.

Referenced by copyFrom(), decrement(), increment(), Remove(), and setPosition().

00199                                                         {
00200         arraypos = ielement;
00201         if (arraypos >= arraycnt) {
00202                 arraypos = (arraycnt>0)?arraycnt - 1:0;
00203                 error = KEYERR_OUTOFBOUNDS;
00204         }
00205         else {
00206                 if (arraypos < 0) {
00207                         arraypos = 0;
00208                         error = KEYERR_OUTOFBOUNDS;
00209                 }
00210                 else {
00211                         error = 0;
00212                 }
00213         }
00214         
00215         if (arraycnt) {
00216                 (*array[arraypos]) = pos;
00217                 *this = (const char *)(*array[arraypos]);
00218         }
00219         else *this = "";
00220         
00221         return error;
00222 }


The documentation for this class was generated from the following files:
Generated on Thu Jun 20 22:13:02 2002 for The Sword Project by doxygen1.2.15