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 #ifndef DCHASHDI_H
00035 #define DCHASHDI_H
00036
00037 #include "dcmtk/config/osconfig.h"
00038 #include "dcmtk/ofstd/oflist.h"
00039 #include "dcmtk/ofstd/ofstream.h"
00040
00041 class DcmDictEntry;
00042 class DcmTagKey;
00043 class DcmHashDict;
00044
00046 const int DCMHASHDICT_DEFAULT_HASHSIZE = 2047;
00047
00049 typedef OFListIterator(DcmDictEntry *) OFListIteratorPDcmDictEntry;
00050 typedef OFListConstIterator(DcmDictEntry *) OFListConstIteratorPDcmDictEntry;
00051
00052
00055 class DcmDictEntryListIterator: public OFListIteratorPDcmDictEntry
00056 {
00057 public:
00059 DcmDictEntryListIterator() {}
00060
00064 DcmDictEntryListIterator(const OFListIterator(DcmDictEntry*)& iter)
00065 : OFListIterator(DcmDictEntry*)(iter) {}
00066
00068 DcmDictEntryListIterator& operator=(const DcmDictEntryListIterator& i)
00069 {
00070 OFListIteratorPDcmDictEntry::operator=(i);
00071 return *this;
00072 }
00073 };
00074
00077 class DcmDictEntryListConstIterator: public OFListConstIteratorPDcmDictEntry
00078 {
00079 public:
00081 DcmDictEntryListConstIterator() {}
00082
00086 DcmDictEntryListConstIterator(const OFListConstIterator(DcmDictEntry*)& iter)
00087 : OFListConstIterator(DcmDictEntry*)(iter) {}
00088
00090 DcmDictEntryListConstIterator& operator=(const DcmDictEntryListConstIterator& i)
00091 {
00092 OFListConstIteratorPDcmDictEntry::operator=(i);
00093 return *this;
00094 }
00095 };
00096
00097
00100 class DcmDictEntryList : public OFList<DcmDictEntry *>
00101 {
00102 public:
00104 DcmDictEntryList() {}
00105
00107 ~DcmDictEntryList();
00108
00110 void clear();
00111
00116 DcmDictEntry* insertAndReplace(DcmDictEntry* e);
00117
00118
00119 DcmDictEntry *find(const DcmTagKey& k, const char *privCreator);
00120
00121 private:
00123 DcmDictEntryList(const DcmDictEntryList&);
00124
00126 DcmDictEntryList& operator=(const DcmDictEntryList&);
00127
00128 };
00129
00130
00133 class DcmHashDictIterator
00134 {
00135 public:
00137 DcmHashDictIterator()
00138 : dict(NULL), hindex(0), iterating(OFFalse), iter()
00139 { init(NULL); }
00140
00146 DcmHashDictIterator(const DcmHashDict* d, OFBool atEnd = OFFalse)
00147 : dict(NULL), hindex(0), iterating(OFFalse), iter()
00148 { init(d, atEnd); }
00149
00151 DcmHashDictIterator(const DcmHashDictIterator& i)
00152 : dict(i.dict), hindex(i.hindex), iterating(i.iterating), iter(i.iter)
00153 { }
00154
00156 DcmHashDictIterator& operator=(const DcmHashDictIterator& i)
00157 { dict = i.dict; hindex = i.hindex;
00158 iterating = i.iterating; iter = i.iter; return *this; }
00159
00161 OFBool operator==(const DcmHashDictIterator& x) const
00162 { return (hindex == x.hindex) && (iter == x.iter); }
00163
00165 OFBool operator!=(const DcmHashDictIterator& x) const
00166 { return (hindex != hindex) || (iter != x.iter); }
00167
00169 const DcmDictEntry* operator*() const
00170 { return (*iter); }
00171
00173 DcmHashDictIterator& operator++()
00174 { stepUp(); return *this; }
00175
00177 DcmHashDictIterator operator++(int)
00178 { DcmHashDictIterator tmp(*this); stepUp(); return tmp; }
00179
00180 private:
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 ostream& loadSummary(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