Main Page   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.4 2002/01/22 14:20:28 jansorg 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 {
00078   long index;
00079   static SWClass classdef;
00080   void init ();
00081 
00082 protected:
00083   char *keytext;
00084   char persist;
00085   char error;
00086 
00087 public:
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 (char ikey);
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 
00156   virtual int compare (const SWKey & ikey);
00157 
00163   virtual bool equals(const SWKey &ikey) { return !compare(ikey); }
00164 
00165   virtual void setPosition(SW_POSITION);
00166 
00172   virtual void decrement(int steps = 1);
00173 
00179   virtual void increment(int steps = 1);
00180 
00181   virtual char Traversable () { return 0; }
00182 
00204   virtual long Index () const { return index; }
00205 
00206   virtual long Index (long iindex) { index = iindex; return index; }
00207 
00208   SWKEY_OPERATORS
00209 
00210 };
00211 
00212 
00213 #endif

Generated at Tue Jan 22 14:52:48 2002 for The Sword Project by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001