00001 /* 00002 * 00003 * Copyright (C) 1994-2005, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: dcmdata 00019 * 00020 * Author: Andrew Hewett 00021 * 00022 * Purpose: Hash table interface for DICOM data dictionary 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:28:14 $ 00026 * Source File: $Source: /share/dicom/cvs-depot/dcmtk/dcmdata/include/dcmtk/dcmdata/dchashdi.h,v $ 00027 * CVS/RCS Revision: $Revision: 1.17 $ 00028 * Status: $State: Exp $ 00029 * 00030 * CVS/RCS Log at end of file 00031 * 00032 */ 00033 00034 #ifndef DCHASHDI_H 00035 #define DCHASHDI_H 00036 00037 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 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 /* find an entry in the set */ 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 // iterator over the contents of the hash table 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 /* DCHASHDI_H */ 00319 00320 /* 00321 ** CVS/RCS Log: 00322 ** $Log: dchashdi.h,v $ 00323 ** Revision 1.17 2005/12/08 16:28:14 meichel 00324 ** Changed include path schema for all DCMTK header files 00325 ** 00326 ** Revision 1.16 2003/07/03 15:38:10 meichel 00327 ** Introduced DcmDictEntryListConstIterator, needed for compiling with HAVE_STL. 00328 ** 00329 ** Revision 1.15 2003/06/12 13:35:04 joergr 00330 ** Fixed inconsistent API documentation reported by Doxygen. 00331 ** 00332 ** Revision 1.14 2003/06/03 10:26:17 meichel 00333 ** Renamed local variables to avoid name clashes with STL 00334 ** 00335 ** Revision 1.13 2003/06/02 17:03:58 meichel 00336 ** Added typedef needed by MSVC5 when compiling with STL support 00337 ** 00338 ** Revision 1.12 2003/03/21 13:06:46 meichel 00339 ** Minor code purifications for warnings reported by MSVC in Level 4 00340 ** 00341 ** Revision 1.11 2002/07/23 14:21:26 meichel 00342 ** Added support for private tag data dictionaries to dcmdata 00343 ** 00344 ** Revision 1.10 2001/06/01 15:48:40 meichel 00345 ** Updated copyright header 00346 ** 00347 ** Revision 1.9 2000/05/03 14:19:08 meichel 00348 ** Added new class GlobalDcmDataDictionary which implements read/write lock 00349 ** semantics for safe access to the DICOM dictionary from multiple threads 00350 ** in parallel. The global dcmDataDict now uses this class. 00351 ** 00352 ** Revision 1.8 2000/03/08 16:26:15 meichel 00353 ** Updated copyright header. 00354 ** 00355 ** Revision 1.7 1999/03/31 09:24:39 meichel 00356 ** Updated copyright header in module dcmdata 00357 ** 00358 ** Revision 1.6 1998/07/15 15:48:48 joergr 00359 ** Removed several compiler warnings reported by gcc 2.8.1 with 00360 ** additional options, e.g. missing copy constructors and assignment 00361 ** operators, initialization of member variables in the body of a 00362 ** constructor instead of the member initialization list, hiding of 00363 ** methods by use of identical names, uninitialized member variables, 00364 ** missing const declaration of char pointers. Replaced tabs by spaces. 00365 ** 00366 ** Revision 1.5 1997/09/18 11:41:13 meichel 00367 ** Corrected forward and friend declarations (needed for DEC cxx). 00368 ** 00369 ** Revision 1.4 1997/09/18 07:24:07 meichel 00370 ** Missing operator= added to class DcmDictEntryListIterator 00371 ** 00372 ** Revision 1.3 1997/08/29 13:11:09 andreas 00373 ** Corrected copy constructor for DcmHashDictIterator 00374 ** 00375 ** Revision 1.2 1997/08/26 13:41:11 hewett 00376 ** Corrected a couple of minor spelling errors. 00377 ** 00378 ** Revision 1.1 1997/08/26 13:30:29 hewett 00379 ** Initial Version - Interface for hash table data structure for data dictionary. 00380 ** 00381 */ 00382