sword::SWKey Class Reference

SWKey is used for positioning an SWModule to a specific entry. More...

#include <swkey.h>

Inheritance diagram for sword::SWKey:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 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
 SWKey (SWKey const &k)
 Copy Constructor.
virtual ~SWKey ()
 Destructor, cleans up this instance of SWKey.
virtual SWKeyclone () const
 Returns a new exact clone of this SWKey object.
char Persist () 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.
char Persist (signed char 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.
virtual char Error ()
 Gets and clears error status.
virtual void setText (const char *ikey)
 Sets this SWKey with a character string.
virtual void copyFrom (const SWKey &ikey)
 Copies as much info (position, range, etc.
virtual const char * getText () const
 returns string representation of this key
virtual const char * getShortText () const
virtual const char * getRangeText () const
virtual bool isBoundSet () const
virtual int compare (const SWKey &ikey)
 Compares this key object to another SWKey object.
virtual bool equals (const SWKey &ikey)
 test equality of this SWKey object's position with another SWKey
virtual void setPosition (SW_POSITION)
virtual void decrement (int steps=1)
 Decrements key a number of entry positions This is only valid if isTraversable is true.
virtual void increment (int steps=1)
 Increments key a number of entry positions This is only valid if isTraversable is true.
char Traversable ()
 deprecated, use isTraversible
virtual bool isTraversable () const
 Whether or not this key can be ++ -- incremented.
virtual long Index () const
 Use this function to get an index position within a module.
virtual long Index (long iindex)
 See documentation for Index().
SWKeyoperator= (const char *ikey)
SWKeyoperator= (const SWKey &ikey)
SWKeyoperator= (SW_POSITION pos)
 operator const char * () const
bool operator== (const SWKey &ikey)
bool operator!= (const SWKey &ikey)
virtual bool operator> (const SWKey &ikey)
virtual bool operator< (const SWKey &ikey)
virtual bool operator>= (const SWKey &ikey)
virtual bool operator<= (const SWKey &ikey)
SWKeyoperator-= (int steps)
SWKeyoperator+= (int steps)
SWKeyoperator++ (int)
SWKeyoperator-- (int)

Public Attributes

void * userData

Protected Attributes

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

Private Member Functions

void init ()

Private Attributes

long index

Static Private Attributes

static SWClass classdef

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 71 of file swkey.h.


Constructor & Destructor Documentation

sword::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

sword::SWKey::SWKey ( SWKey const &  k  ) 

Copy Constructor.

Parameters:
k The SWKey object to copy.


Member Function Documentation

virtual SWKey* sword::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 sword::ListKey, sword::TreeKeyIdx, sword::VerseKey, and sword::VerseTreeKey.

char sword::SWKey::Persist (  )  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

char sword::SWKey::Persist ( signed char  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:
ipersist value which to set persist;
Returns:
1 - persists in module; 0 - a copy is attempted

virtual char sword::SWKey::Error (  )  [virtual]

Gets and clears error status.

Returns:
error status

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

Sets this SWKey with a character string.

Parameters:
ikey string used to set this key

Reimplemented in sword::ListKey, sword::TreeKey, sword::TreeKeyIdx, and sword::VerseKey.

virtual void sword::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 sword::ListKey, sword::TreeKeyIdx, and sword::VerseKey.

Referenced by sword::VerseKey::operator=(), sword::TreeKeyIdx::operator=(), and sword::ListKey::operator=().

virtual int sword::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

Reimplemented in sword::TreeKey, sword::TreeKeyIdx, and sword::VerseKey.

virtual bool sword::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 157 of file swkey.h.

virtual void sword::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 sword::ListKey, sword::TreeKey, sword::TreeKeyIdx, and sword::VerseKey.

virtual void sword::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 sword::ListKey, sword::TreeKey, sword::TreeKeyIdx, and sword::VerseKey.

virtual long sword::SWKey::Index (  )  const [inline, virtual]

Use this function to get an index position within 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::getSystemLocaleMgr()->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 sword::ListKey, sword::TreeKey, and sword::VerseKey.

Definition at line 202 of file swkey.h.

Referenced by sword::ListKey::Index().


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