1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2005/01/07 19:20:38 $
7 Version: $Revision: 1.48 $
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
31 * \brief The Dictionnary Set obtained with this constructor simply
32 * contains the Default Public dictionnary.
36 DictPath = BuildDictPath();
37 std::string pubDictFile(DictPath);
38 pubDictFile += PUB_DICT_FILENAME;
39 Dicts[PUB_DICT_NAME] = new Dict(pubDictFile);
48 // Remove dictionnaries
49 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
51 Dict *entryToDelete = tag->second;
60 // Remove virtual dictionnary entries
64 //-----------------------------------------------------------------------------
68 * \brief Print, in an informal fashion, the list of all the dictionaries
69 * contained is this DictSet, along with their respective content.
70 * @param os Output stream used for printing.
72 void DictSet::Print(std::ostream &os)
74 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
76 os << "Printing dictionary " << dict->first << std::endl;
77 dict->second->Print(os);
81 //-----------------------------------------------------------------------------
85 * \brief Consider all the entries of the public dicom dictionnary.
86 * Build all list of all the tag names of all those entries.
87 * \sa DictSet::GetPubDictTagNamesByCategory
88 * @return A list of all entries of the public dicom dictionnary.
93 //EntryNamesList *DictSet::GetPubDictEntryNames()
95 // return GetDefaultPubDict()->GetDictEntryNames();
101 * - Consider all the entries of the public dicom dictionnary.
102 * - Build an hashtable whose keys are the names of the groups
103 * (fourth field in each line of dictionary) and whose corresponding
104 * values are lists of all the dictionnary entries among that
105 * group. Note that apparently the Dicom standard doesn't explicitely
106 * define a name (as a string) for each group.
107 * NO ! Dicom Standard explicitely doesn't define
108 * any name, for any group !
109 * - A typical usage of this method would be to enable a dynamic
110 * configuration of a Dicom file browser: the admin/user can
111 * select in the interface which Dicom tags should be displayed.
113 * - Dicom *doesn't* define any name for any 'categorie'
114 * (the dictionnary fourth field was formerly NIH defined
115 * -and no longer he is-
116 * and will be removed when Dicom provides us a text file
117 * with the 'official' Dictionnary, that would be more friendly
118 * than asking us to perform a line by line check of the dictionnary
119 * at the beginning of each year to -try to- guess the changes)
120 * - Therefore : please NEVER use that fourth field :-(
122 * @return An hashtable: whose keys are the names of the groups and whose
123 * corresponding values are lists of all the dictionnary entries
128 // Probabely useless!
130 //EntryNamesByCatMap *DictSet::GetPubDictEntryNamesByCategory()
132 // return GetDefaultPubDict()->GetDictEntryNamesByCategory();
137 * \brief Loads a dictionary from a specified file, and add it
138 * to already the existing ones contained in this DictSet.
139 * @param filename Absolute or relative filename containing the
140 * dictionary to load.
141 * @param name Symbolic name that be used as identifier of the newly
142 * created dictionary.
144 Dict *DictSet::LoadDictFromFile(std::string const & filename,
145 DictKey const & name)
147 Dict *newDict = new Dict(filename);
148 AppendDict(newDict, name);
155 * \brief Retrieve the specified dictionary (when existing) from this
157 * @param dictName The symbolic name of the searched dictionary.
158 * \result The retrieved dictionary.
160 Dict *DictSet::GetDict(DictKey const &dictName)
162 DictSetHT::iterator dict = Dicts.find(dictName);
163 if(dict != Dicts.end())
171 * \brief Create a DictEntry which will be reference
173 * @return virtual entry
175 DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
182 const std::string tag = DictEntry::TranslateToKey(group,element)
183 + "#" + vr + "#" + vm + "#" + name;
184 TagKeyHT::iterator it;
186 it = VirtualEntry.find(tag);
187 if(it != VirtualEntry.end())
189 entry = &(it->second);
193 DictEntry ent(group, element, vr, vm, name);
195 std::map<TagKey, DictEntry>::value_type
197 entry = &(VirtualEntry.find(tag)->second);
204 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
205 * path to directory containing the dictionnaries. When
206 * the environnement variable is absent the path is defaulted
208 * @return path to directory containing the dictionnaries
210 std::string DictSet::BuildDictPath()
212 std::string resultPath;
213 const char *envPath = 0;
214 envPath = getenv("GDCM_DICT_PATH");
216 if (envPath && (strlen(envPath) != 0))
218 resultPath = envPath;
219 if ( resultPath[resultPath.length()-1] != '/' )
223 gdcmVerboseMacro("DictSet::BuildDictPath:"
224 "Dictionary path set from environnement");
228 resultPath = PUB_DICT_PATH;
234 //-----------------------------------------------------------------------------
236 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
238 Dicts[name] = newDict;
243 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
248 } // end namespace gdcm