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 #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
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
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