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