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

swkey.cpp

00001 /******************************************************************************
00002  *  swkey.cpp - code for base class 'SWKey'.  SWKey is the basis for all
00003  *              types of keys for indexing into modules (e.g. verse, word,
00004  *              place, etc.)
00005  */
00006 
00007 #include <swkey.h>
00008 #include <utilfuns.h>
00009 #include <string.h>
00010 
00011 static const char *classes[] = {"SWKey", "SWObject", 0};
00012 SWClass SWKey::classdef(classes);
00013 
00014 /******************************************************************************
00015  * SWKey Constructor - initializes instance of SWKey
00016  *
00017  * ENT: ikey - text key
00018  */
00019 
00020 SWKey::SWKey(const char *ikey)
00021 {
00022         index   = 0;
00023         persist = 0;
00024         keytext = 0;
00025         error   = 0;
00026         stdstr(&keytext, ikey);
00027         init();
00028 }
00029 
00030 SWKey::SWKey(SWKey const &k)
00031 {
00032         index   = k.index;
00033         persist = k.persist;
00034         keytext = 0;
00035         error = k.error;
00036         stdstr(&keytext, k.keytext);
00037         init();
00038 }
00039 
00040 void SWKey::init() {
00041         myclass = &classdef;
00042 }
00043 
00044 SWKey *SWKey::clone() const
00045 {
00046         return new SWKey(*this);
00047 }
00048 
00049 /******************************************************************************
00050  * SWKey Destructor - cleans up instance of SWKey
00051  */
00052 
00053 SWKey::~SWKey() {
00054         if (keytext)
00055                 delete [] keytext;
00056 }
00057 
00058 
00059 /******************************************************************************
00060  * SWKey::Persist - Gets whether this object itself persists within a
00061  *                      module that it was used to SetKey or just a copy.
00062  *                      (1 - persists in module; 0 - a copy is attempted
00063  *
00064  * RET: value of persist
00065  */
00066 
00067 char SWKey::Persist() const
00068 {
00069         return persist;
00070 }
00071 
00072 
00073 /******************************************************************************
00074  * SWKey::Persist - Set/gets whether this object itself persists within a
00075  *                      module that it was used to SetKey or just a copy.
00076  *                      (1 - persists in module; 0 - a copy is attempted
00077  *
00078  * ENT: ipersist - value which to set persist
00079  *              [-1] - only get
00080  *
00081  * RET: value of persist
00082  */
00083 
00084 char SWKey::Persist(signed char ipersist)
00085 {
00086         if (ipersist != -1)
00087                 persist = ipersist;
00088 
00089         return persist;
00090 }
00091 
00092 
00093 /******************************************************************************
00094  * SWKey::Error - Gets and clears error status
00095  *
00096  * RET: error status
00097  */
00098 
00099 char SWKey::Error()
00100 {
00101         char retval = error;
00102 
00103         error = 0;
00104         return retval;
00105 }
00106 
00107 
00108 /******************************************************************************
00109  * SWKey::setText Equates this SWKey to a character string
00110  *
00111  * ENT: ikey - other swkey object
00112  */
00113 
00114 void SWKey::setText(const char *ikey) {
00115         stdstr(&keytext, ikey);
00116 }
00117 
00118 
00119 /******************************************************************************
00120  * SWKey::copyFrom Equates this SWKey to another SWKey object
00121  *
00122  * ENT: ikey - other swkey object
00123  */
00124 
00125 void SWKey::copyFrom(const SWKey &ikey) {
00126 // not desirable        Persist(ikey.Persist());
00127         setText((const char *)ikey);
00128 }
00129 
00130 
00131 /******************************************************************************
00132  * SWKey::getText - returns text key if (char *) cast is requested
00133  */
00134 
00135 const char *SWKey::getText() const {
00136         return keytext;
00137 }
00138 
00139 
00140 /******************************************************************************
00141  * SWKey::compare       - Compares another VerseKey object
00142  *
00143  * ENT: ikey - key to compare with this one
00144  *
00145  * RET: > 0 if this key is greater than compare key
00146  *      < 0
00147  *        0
00148  */
00149 
00150 int SWKey::compare(const SWKey &ikey)
00151 {
00152         return strcmp((const char *)*this, (const char *)ikey);
00153 }
00154 
00155 
00156 /******************************************************************************
00157  * SWKey::setPosition(SW_POSITION)      - Positions this key if applicable
00158  */
00159 
00160 void SWKey::setPosition(SW_POSITION p) {
00161         switch (p) {
00162         case POS_TOP:
00163 //              *this = "";
00164                 break;
00165         case POS_BOTTOM:
00166 //              *this = "zzzzzzzzz";
00167                 break;
00168         } 
00169 }
00170 
00171 
00172 /******************************************************************************
00173  * SWKey::increment     - Increments key a number of entries
00174  *
00175  * ENT: increment       - Number of entries to jump forward
00176  *
00177  * RET: *this
00178  */
00179 
00180 void SWKey::increment(int) {
00181         error = KEYERR_OUTOFBOUNDS;
00182 }
00183 
00184 
00185 /******************************************************************************
00186  * SWKey::decrement     - Decrements key a number of entries
00187  *
00188  * ENT: decrement       - Number of entries to jump backward
00189  *
00190  * RET: *this
00191  */
00192 
00193 void SWKey::decrement(int) {
00194         error = KEYERR_OUTOFBOUNDS;
00195 }

Generated on Wed Apr 3 22:34:15 2002 for The Sword Project by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002