1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2005/01/23 10:12:33 $
7 Version: $Revision: 1.56 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDictSet.h"
20 #include "gdcmDebug.h"
22 #include <stdlib.h> // For getenv
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
30 * \brief The Dictionary Set obtained with this constructor simply
31 * contains the Default Public dictionary.
35 DictPath = BuildDictPath();
36 std::string pubDictFile(DictPath);
37 pubDictFile += PUB_DICT_FILENAME;
38 Dicts[PUB_DICT_NAME] = new Dict(pubDictFile);
46 // Remove dictionaries
47 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
49 Dict *entryToDelete = tag->second;
58 // Remove virtual dictionary entries
62 //-----------------------------------------------------------------------------
65 * \brief Print, in an informal fashion, the list of all the dictionaries
66 * contained is this DictSet, along with their respective content.
67 * @param os Output stream used for printing.
68 * @param indent Indentation string to be prepended during printing
70 void DictSet::Print(std::ostream &os, std::string const & )
72 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
74 os << "Printing dictionary " << dict->first << std::endl;
75 dict->second->Print(os);
79 //-----------------------------------------------------------------------------
82 * \brief Consider all the entries of the public dicom dictionary.
83 * Build all list of all the tag names of all those entries.
84 * \sa DictSet::GetPubDictTagNamesByCategory
85 * @return A list of all entries of the public dicom dictionary.
90 //EntryNamesList *DictSet::GetPubDictEntryNames()
92 // return GetDefaultPubDict()->GetDictEntryNames();
97 * - Consider all the entries of the public dicom dictionary.
98 * - Build an hashtable whose keys are the names of the groups
99 * (fourth field in each line of dictionary) and whose corresponding
100 * values are lists of all the dictionary entries among that
101 * group. Note that apparently the Dicom standard doesn't explicitely
102 * define a name (as a string) for each group.
103 * NO ! Dicom Standard explicitely doesn't define
104 * any name, for any group !
105 * - A typical usage of this method would be to enable a dynamic
106 * configuration of a Dicom file browser: the admin/user can
107 * select in the interface which Dicom tags should be displayed.
109 * - Dicom *doesn't* define any name for any 'categorie'
110 * (the dictionary fourth field was formerly NIH defined
111 * -and no longer he is-
112 * and will be removed when Dicom provides us a text file
113 * with the 'official' Dictionary, that would be more friendly
114 * than asking us to perform a line by line check of the dictionary
115 * at the beginning of each year to -try to- guess the changes)
116 * - Therefore : please NEVER use that fourth field :-(
118 * @return An hashtable: whose keys are the names of the groups and whose
119 * corresponding values are lists of all the dictionary entries
124 // Probabely useless!
126 //EntryNamesByCatMap *DictSet::GetPubDictEntryNamesByCategory()
128 // return GetDefaultPubDict()->GetDictEntryNamesByCategory();
132 * \brief Loads a dictionary from a specified file, and add it
133 * to already the existing ones contained in this DictSet.
134 * @param filename Absolute or relative filename containing the
135 * dictionary to load.
136 * @param name Symbolic name that be used as identifier of the newly
137 * created dictionary.
139 Dict *DictSet::LoadDictFromFile(std::string const & filename,
140 DictKey const & name)
142 Dict *newDict = new Dict(filename);
143 AppendDict(newDict, name);
149 * \brief Retrieve the specified dictionary (when existing) from this
151 * @param dictName The symbolic name of the searched dictionary.
152 * \result The retrieved dictionary.
154 Dict *DictSet::GetDict(DictKey const &dictName)
156 DictSetHT::iterator dict = Dicts.find(dictName);
157 if(dict != Dicts.end())
165 * \brief Create a DictEntry which will be referenced
167 * @return virtual entry
169 DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
176 const std::string tag = DictEntry::TranslateToKey(group,element)
177 + "#" + vr + "#" + vm + "#" + name;
178 TagKeyHT::iterator it;
180 it = VirtualEntry.find(tag);
181 if(it != VirtualEntry.end())
183 entry = &(it->second);
187 DictEntry ent(group, element, vr, vm, name);
189 std::map<TagKey, DictEntry>::value_type
191 entry = &(VirtualEntry.find(tag)->second);
198 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
199 * path to directory containing the dictionaries. When
200 * the environnement variable is absent the path is defaulted
202 * @return path to directory containing the dictionaries
204 std::string DictSet::BuildDictPath()
206 std::string resultPath;
207 const char *envPath = 0;
208 envPath = getenv("GDCM_DICT_PATH");
210 if (envPath && (strlen(envPath) != 0))
212 resultPath = envPath;
213 if ( resultPath[resultPath.length()-1] != '/' )
217 gdcmVerboseMacro( "Dictionary path set from environnement");
221 resultPath = PUB_DICT_PATH;
229 * \brief Get the first entry while visiting the DictSet
230 * \return The first Dict if found, otherwhise NULL
232 Dict *DictSet::GetFirstEntry()
234 ItDictHt = Dicts.begin();
235 if( ItDictHt != Dicts.end() )
236 return ItDictHt->second;
241 * \brief Get the next entry while visiting the Hash table (DictSetHT)
242 * \note : meaningfull only if GetFirstEntry already called
243 * \return The next Dict if found, otherwhise NULL
245 Dict *DictSet::GetNextEntry()
247 gdcmAssertMacro (ItDictHt != Dicts.end());
250 if ( ItDictHt != Dicts.end() )
251 return ItDictHt->second;
255 //-----------------------------------------------------------------------------
259 * \brief Adds a Dictionary to a DictSet
260 * \return always true
262 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
264 Dicts[name] = newDict;
269 //-----------------------------------------------------------------------------
272 //-----------------------------------------------------------------------------
274 } // end namespace gdcm