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

Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by doxygen1.2.15