dcmdata/include/dcmtk/dcmdata/dchashdi.h

00001 /*
00002  *
00003  *  Copyright (C) 1994-2010, OFFIS e.V.
00004  *  All rights reserved.  See COPYRIGHT file for details.
00005  *
00006  *  This software and supporting documentation were developed by
00007  *
00008  *    OFFIS e.V.
00009  *    R&D Division Health
00010  *    Escherweg 2
00011  *    D-26121 Oldenburg, Germany
00012  *
00013  *
00014  *  Module:  dcmdata
00015  *
00016  *  Author:  Andrew Hewett
00017  *
00018  *  Purpose: Hash table interface for DICOM data dictionary
00019  *
00020  *  Last Update:      $Author: uli $
00021  *  Update Date:      $Date: 2010-11-10 12:04:06 $
00022  *  CVS/RCS Revision: $Revision: 1.22 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 #ifndef DCHASHDI_H
00030 #define DCHASHDI_H
00031 
00032 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
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     /* find an entry in the set */
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     // 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     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 /* DCHASHDI_H */
00319 
00320 
00321 /*
00322 ** CVS/RCS Log:
00323 ** $Log: dchashdi.h,v $
00324 ** Revision 1.22  2010-11-10 12:04:06  uli
00325 ** Corrected DcmHashDictIterator::operator!=. Previously it ignored hindex.
00326 **
00327 ** Revision 1.21  2010-10-14 13:15:41  joergr
00328 ** Updated copyright header. Added reference to COPYRIGHT file.
00329 **
00330 ** Revision 1.20  2009-01-05 14:14:14  joergr
00331 ** Fixed bug in DcmHashDictIterator::operator!=() introduced with last commit.
00332 ** Reverted to old implementation.
00333 **
00334 ** Revision 1.19  2008-12-19 14:57:59  joergr
00335 ** Fixed bug in DcmHashDictIterator::operator!=() - wrong comparison operand.
00336 **
00337 ** Revision 1.18  2006/08/15 15:49:56  meichel
00338 ** Updated all code in module dcmdata to correctly compile when
00339 **   all standard C++ classes remain in namespace std.
00340 **
00341 ** Revision 1.17  2005/12/08 16:28:14  meichel
00342 ** Changed include path schema for all DCMTK header files
00343 **
00344 ** Revision 1.16  2003/07/03 15:38:10  meichel
00345 ** Introduced DcmDictEntryListConstIterator, needed for compiling with HAVE_STL.
00346 **
00347 ** Revision 1.15  2003/06/12 13:35:04  joergr
00348 ** Fixed inconsistent API documentation reported by Doxygen.
00349 **
00350 ** Revision 1.14  2003/06/03 10:26:17  meichel
00351 ** Renamed local variables to avoid name clashes with STL
00352 **
00353 ** Revision 1.13  2003/06/02 17:03:58  meichel
00354 ** Added typedef needed by MSVC5 when compiling with STL support
00355 **
00356 ** Revision 1.12  2003/03/21 13:06:46  meichel
00357 ** Minor code purifications for warnings reported by MSVC in Level 4
00358 **
00359 ** Revision 1.11  2002/07/23 14:21:26  meichel
00360 ** Added support for private tag data dictionaries to dcmdata
00361 **
00362 ** Revision 1.10  2001/06/01 15:48:40  meichel
00363 ** Updated copyright header
00364 **
00365 ** Revision 1.9  2000/05/03 14:19:08  meichel
00366 ** Added new class GlobalDcmDataDictionary which implements read/write lock
00367 **   semantics for safe access to the DICOM dictionary from multiple threads
00368 **   in parallel. The global dcmDataDict now uses this class.
00369 **
00370 ** Revision 1.8  2000/03/08 16:26:15  meichel
00371 ** Updated copyright header.
00372 **
00373 ** Revision 1.7  1999/03/31 09:24:39  meichel
00374 ** Updated copyright header in module dcmdata
00375 **
00376 ** Revision 1.6  1998/07/15 15:48:48  joergr
00377 ** Removed several compiler warnings reported by gcc 2.8.1 with
00378 ** additional options, e.g. missing copy constructors and assignment
00379 ** operators, initialization of member variables in the body of a
00380 ** constructor instead of the member initialization list, hiding of
00381 ** methods by use of identical names, uninitialized member variables,
00382 ** missing const declaration of char pointers. Replaced tabs by spaces.
00383 **
00384 ** Revision 1.5  1997/09/18 11:41:13  meichel
00385 ** Corrected forward and friend declarations (needed for DEC cxx).
00386 **
00387 ** Revision 1.4  1997/09/18 07:24:07  meichel
00388 ** Missing operator= added to class DcmDictEntryListIterator
00389 **
00390 ** Revision 1.3  1997/08/29 13:11:09  andreas
00391 ** Corrected copy constructor for DcmHashDictIterator
00392 **
00393 ** Revision 1.2  1997/08/26 13:41:11  hewett
00394 ** Corrected a couple of minor spelling errors.
00395 **
00396 ** Revision 1.1  1997/08/26 13:30:29  hewett
00397 ** Initial Version - Interface for hash table data structure for data dictionary.
00398 **
00399 */


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1