dcmdata/include/dcmtk/dcmdata/dcdict.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: Interface for loadable DICOM data dictionary
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:15:40 $
00022  *  CVS/RCS Revision: $Revision: 1.24 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef DCMDICT_H
00031 #define DCMDICT_H
00032 
00033 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
00034 
00035 #include "dcmtk/ofstd/ofthread.h"
00036 #include "dcmtk/dcmdata/dchashdi.h"
00037 
00039 #define DCM_MAXDICTLINESIZE     2048
00040 
00042 #define DCM_MAXDICTFIELDS       6
00043 
00045 #define DCM_DICT_ENVIRONMENT_VARIABLE   "DCMDICTPATH"
00046 
00047 #ifndef DCM_DICT_DEFAULT_PATH
00048 /*
00049 ** The default dictionary path is system dependent.  It should
00050 ** be defined in a configuration file included from "osconfig.h"
00051 */
00052 #error "DCM_DICT_DEFAULT_PATH is not defined via osconfig.h"
00053 #endif /* !DCM_DICT_DEFAULT_PATH */
00054 
00055 #ifndef ENVIRONMENT_PATH_SEPARATOR
00056 #define ENVIRONMENT_PATH_SEPARATOR '\n' /* at least define something unlikely */
00057 #endif
00058 
00059 
00062 class DcmDataDictionary
00063 {
00064 public:
00065 
00072     DcmDataDictionary(OFBool loadBuiltin, OFBool loadExternal);
00073 
00075     ~DcmDataDictionary();
00076 
00080     OFBool isDictionaryLoaded() const { return dictionaryLoaded; }
00081 
00083     int numberOfNormalTagEntries() const { return hashDict.size(); }
00084 
00086     int numberOfRepeatingTagEntries() const { return OFstatic_cast(int, repDict.size()); }
00087 
00091     int numberOfEntries() const
00092         { return numberOfNormalTagEntries()
00093               + numberOfRepeatingTagEntries() - skeletonCount; }
00094 
00100     int numberOfSkeletonEntries() const { return skeletonCount; }
00101 
00109     OFBool reloadDictionaries(OFBool loadBuiltin, OFBool loadExternal);
00110 
00118     OFBool loadDictionary(const char* fileName, OFBool errorIfAbsent = OFTrue);
00119 
00126     const DcmDictEntry* findEntry(const DcmTagKey& key, const char *privCreator) const;
00127 
00134     const DcmDictEntry* findEntry(const char *name) const;
00135 
00137     void clear();
00138 
00146     void addEntry(DcmDictEntry* entry);
00147 
00148     /* Iterators to access the normal and the repeating entries */
00149 
00151     DcmHashDictIterator normalBegin() { return hashDict.begin(); }
00152 
00154     DcmHashDictIterator normalEnd() { return hashDict.end(); }
00155 
00157     DcmDictEntryListIterator repeatingBegin() { return repDict.begin(); }
00158 
00160     DcmDictEntryListIterator repeatingEnd() { return repDict.end(); }
00161 
00162 private:
00163 
00166     DcmDataDictionary &operator=(const DcmDataDictionary &);
00167 
00170     DcmDataDictionary(const DcmDataDictionary &);
00171 
00175     OFBool loadExternalDictionaries();
00176 
00181     void loadBuiltinDictionary();
00182 
00186     OFBool loadSkeletonDictionary();
00187 
00191     const DcmDictEntry* findEntry(const DcmDictEntry& entry) const;
00192 
00195     void deleteEntry(const DcmDictEntry& entry);
00196 
00197 
00200     DcmHashDict hashDict;
00201 
00204     DcmDictEntryList repDict;
00205 
00208     int skeletonCount;
00209 
00212     OFBool dictionaryLoaded;
00213 
00214 };
00215 
00216 
00223 class GlobalDcmDataDictionary
00224 {
00225 public:
00230   GlobalDcmDataDictionary(OFBool loadBuiltin, OFBool loadExternal);
00231 
00234   ~GlobalDcmDataDictionary();
00235 
00240   const DcmDataDictionary& rdlock();
00241 
00246   DcmDataDictionary& wrlock();
00247 
00250   void unlock();
00251 
00257   OFBool isDictionaryLoaded();
00258 
00264   void clear();
00265 
00266 private:
00269   GlobalDcmDataDictionary &operator=(const GlobalDcmDataDictionary &);
00270 
00273   GlobalDcmDataDictionary(const GlobalDcmDataDictionary &);
00274 
00277   DcmDataDictionary dataDict;
00278 
00279 #ifdef WITH_THREADS
00280 
00282   OFReadWriteLock dataDictLock;
00283 #endif
00284 };
00285 
00286 
00298 extern GlobalDcmDataDictionary dcmDataDict;
00299 
00300 #endif
00301 
00302 
00303 /*
00304 ** CVS/RCS Log:
00305 ** $Log: dcdict.h,v $
00306 ** Revision 1.24  2010-10-14 13:15:40  joergr
00307 ** Updated copyright header. Added reference to COPYRIGHT file.
00308 **
00309 ** Revision 1.23  2010-10-04 14:44:39  joergr
00310 ** Replaced "#ifdef _REENTRANT" by "#ifdef WITH_THREADS" where appropriate (i.e.
00311 ** in all cases where OFMutex, OFReadWriteLock, etc. are used).
00312 **
00313 ** Revision 1.22  2009-02-05 13:13:51  joergr
00314 ** Added reload method to data dictionary class.
00315 **
00316 ** Revision 1.21  2008-08-15 09:27:14  meichel
00317 ** Added type cast to fix a warning
00318 **
00319 ** Revision 1.20  2005/12/08 16:28:09  meichel
00320 ** Changed include path schema for all DCMTK header files
00321 **
00322 ** Revision 1.19  2004/01/16 14:07:27  joergr
00323 ** Removed acknowledgements with e-mail addresses from CVS log.
00324 **
00325 ** Revision 1.18  2002/07/23 14:21:25  meichel
00326 ** Added support for private tag data dictionaries to dcmdata
00327 **
00328 ** Revision 1.17  2002/02/27 14:21:20  meichel
00329 ** Declare dcmdata read/write locks only when compiled in multi-thread mode
00330 **
00331 ** Revision 1.16  2001/06/01 15:48:38  meichel
00332 ** Updated copyright header
00333 **
00334 ** Revision 1.15  2000/05/03 14:19:08  meichel
00335 ** Added new class GlobalDcmDataDictionary which implements read/write lock
00336 **   semantics for safe access to the DICOM dictionary from multiple threads
00337 **   in parallel. The global dcmDataDict now uses this class.
00338 **
00339 ** Revision 1.14  2000/03/08 16:26:13  meichel
00340 ** Updated copyright header.
00341 **
00342 ** Revision 1.13  1999/03/31 09:24:35  meichel
00343 ** Updated copyright header in module dcmdata
00344 **
00345 ** Revision 1.12  1998/07/15 15:48:45  joergr
00346 ** Removed several compiler warnings reported by gcc 2.8.1 with
00347 ** additional options, e.g. missing copy constructors and assignment
00348 ** operators, initialization of member variables in the body of a
00349 ** constructor instead of the member initialization list, hiding of
00350 ** methods by use of identical names, uninitialized member variables,
00351 ** missing const declaration of char pointers. Replaced tabs by spaces.
00352 **
00353 ** Revision 1.11  1997/08/26 14:02:56  hewett
00354 ** New data structures for data-dictionary.  The main part of the
00355 ** data-dictionary is now stored in an hash table using an optimized
00356 ** hash function.  This new data structure reduces data-dictionary
00357 ** load times by a factor of 4!  he data-dictionary specific linked-list
00358 ** has been replaced by a linked list derived from OFList class
00359 ** (see ofstd/include/oflist.h).
00360 ** The only interface modifications are related to iterating over the entire
00361 ** data dictionary which should not be needed by "normal" applications.
00362 **
00363 ** Revision 1.10  1997/07/21 08:25:07  andreas
00364 ** - Replace all boolean types (BOOLEAN, CTNBOOLEAN, DICOM_BOOL, BOOL)
00365 **   with one unique boolean type OFBool.
00366 **
00367 ** Revision 1.9  1997/05/22 13:15:54  hewett
00368 ** Added method DcmDataDictionary::isDictionaryLoaded() to ask if a full
00369 ** data dictionary has been loaded.  This method should be used in tests
00370 ** rather that querying the number of entries (a sekelton dictionary is
00371 ** now always present).
00372 **
00373 ** Revision 1.8  1997/05/13 13:58:41  hewett
00374 ** Added member function (loadSkeletomDictionary) to preload of a few
00375 ** essential attribute descriptions into the data dictionary (e.g. Item
00376 ** and ItemDelimitation tags).
00377 **
00378 ** Revision 1.7  1996/09/18 16:37:10  hewett
00379 ** Added capability to search data dictionary by tag name.
00380 **
00381 ** Revision 1.6  1996/03/22 13:09:12  hewett
00382 ** Moved the definition of DCM_DICT_DEFAULT_PATH to the system
00383 ** dependent configuration files included via "osconfig.h".
00384 **
00385 ** Revision 1.5  1996/03/21 09:50:38  hewett
00386 ** Added a  method numberOfEntries() to return the total number of
00387 ** dictionary entries.
00388 **
00389 ** Revision 1.4  1996/03/20 16:43:49  hewett
00390 ** Updated for revised data dictionary.  Repeating tags are now handled better.
00391 ** A linear list of repeating tags has been introduced with a subset ordering
00392 ** mechanism to ensure that dictionary searches locate the most precise
00393 ** dictionary entry.
00394 **
00395 */


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