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

swkey.h

00001 /******************************************************************************
00002  *  swkey.h     - 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  * $Id: swkey_8h-source.html,v 1.1 2003/02/28 21:22:00 mgruner Exp $
00007  *
00008  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00009  *      CrossWire Bible Society
00010  *      P. O. Box 2528
00011  *      Tempe, AZ  85280-2528
00012  *
00013  * This program is free software; you can redistribute it and/or modify it
00014  * under the terms of the GNU General Public License as published by the
00015  * Free Software Foundation version 2.
00016  *
00017  * This program is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * General Public License for more details.
00021  *
00022  */
00023 
00024 #ifndef SWKEY_H
00025 #define SWKEY_H
00026 
00027 #include <swobject.h>
00028 
00029 #include <defs.h>
00030 
00031 SWORD_NAMESPACE_START
00032 
00033 #define KEYERR_OUTOFBOUNDS 1
00034 
00035 #define SWKEY_OPERATORS \
00036   SWKey & operator =(const char *ikey) { setText(ikey); return *this; } \
00037   SWKey & operator =(const SWKey &ikey) { copyFrom(ikey); return *this; } \
00038   SWKey & operator =(SW_POSITION pos) { setPosition(pos); return *this; } \
00039   operator const char *() const { return getText(); } \
00040   bool operator ==(const SWKey & ikey) { return equals(ikey); } \
00041   bool operator !=(const SWKey & ikey) { return !equals(ikey); } \
00042   virtual bool operator >(const SWKey & ikey) { return (compare(ikey) > 0); } \
00043   virtual bool operator <(const SWKey & ikey) { return (compare(ikey) < 0); } \
00044   virtual bool operator >=(const SWKey & ikey) { return (compare(ikey) > -1); }  \
00045   virtual bool operator <=(const SWKey & ikey) { return (compare(ikey) < 1); } \
00046   SWKey & operator -=(int steps) { decrement(steps); return *this; } \
00047   SWKey & operator +=(int steps) { increment(steps); return *this; } \
00048   SWKey & operator++(int) { return *this += 1; } \
00049   SWKey & operator--(int) { return *this -= 1; }
00050 
00051 
00052 // For use with = operator to position key.
00053 
00054 class SW_POSITION {
00055         char pos;
00056 public:
00057         SW_POSITION(char ipos) { pos = ipos; }
00058         operator char() { return pos; }
00059 };
00060 
00061 #define POS_TOP ((char)1)
00062 #define POS_BOTTOM ((char)2)
00063 
00064 #define TOP SW_POSITION(POS_TOP)
00065 #define BOTTOM SW_POSITION(POS_BOTTOM)
00066 
00071 class SWDLLEXPORT SWKey : public SWObject {
00072         long index;
00073         static SWClass classdef;
00074         void init();
00075 
00076 protected:
00077         char *keytext;
00078         mutable char *rangeText;
00079         mutable bool boundSet;
00080         char persist;
00081         char error;
00082 
00083 public:
00084 
00085         // misc pointer for whatever
00086         void *userData;
00087 
00092         SWKey(const char *ikey = 0);
00093 
00097         SWKey(SWKey const &k);
00098 
00101         virtual ~SWKey();
00102 
00107         virtual SWKey *clone() const;
00108 
00115         char Persist() const;
00116 
00125         char Persist(signed char ipersist);
00126 
00131         virtual char Error();
00132 
00137         virtual void setText(const char *ikey);
00138 
00143         virtual void copyFrom(const SWKey &ikey);
00144 
00147         virtual const char *getText() const;
00148         virtual const char *getShortText() const { return getText(); }
00149         virtual const char *getRangeText() const;
00150         virtual bool isBoundSet() const { return boundSet; }
00151 
00159         virtual int compare(const SWKey & ikey);
00160 
00166         virtual bool equals(const SWKey &ikey) { return !compare(ikey); }
00167 
00168         virtual void setPosition(SW_POSITION);
00169 
00175         virtual void decrement(int steps = 1);
00176 
00182         virtual void increment(int steps = 1);
00183 
00184         virtual char Traversable() { return 0; }
00185 
00208         virtual long Index() const { return index; }
00209         virtual long Index(long iindex) { index = iindex; return index; }
00210 
00211         SWKEY_OPERATORS
00212 
00213         };
00214 
00215 SWORD_NAMESPACE_END
00216 #endif

Generated on Fri Feb 28 22:01:39 2003 for The Sword Project by doxygen1.3-rc3