00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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