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

SWKey Class Reference

SWKey is the basis for all types of keys for indexing into modules (e.g. More...

#include <swkey.h>

Inheritance diagram for SWKey:

Inheritance graph
[legend]
Collaboration diagram for SWKey:

Collaboration graph
[legend]
List of all members.

Public Methods

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

 SWKey (SWKey const &k)
 Copy Constructor. More...

virtual ~SWKey ()
 Destructor, cleans up this instance of SWKey.

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

char Persist () const
 Gets whether this object itself persists within a module that it was used to SetKey or just a copy. More...

char Persist (signed char ikey)
 Set/gets whether this object itself persists within a module that it was used to SetKey or just a copy. More...

virtual char Error ()
 Gets and clears error status. More...

virtual void setText (const char *ikey)
 Equates this SWKey to a character string. More...

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

virtual const char * getText () const
 returns text key if (char *) cast is requested.

virtual int compare (const SWKey &ikey)
 Compares another VerseKey object. More...

virtual bool equals (const SWKey &ikey)
 Compares another VerseKey object. More...

virtual void setPosition (SW_POSITION)
virtual void decrement (int steps=1)
 Decrements key a number of entries. More...

virtual void increment (int steps=1)
 Increments key a number of entries. More...

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

virtual long Index (long iindex)

Protected Attributes

char * keytext
char persist
char error

Private Methods

void init ()

Private Attributes

long index

Static Private Attributes

SWClass classdef

Detailed Description

SWKey is the basis for all types of keys for indexing into modules (e.g.

verse, word, place, etc.)

Definition at line 76 of file swkey.h.


Constructor & Destructor Documentation

SWKey::SWKey const char *    ikey = 0
 

initializes instance of SWKey.

Parameters:
ikey  text key

Definition at line 20 of file swkey.cpp.

Referenced by clone.

00021 {
00022         index   = 0;
00023         persist = 0;
00024         keytext = 0;
00025         error   = 0;
00026         stdstr(&keytext, ikey);
00027         init();
00028 }

SWKey::SWKey SWKey const &    k
 

Copy Constructor.

Parameters:
The  SWKey object to copy.

Definition at line 30 of file swkey.cpp.

References error, index, keytext, and persist.

00031 {
00032         index   = k.index;
00033         persist = k.persist;
00034         keytext = 0;
00035         error = k.error;
00036         stdstr(&keytext, k.keytext);
00037         init();
00038 }


Member Function Documentation

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

Definition at line 44 of file swkey.cpp.

References SWKey.

Referenced by ListKey::copyFrom, and SWModule::Search.

00045 {
00046         return new SWKey(*this);
00047 }

int SWKey::compare const SWKey &    ikey [virtual]
 

Compares another VerseKey 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

Reimplemented in TreeKey.

Definition at line 150 of file swkey.cpp.

Referenced by TreeKeyIdx::compare.

00151 {
00152         return strcmp((const char *)*this, (const char *)ikey);
00153 }

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

Equates this SWKey to another SWKey object.

Parameters:
ikey  other swkey object

Reimplemented in ListKey.

Definition at line 125 of file swkey.cpp.

References setText.

Referenced by VerseKey::copyFrom, TreeKeyIdx::copyFrom, and ListKey::copyFrom.

00125                                       {
00126 // not desirable        Persist(ikey.Persist());
00127         setText((const char *)ikey);
00128 }

void SWKey::decrement int    steps = 1 [virtual]
 

Decrements key a number of entries.

Parameters:
steps  Number of entries to jump backward
Returns:
*this

Reimplemented in ListKey.

Definition at line 193 of file swkey.cpp.

00193                          {
00194         error = KEYERR_OUTOFBOUNDS;
00195 }

virtual bool SWKey::equals const SWKey &    ikey [inline, virtual]
 

Compares another VerseKey object.

Parameters:
ikey  key to compare with this one
Returns:
true if the keys are the same

Definition at line 163 of file swkey.h.

00163 { return !compare(ikey); }

char SWKey::Error   [virtual]
 

Gets and clears error status.

Returns:
error status

Definition at line 99 of file swkey.cpp.

Referenced by VerseKey::decrement, ListKey::decrement, VerseKey::increment, ListKey::increment, SWModule::operator+=, SWModule::operator-=, SWModule::operator=, VerseKey::setPosition, and TreeKeyIdx::setText.

00100 {
00101         char retval = error;
00102 
00103         error = 0;
00104         return retval;
00105 }

void SWKey::increment int    steps = 1 [virtual]
 

Increments key a number of entries.

Parameters:
increment  Number of entries to jump forward
Returns:
*this

Reimplemented in ListKey.

Definition at line 180 of file swkey.cpp.

00180                          {
00181         error = KEYERR_OUTOFBOUNDS;
00182 }

virtual long SWKey::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 in ListKey.

Definition at line 204 of file swkey.h.

Referenced by ListKey::Index, and SWModule::Search.

00204 { return index; }

char SWKey::Persist signed char    ikey
 

Set/gets whether this object itself persists within a module that it was used to SetKey or just a copy.

(1 - persists in module; 0 - a copy is attempted

Parameters:
ipersist  value which to set persist; [-1] - only get
Returns:
value of persist

Definition at line 84 of file swkey.cpp.

00085 {
00086         if (ipersist != -1)
00087                 persist = ipersist;
00088 
00089         return persist;
00090 }

char SWKey::Persist   const
 

Gets whether this object itself persists within a module that it was used to SetKey or just a copy.

(1 - persists in module; 0 - a copy is attempted

Returns:
value of persist

Definition at line 67 of file swkey.cpp.

Referenced by SWLD::KeyText, SWModule::RenderText, SWModule::Search, SWModule::SetKey, SWModule::StripText, and SWModule::~SWModule.

00068 {
00069         return persist;
00070 }

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

Equates this SWKey to a character string.

Parameters:
ikey  string to set this key to

Reimplemented in TreeKey.

Definition at line 114 of file swkey.cpp.

Referenced by copyFrom, VerseKey::parse, and VerseKey::setText.

00114                                     {
00115         stdstr(&keytext, ikey);
00116 }


The documentation for this class was generated from the following files:
Generated on Wed Apr 3 22:34:18 2002 for The Sword Project by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002