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

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.7 2002/06/20 20:23:10 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 #define KEYERR_OUTOFBOUNDS 1
00032 
00033 #define SWKEY_OPERATORS \
00034   SWKey & operator = (const char *ikey) { setText(ikey); return *this; } \
00035   SWKey & operator = (const SWKey &ikey) { copyFrom(ikey); return *this; } \
00036   SWKey & operator = (SW_POSITION pos) { setPosition(pos); return *this; } \
00037   operator const char *() const { return getText(); } \
00038   bool operator == (const SWKey & ikey) { return equals(ikey); } \
00039   bool operator != (const SWKey & ikey) { return !equals(ikey); } \
00040   virtual bool operator > (const SWKey & ikey) { return (compare (ikey) > 0); } \
00041   virtual bool operator < (const SWKey & ikey) { return (compare (ikey) < 0); } \
00042   virtual bool operator >= (const SWKey & ikey) { return (compare (ikey) > -1); }  \
00043   virtual bool operator <= (const SWKey & ikey) { return (compare (ikey) < 1); } \
00044   SWKey & operator -= (int steps) { decrement(steps); return *this; } \
00045   SWKey & operator += (int steps) { increment(steps); return *this; } \
00046   SWKey & operator++ (int) { return *this += 1; } \
00047   SWKey & operator-- (int) { return *this -= 1; }
00048 
00049 
00050 // For use with = operator to position key.
00051 
00052 class SW_POSITION
00053 {
00054   char pos;
00055 public:
00056     SW_POSITION (char ipos)
00057   {
00058     pos = ipos;
00059   }
00060   operator char ()
00061   {
00062     return pos;
00063   }
00064 };
00065 
00066 #define POS_TOP ((char)1)
00067 #define POS_BOTTOM ((char)2)
00068 
00069 #define TOP SW_POSITION(POS_TOP)
00070 #define BOTTOM SW_POSITION(POS_BOTTOM)
00071 
00076 class SWDLLEXPORT SWKey : public SWObject {
00077   long index;
00078   static SWClass classdef;
00079   void init ();
00080 
00081 protected:
00082   char *keytext;
00083   char persist;
00084   char error;
00085 
00086 public:
00087 
00088   // misc pointer for whatever
00089   void *userData;
00090 
00095   SWKey (const char *ikey = 0);
00096 
00100   SWKey (SWKey const &k);
00101 
00104   virtual ~ SWKey ();
00105 
00110   virtual SWKey *clone () const;
00111 
00118   char Persist () const;
00119 
00128   char Persist (signed char ikey);
00129 
00134   virtual char Error ();
00135 
00140   virtual void setText(const char *ikey);
00141 
00146   virtual void copyFrom(const SWKey &ikey);
00147 
00150   virtual const char *getText() const;
00151   virtual const char *getShortText() const { return getText(); }
00152 
00160   virtual int compare (const SWKey & ikey);
00161 
00167   virtual bool equals(const SWKey &ikey) { return !compare(ikey); }
00168 
00169   virtual void setPosition(SW_POSITION);
00170 
00176   virtual void decrement(int steps = 1);
00177 
00183   virtual void increment(int steps = 1);
00184 
00185   virtual char Traversable () { return 0; }
00186 
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 
00216 #endif

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