1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2005/01/18 07:50:58 $
7 Version: $Revision: 1.52 $
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 dictionnaries
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.
69 void DictSet::Print(std::ostream &os, std::string const & )
71 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
73 os << "Printing dictionary " << dict->first << std::endl;
74 dict->second->Print(os);
78 //-----------------------------------------------------------------------------
81 * \brief Consider all the entries of the public dicom dictionary.
82 * Build all list of all the tag names of all those entries.
83 * \sa DictSet::GetPubDictTagNamesByCategory
84 * @return A list of all entries of the public dicom dictionary.
89 //EntryNamesList *DictSet::GetPubDictEntryNames()
91 // return GetDefaultPubDict()->GetDictEntryNames();
96 * - Consider all the entries of the public dicom dictionary.
97 * - Build an hashtable whose keys are the names of the groups
98 * (fourth field in each line of dictionary) and whose corresponding
99 * values are lists of all the dictionary entries among that
100 * group. Note that apparently the Dicom standard doesn't explicitely
101 * define a name (as a string) for each group.
102 * NO ! Dicom Standard explicitely doesn't define
103 * any name, for any group !
104 * - A typical usage of this method would be to enable a dynamic
105 * configuration of a Dicom file browser: the admin/user can
106 * select in the interface which Dicom tags should be displayed.
108 * - Dicom *doesn't* define any name for any 'categorie'
109 * (the dictionary fourth field was formerly NIH defined
110 * -and no longer he is-
111 * and will be removed when Dicom provides us a text file
112 * with the 'official' Dictionary, that would be more friendly
113 * than asking us to perform a line by line check of the dictionary
114 * at the beginning of each year to -try to- guess the changes)
115 * - Therefore : please NEVER use that fourth field :-(
117 * @return An hashtable: whose keys are the names of the groups and whose
118 * corresponding values are lists of all the dictionary entries
123 // Probabely useless!
125 //EntryNamesByCatMap *DictSet::GetPubDictEntryNamesByCategory()
127 // return GetDefaultPubDict()->GetDictEntryNamesByCategory();
131 * \brief Loads a dictionary from a specified file, and add it
132 * to already the existing ones contained in this DictSet.
133 * @param filename Absolute or relative filename containing the
134 * dictionary to load.
135 * @param name Symbolic name that be used as identifier of the newly
136 * created dictionary.
138 Dict *DictSet::LoadDictFromFile(std::string const & filename,
139 DictKey const & name)
141 Dict *newDict = new Dict(filename);
142 AppendDict(newDict, name);
148 * \brief Retrieve the specified dictionary (when existing) from this
150 * @param dictName The symbolic name of the searched dictionary.
151 * \result The retrieved dictionary.
153 Dict *DictSet::GetDict(DictKey const &dictName)
155 DictSetHT::iterator dict = Dicts.find(dictName);
156 if(dict != Dicts.end())
164 * \brief Create a DictEntry which will be referenced
166 * @return virtual entry
168 DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
175 const std::string tag = DictEntry::TranslateToKey(group,element)
176 + "#" + vr + "#" + vm + "#" + name;
177 TagKeyHT::iterator it;
179 it = VirtualEntry.find(tag);
180 if(it != VirtualEntry.end())
182 entry = &(it->second);
186 DictEntry ent(group, element, vr, vm, name);
188 std::map<TagKey, DictEntry>::value_type
190 entry = &(VirtualEntry.find(tag)->second);
197 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
198 * path to directory containing the dictionnaries. When
199 * the environnement variable is absent the path is defaulted
201 * @return path to directory containing the dictionnaries
203 std::string DictSet::BuildDictPath()
205 std::string resultPath;
206 const char *envPath = 0;
207 envPath = getenv("GDCM_DICT_PATH");
209 if (envPath && (strlen(envPath) != 0))
211 resultPath = envPath;
212 if ( resultPath[resultPath.length()-1] != '/' )
216 gdcmVerboseMacro( "Dictionary path set from environnement");
220 resultPath = PUB_DICT_PATH;
228 * \brief Get the first entry while visiting the DictSet
229 * \return The first Dict if found, otherwhise NULL
231 Dict *DictSet::GetFirstEntry()
233 ItDictHt = Dicts.begin();
234 return ItDictHt->second;
238 * \brief Get the next entry while visiting the Hash table (DictSetHT)
239 * \note : meaningfull only if GetFirstEntry already called
240 * \return The next Dict if found, otherwhise NULL
242 Dict *DictSet::GetNextEntry()
244 if (ItDictHt != Dicts.end())
246 Dict *tmp = ItDictHt->second;
257 //-----------------------------------------------------------------------------
261 * \brief Adds a Dictionary to a DictSet
262 * \return always true
264 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
266 Dicts[name] = newDict;
271 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
276 } // end namespace gdcm