00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef QINTDICT_H
00023 #define QINTDICT_H
00024
00025 #include "qdictbase.h"
00026
00027 namespace FX {
00028
00039 template<class type> class QIntDict : public QDictBase<FXint, type>
00040 {
00041 public:
00043 explicit QIntDict(int size=13, bool wantAutoDel=false) : QDictBase<FXint, type>(size, wantAutoDel) { }
00044 ~QIntDict() { QDictBase<FXint, type>::clear(); }
00046 void insert(FXint k, const type *d)
00047 {
00048 QDictBase<FXint, type>::insert(k, k, const_cast<type *>(d));
00049 }
00051 void replace(FXint k, const type *d)
00052 {
00053 QDictBase<FXint, type>::replace(k, k, const_cast<type *>(d));
00054 }
00056 bool remove(FXint k)
00057 {
00058 return QDictBase<FXint, type>::remove(k, k);
00059 }
00061 type *take(FXint k)
00062 {
00063 return QDictBase<FXint, type>::take(k, k);
00064 }
00066 type *find(FXint k) const
00067 {
00068 return QDictBase<FXint, type>::find(k, k);
00069 }
00071 type *operator[](FXint k) const { return find(k); }
00072 protected:
00073 virtual void deleteItem(type *d);
00074 };
00075
00076 template<class type> inline void QIntDict<type>::deleteItem(type *d)
00077 {
00078 if(QDictBase<FXint, type>::autoDelete())
00079 {
00080
00081 delete d;
00082 }
00083 }
00084
00085 template<> inline void QIntDict<void>::deleteItem(void *)
00086 {
00087 }
00088
00093 template<class type> class QIntDictIterator : public QDictBaseIterator<FXint, type>
00094 {
00095 public:
00096 QIntDictIterator() { }
00097 QIntDictIterator(const QIntDict<type> &d) : QDictBaseIterator<FXint, type>(d) { }
00098 };
00099
00101 template<class type> FXStream &operator<<(FXStream &s, const QIntDict<type> &i)
00102 {
00103 FXuint mysize=i.count();
00104 s << mysize;
00105 for(QIntDictIterator<type> it(i); it.current(); ++it)
00106 {
00107 s << (FXlong) it.currentKey();
00108 s << *it.current();
00109 }
00110 return s;
00111 }
00113 template<class type> FXStream &operator>>(FXStream &s, QIntDict<type> &i)
00114 {
00115 FXuint mysize;
00116 s >> mysize;
00117 i.clear();
00118 FXlong key;
00119 for(FXuint n=0; n<mysize; n++)
00120 {
00121 type *item;
00122 FXERRHM(item=new type);
00123 s >> key;
00124 s >> *item;
00125 i.insert((FXint) key, item);
00126 }
00127 return s;
00128 }
00129
00130 }
00131
00132 #endif