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 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055
00056
00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076
00077
00078
00079 #if !defined(NAMEIDPOOL_HPP)
00080 #define NAMEIDPOOL_HPP
00081
00082 #include <util/XercesDefs.hpp>
00083 #include <memory.h>
00084 #include <util/XMLEnumerator.hpp>
00085 #include <util/XMLString.hpp>
00086
00087
00088
00089
00090
00091
00092 template <class TElem> class NameIdPoolEnumerator;
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 template <class TElem> struct NameIdPoolBucketElem
00122 {
00123 public :
00124 NameIdPoolBucketElem
00125 (
00126 TElem* const value
00127 , NameIdPoolBucketElem<TElem>* const next
00128 );
00129 ~NameIdPoolBucketElem();
00130
00131 TElem* fData;
00132 NameIdPoolBucketElem<TElem>* fNext;
00133 };
00134
00135
00136 template <class TElem> class NameIdPool
00137 {
00138 public :
00139
00140
00141
00142 NameIdPool
00143 (
00144 const unsigned int hashModulus
00145 , const unsigned int initSize = 128
00146 );
00147
00148 ~NameIdPool();
00149
00150
00151
00152
00153
00154 bool containsKey(const XMLCh* const key) const;
00155 void removeAll();
00156
00157
00158
00159
00160
00161 TElem* getByKey(const XMLCh* const key);
00162 const TElem* getByKey(const XMLCh* const key) const;
00163 TElem* getById(const unsigned elemId);
00164 const TElem* getById(const unsigned elemId) const;
00165
00166
00167
00168
00169
00170
00171
00172
00173 unsigned int put(TElem* const valueToAdopt);
00174
00175
00176 protected :
00177
00178
00179
00180 friend class NameIdPoolEnumerator<TElem>;
00181
00182
00183 private :
00184
00185
00186
00187 NameIdPool(const NameIdPool<TElem>&);
00188 void operator=(const NameIdPool<TElem>&);
00189
00190
00191
00192
00193
00194 NameIdPoolBucketElem<TElem>* findBucketElem
00195 (
00196 const XMLCh* const key
00197 , unsigned int& hashVal
00198 );
00199 const NameIdPoolBucketElem<TElem>* findBucketElem
00200 (
00201 const XMLCh* const key
00202 , unsigned int& hashVal
00203 ) const;
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 NameIdPoolBucketElem<TElem>** fBucketList;
00232 TElem** fIdPtrs;
00233 unsigned int fIdPtrsCount;
00234 unsigned int fIdCounter;
00235 unsigned int fHashModulus;
00236 };
00237
00238
00239
00240
00241
00242
00243 template <class TElem> class NameIdPoolEnumerator : public XMLEnumerator<TElem>
00244 {
00245 public :
00246
00247
00248
00249 NameIdPoolEnumerator
00250 (
00251 NameIdPool<TElem>* const toEnum
00252 );
00253
00254 NameIdPoolEnumerator
00255 (
00256 const NameIdPoolEnumerator<TElem>& toCopy
00257 );
00258
00259 ~NameIdPoolEnumerator();
00260
00261
00262
00263
00264 NameIdPoolEnumerator<TElem>& operator=
00265 (
00266 const NameIdPoolEnumerator<TElem>& toAssign
00267 );
00268
00269
00270
00271
00272
00273 bool hasMoreElements() const;
00274 TElem& nextElement();
00275 void Reset();
00276
00277
00278 private :
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 unsigned int fCurIndex;
00290 NameIdPool<TElem>* fToEnum;
00291 };
00292
00293
00294 #if !defined(XERCES_TMPLSINC)
00295 #include <util/NameIdPool.c>
00296 #endif
00297
00298 #endif