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
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
00093 SWKey(const char *ikey = 0);
00094
00098 SWKey(SWKey const &k);
00099
00102 virtual ~SWKey();
00103
00108 virtual SWKey *clone() const;
00109
00114 char Persist() const;
00115
00121 char Persist(signed char ipersist);
00122
00126 virtual char Error();
00127
00131 virtual void setText(const char *ikey);
00132
00136 virtual void copyFrom(const SWKey &ikey);
00137
00140 virtual const char *getText() const;
00141 virtual const char *getShortText() const { return getText(); }
00142 virtual const char *getRangeText() const;
00143 virtual bool isBoundSet() const { return boundSet; }
00144
00151 virtual int compare(const SWKey &ikey);
00152
00157 virtual bool equals(const SWKey &ikey) { return !compare(ikey); }
00158
00159 virtual void setPosition(SW_POSITION);
00160
00165 virtual void decrement(int steps = 1);
00166
00171 virtual void increment(int steps = 1);
00172
00175 char Traversable() { return (isTraversable()) ? 1:0; }
00176
00179 virtual bool isTraversable() const { return false; }
00180
00202 virtual long Index() const { return index; }
00203
00206 virtual long Index(long iindex) { index = iindex; return index; }
00207
00208 SWKEY_OPERATORS
00209
00210 };
00211
00212 SWORD_NAMESPACE_END
00213 #endif