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