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 #include <sysdata.h>
00031 #include <utilstr.h>
00032
00033 SWORD_NAMESPACE_START
00034
00035 #define KEYERR_OUTOFBOUNDS 1
00036
00037 #define SWKEY_OPERATORS \
00038 SWKey &operator =(const char *ikey) { setText(ikey); return *this; } \
00039 SWKey &operator =(const SWKey &ikey) { positionFrom(ikey); return *this; } \
00040 SWKey &operator =(SW_POSITION pos) { setPosition(pos); return *this; } \
00041 operator const char *() const { return getText(); } \
00042 bool operator ==(const SWKey &ikey) { return equals(ikey); } \
00043 bool operator !=(const SWKey &ikey) { return !equals(ikey); } \
00044 virtual bool operator >(const SWKey &ikey) { return (compare(ikey) > 0); } \
00045 virtual bool operator <(const SWKey &ikey) { return (compare(ikey) < 0); } \
00046 virtual bool operator >=(const SWKey &ikey) { return (compare(ikey) > -1); } \
00047 virtual bool operator <=(const SWKey &ikey) { return (compare(ikey) < 1); } \
00048 SWKey &operator -=(int steps) { decrement(steps); return *this; } \
00049 SWKey &operator +=(int steps) { increment(steps); return *this; } \
00050 SWKey &operator ++() { increment(1); return *this; } \
00051 SWKey operator ++(int) { SWKey temp = *this; increment(1); return temp; } \
00052 SWKey &operator --() { decrement(1); return *this; } \
00053 SWKey operator --(int) { SWKey temp = *this; decrement(1); return temp; }
00054
00055
00058 class SW_POSITION {
00059 char pos;
00060 public:
00061 SW_POSITION(char ipos) { pos = ipos; }
00062 operator char() { return pos; }
00063 };
00064
00065 #define POS_TOP ((char)1)
00066 #define POS_BOTTOM ((char)2)
00067
00068 #define TOP SW_POSITION(POS_TOP)
00069 #define BOTTOM SW_POSITION(POS_BOTTOM)
00070
00071 class SWLocale;
00072
00077 class SWDLLEXPORT SWKey : public SWObject {
00078
00079 class LocaleCache {
00080 public:
00081 char *name;
00082 SWLocale *locale;
00083 LocaleCache() {
00084 name = 0;
00085 locale = 0;
00086 }
00087 virtual ~LocaleCache() {
00088 if (name)
00089 delete[]name;
00090 }
00091 };
00092 static LocaleCache localeCache;
00093
00094 mutable SWLocale *locale;
00095
00096
00097 long index;
00098 static SWClass classdef;
00099 void init();
00100
00101
00102 protected:
00103 char *keytext;
00104 mutable char *rangeText;
00105 mutable bool boundSet;
00106 bool persist;
00107 char error;
00108
00109 char *localeName;
00110 SWLocale *getPrivateLocale() const;
00111
00112
00113 public:
00114
00115
00116 __u64 userData;
00117
00123 SWKey(const char *ikey = 0);
00124
00128 SWKey(SWKey const &k);
00129
00132 virtual ~SWKey();
00133
00138 virtual SWKey *clone() const;
00139
00140
00145 bool isPersist() const;
00146 SWDEPRECATED char Persist() const { return isPersist(); }
00147
00153 SWDEPRECATED char Persist(signed char ipersist) { setPersist(ipersist); return isPersist(); }
00154 void setPersist(bool ipersist);
00155
00159 SWDEPRECATED char Error() { return popError(); }
00160 virtual char popError();
00161 virtual void setError(char err) { error = err; }
00162
00166 virtual void setText(const char *ikey);
00167
00171 virtual void copyFrom(const SWKey &ikey);
00172 virtual void positionFrom(const SWKey &ikey) { copyFrom(ikey); }
00173
00176 virtual const char *getText() const;
00177 virtual const char *getShortText() const { return getText(); }
00178 virtual const char *getRangeText() const;
00179 virtual const char *getOSISRefRangeText() const;
00180 virtual bool isBoundSet() const { return boundSet; }
00181 virtual void clearBound() const { boundSet = false; }
00182
00189 virtual int compare(const SWKey &ikey);
00190
00195 virtual bool equals(const SWKey &ikey) { return !compare(ikey); }
00196
00197 virtual void setPosition(SW_POSITION);
00198
00203 virtual void decrement(int steps = 1);
00204
00209 virtual void increment(int steps = 1);
00210
00213 virtual bool isTraversable() const { return false; }
00214
00215 char *getLocale() const { return localeName; }
00216 void setLocale(const char *name) { stdstr(&localeName, name); locale = 0; }
00217
00220 virtual long getIndex() const { return index; }
00221
00224 virtual void setIndex(long iindex) { index = iindex; }
00225
00226 SWKEY_OPERATORS
00227
00228 };
00229
00230 SWORD_NAMESPACE_END
00231 #endif