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 #ifndef DCHASHDI_H
00030 #define DCHASHDI_H
00031
00032 #include "dcmtk/config/osconfig.h"
00033 #include "dcmtk/ofstd/oflist.h"
00034 #include "dcmtk/ofstd/ofstream.h"
00035
00036 class DcmDictEntry;
00037 class DcmTagKey;
00038 class DcmHashDict;
00039
00041 const int DCMHASHDICT_DEFAULT_HASHSIZE = 2047;
00042
00044 typedef OFListIterator(DcmDictEntry *) OFListIteratorPDcmDictEntry;
00045 typedef OFListConstIterator(DcmDictEntry *) OFListConstIteratorPDcmDictEntry;
00046
00047
00050 class DcmDictEntryListIterator: public OFListIteratorPDcmDictEntry
00051 {
00052 public:
00053
00055 DcmDictEntryListIterator() {}
00056
00060 DcmDictEntryListIterator(const OFListIterator(DcmDictEntry*)& iter)
00061 : OFListIterator(DcmDictEntry*)(iter) {}
00062
00064 DcmDictEntryListIterator& operator=(const DcmDictEntryListIterator& i)
00065 {
00066 OFListIteratorPDcmDictEntry::operator=(i);
00067 return *this;
00068 }
00069 };
00070
00073 class DcmDictEntryListConstIterator: public OFListConstIteratorPDcmDictEntry
00074 {
00075 public:
00076
00078 DcmDictEntryListConstIterator() {}
00079
00083 DcmDictEntryListConstIterator(const OFListConstIterator(DcmDictEntry*)& iter)
00084 : OFListConstIterator(DcmDictEntry*)(iter) {}
00085
00087 DcmDictEntryListConstIterator& operator=(const DcmDictEntryListConstIterator& i)
00088 {
00089 OFListConstIteratorPDcmDictEntry::operator=(i);
00090 return *this;
00091 }
00092 };
00093
00094
00097 class DcmDictEntryList : public OFList<DcmDictEntry *>
00098 {
00099 public:
00100
00102 DcmDictEntryList() {}
00103
00105 ~DcmDictEntryList();
00106
00108 void clear();
00109
00114 DcmDictEntry* insertAndReplace(DcmDictEntry* e);
00115
00116
00117 DcmDictEntry *find(const DcmTagKey& k, const char *privCreator);
00118
00119 private:
00120
00122 DcmDictEntryList(const DcmDictEntryList&);
00123
00125 DcmDictEntryList& operator=(const DcmDictEntryList&);
00126 };
00127
00128
00131 class DcmHashDictIterator
00132 {
00133 public:
00134
00136 DcmHashDictIterator()
00137 : dict(NULL), hindex(0), iterating(OFFalse), iter()
00138 { init(NULL); }
00139
00145 DcmHashDictIterator(const DcmHashDict* d, OFBool atEnd = OFFalse)
00146 : dict(NULL), hindex(0), iterating(OFFalse), iter()
00147 { init(d, atEnd); }
00148
00150 DcmHashDictIterator(const DcmHashDictIterator& i)
00151 : dict(i.dict), hindex(i.hindex), iterating(i.iterating), iter(i.iter)
00152 { }
00153
00155 DcmHashDictIterator& operator=(const DcmHashDictIterator& i)
00156 { dict = i.dict; hindex = i.hindex;
00157 iterating = i.iterating; iter = i.iter; return *this; }
00158
00160 OFBool operator==(const DcmHashDictIterator& x) const
00161 { return (hindex == x.hindex) && (iter == x.iter); }
00162
00164 OFBool operator!=(const DcmHashDictIterator& x) const
00165 { return !(*this == x); }
00166
00168 const DcmDictEntry* operator*() const
00169 { return (*iter); }
00170
00172 DcmHashDictIterator& operator++()
00173 { stepUp(); return *this; }
00174
00176 DcmHashDictIterator operator++(int)
00177 { DcmHashDictIterator tmp(*this); stepUp(); return tmp; }
00178
00179 private:
00180
00186 void init(const DcmHashDict *d, OFBool atEnd = OFFalse);
00187
00190 void stepUp();
00191
00193 const DcmHashDict* dict;
00194
00196 int hindex;
00197
00199 OFBool iterating;
00200
00202 DcmDictEntryListIterator iter;
00203 };
00204
00205
00208 class DcmHashDict
00209 {
00210
00211 public:
00215 DcmHashDict(int hashTabLen = DCMHASHDICT_DEFAULT_HASHSIZE)
00216 : hashTab(NULL), hashTabLength(0), lowestBucket(0), highestBucket(0), entryCount(0)
00217 { _init(hashTabLen); }
00218
00220 ~DcmHashDict();
00221
00223 int size() const { return entryCount; }
00224
00226 void clear();
00227
00231 void put(DcmDictEntry* e);
00232
00237 const DcmDictEntry* get(const DcmTagKey& key, const char *privCreator) const;
00238
00243 void del(const DcmTagKey& k, const char *privCreator);
00244
00245
00246 friend class DcmHashDictIterator;
00247
00249 DcmHashDictIterator begin() const
00250 { DcmHashDictIterator iter(this); return iter; }
00251
00253 DcmHashDictIterator end() const
00254 { DcmHashDictIterator iter(this, OFTrue); return iter; }
00255
00257 STD_NAMESPACE ostream& loadSummary(STD_NAMESPACE ostream& out);
00258
00259 private:
00260
00262 DcmHashDict(const DcmHashDict &);
00263
00265 DcmHashDict &operator=(const DcmHashDict &);
00266
00268 void _init(int hashSize);
00269
00274 int hash(const DcmTagKey* k) const;
00275
00281 DcmDictEntry* insertInList(DcmDictEntryList& lst, DcmDictEntry* e);
00282
00289 DcmDictEntry* removeInList(DcmDictEntryList& lst, const DcmTagKey& k, const char *privCreator);
00290
00297 DcmDictEntry* findInList(DcmDictEntryList& lst, const DcmTagKey& k, const char *privCreator) const;
00298
00302 DcmDictEntryList** hashTab;
00303
00305 int hashTabLength;
00306
00308 int lowestBucket;
00309
00311 int highestBucket;
00312
00314 int entryCount;
00315
00316 };
00317
00318 #endif
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399