00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __SHAREDDATA_H__
00026 #define __SHAREDDATA_H__
00027
00028
00029
00030 #include <qvector.h>
00031 #include <qstring.h>
00032 #include <qdatetime.h>
00033 #include <qcstring.h>
00034 #include <qdatastream.h>
00035 #include <qintdict.h>
00036
00037 class DBStore;
00038
00039
00040 class QStringVector : public QVector<QString>
00041 {
00042 public:
00043 int compareItems(Item a, Item b);
00044 };
00045
00046
00047
00048
00049
00050
00051 class TVVariantPrivate;
00052
00053 class TVVariant
00054 {
00055 public:
00056 enum KeyType {
00057 Invalid = 0,
00058 Int,
00059 String,
00060 Date,
00061 Time,
00062 };
00063
00064 TVVariant();
00065 ~TVVariant();
00066
00067 TVVariant(const TVVariant&);
00068 TVVariant(QDataStream&);
00069
00070 TVVariant(const QString &);
00071 TVVariant(const int);
00072 TVVariant(const QDate &);
00073 TVVariant(const QTime &);
00074
00075 TVVariant& operator=(const TVVariant& );
00076 bool operator==(const TVVariant&) const;
00077 bool operator!=(const TVVariant&) const;
00078 bool operator<(const TVVariant&) const;
00079 bool operator>(const TVVariant&) const;
00080
00081 bool closer(TVVariant, TVVariant);
00082 bool close(TVVariant);
00083
00084 KeyType type() const;
00085 const QString typeName() const;
00086 int numTypes() const;
00087
00088 const QString typeName(KeyType) const;
00089 bool canCast(KeyType) const;
00090 bool isValid() const;
00091 void clear();
00092
00093 const QString toString() const;
00094 const QDate toDate() const;
00095 const QTime toTime() const;
00096 int toInt() const;
00097
00098 QString& asString();
00099 QDate& asDate();
00100 QTime& asTime();
00101 int& asInt();
00102
00103 void load(QDataStream&);
00104 void save(QDataStream&) const;
00105
00106 static const QString typeToName(KeyType typ);
00107 static KeyType nameToType(const QString &);
00108 private:
00109 void detach();
00110
00111 TVVariantPrivate *d;
00112 };
00113
00114 class TVVariantPrivate : public QShared
00115 {
00116 public:
00117 TVVariantPrivate();
00118 TVVariantPrivate(TVVariantPrivate *);
00119
00120 ~TVVariantPrivate();
00121
00122 void clear();
00123
00124 TVVariant::KeyType typ;
00125
00126 union {
00127 int i;
00128 void *ptr;
00129 } value;
00130 };
00131
00132 inline TVVariant::KeyType TVVariant::type() const
00133 {
00134 return d->typ;
00135 }
00136
00137 inline bool TVVariant::isValid() const
00138 {
00139 return (d->typ != Invalid);
00140 }
00141
00142 inline int TVVariant::numTypes() const
00143 {
00144 return 4;
00145 }
00146
00147 class Key {
00148 public:
00149 Key();
00150 Key(QString name, TVVariant example, int flags = 0);
00151 Key(const Key &);
00152 Key& operator=(const Key& );
00153
00154 QString name() const;
00155 TVVariant example() const;
00156 TVVariant::KeyType type() const;
00157 int flags() const;
00158
00159 void setName(const QString &);
00160 void setExample(const TVVariant &);
00161 void setFlags(int);
00162
00163 bool delFlag() const;
00164 bool newFlag() const;
00165
00166 void setDelFlag(bool);
00167 void setNewFlag(bool);
00168
00169 private:
00170 QString kname;
00171 TVVariant kexample;
00172 int kflags;
00173 };
00174
00175 class KeyList : public QIntDict<Key> {
00176 public:
00177 KeyList();
00178 KeyList(const KeyList&);
00179
00180 ~KeyList();
00181
00182 bool operator!=(const KeyList &);
00183
00184 int getNumFields() const;
00185
00186 int addKey(QString KeyName, TVVariant example);
00187 int addKey(QString KeyName, TVVariant::KeyType type);
00188
00189 TVVariant getKeyExample(int ) const;
00190 void setKeyExample(int, TVVariant e);
00191
00192 QString getKeyName(int i) const;
00193 void setKeyName(int i, const QString &n);
00194
00195 TVVariant::KeyType getKeyType(int i) const;
00196 void setKeyType(int i, TVVariant::KeyType);
00197
00198 int getKeyIndex(QString q) const;
00199
00200 int getKeyFlags(int i) const;
00201 void setKeyFlags(int i, int flag);
00202
00203
00204 bool checkNewFlag(int i) const;
00205 void setNewFlag(int i, bool f);
00206 bool checkDeleteFlag(int i) const;
00207 void setDeleteFlag(int i, bool f);
00208
00209 bool validIndex(int) const;
00210 };
00211
00212 class KeyListIterator : public QIntDictIterator<Key>
00213 {
00214 public:
00215 KeyListIterator(const KeyList &k) : QIntDictIterator<Key>(k) {};
00216 };
00217
00218
00219 class DataElem {
00220 public:
00221 DataElem(DBStore *container);
00222 ~DataElem();
00223
00224 int getNumFields() const;
00225 KeyList getKeys() const;
00226
00227 bool hasValidValue(int) const;
00228 bool hasValidValue(QString) const;
00229 TVVariant::KeyType getFieldType(int) const;
00230 TVVariant::KeyType getFieldType(QString) const;
00231 TVVariant getField(int) const;
00232 TVVariant getField(QString) const;
00233
00234 void setField(int, QString);
00235 void setField(int, TVVariant);
00236 void setField(QString, QString);
00237 void setField(QString, TVVariant);
00238 void unsetField(int);
00239 void unsetField(QString);
00240
00241 QString toQString() const;
00242 QString toQString(int i) const;
00243 QString toSortableQString(int i) const;
00244
00245
00246 bool lessThan(int i, TVVariant) const;
00247 bool moreThan(int i, TVVariant) const;
00248 bool equalTo(int i, TVVariant) const;
00249 bool contains(int i, TVVariant) const;
00250 bool startsWith(int i, TVVariant) const;
00251 bool endsWith(int i, TVVariant) const;
00252
00253
00254
00255 static int compare(const TVVariant, const TVVariant, int i);
00256
00257
00258
00259 static bool closer(DataElem*, DataElem *, TVVariant, int column);
00260 private:
00261 QIntDict<TVVariant> values;
00262 DBStore *contained;
00263 };
00264
00265 typedef struct _TableState {
00266 int current_column;
00267 KeyList *kRep;
00268 DataElem *current_elem;
00269 } TableState;
00270
00271
00272 #ifndef QT_NO_DATASTREAM
00273 Q_EXPORT QDataStream &operator<<( QDataStream &, const KeyList & );
00274 Q_EXPORT QDataStream &operator<<( QDataStream &, const DataElem & );
00275 Q_EXPORT QDataStream &operator>>( QDataStream &, KeyList & );
00276 Q_EXPORT QDataStream &operator>>( QDataStream &, DataElem & );
00277
00278
00279 Q_EXPORT QDataStream &operator>>( QDataStream &, TVVariant & );
00280 Q_EXPORT QDataStream &operator<<( QDataStream &, const TVVariant & );
00281 Q_EXPORT QDataStream &operator>>( QDataStream &, TVVariant::KeyType& );
00282 Q_EXPORT QDataStream &operator<<( QDataStream &, const TVVariant::KeyType& );
00283 #endif
00284
00285 #endif