1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2005/02/05 01:37:08 $
7 Version: $Revision: 1.60 $
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 Loads a dictionary from a specified file, and add it
66 * to already the existing ones contained in this DictSet.
67 * @param filename Absolute or relative filename containing the
69 * @param name Symbolic name that be used as identifier of the newly
72 Dict *DictSet::LoadDictFromFile(std::string const &filename,
75 Dict *newDict = new Dict(filename);
76 AppendDict(newDict, name);
82 * \brief Retrieve the specified dictionary (when existing) from this
84 * @param dictName The symbolic name of the searched dictionary.
85 * \result The retrieved dictionary.
87 Dict *DictSet::GetDict(DictKey const &dictName)
89 DictSetHT::iterator dict = Dicts.find(dictName);
90 if(dict != Dicts.end())
98 * \brief Create a DictEntry which will be referenced
100 * @return virtual entry
102 DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
109 const std::string tag = DictEntry::TranslateToKey(group,element)
110 + "#" + vr + "#" + vm + "#" + name;
111 TagKeyHT::iterator it;
113 it = VirtualEntry.find(tag);
114 if(it != VirtualEntry.end())
116 entry = &(it->second);
120 DictEntry ent(group, element, vr, vm, name);
122 std::map<TagKey, DictEntry>::value_type
124 entry = &(VirtualEntry.find(tag)->second);
131 * \brief Get the first entry while visiting the DictSet
132 * \return The first Dict if found, otherwhise NULL
134 Dict *DictSet::GetFirstEntry()
136 ItDictHt = Dicts.begin();
137 if( ItDictHt != Dicts.end() )
138 return ItDictHt->second;
143 * \brief Get the next entry while visiting the Hash table (DictSetHT)
144 * \note : meaningfull only if GetFirstEntry already called
145 * \return The next Dict if found, otherwhise NULL
147 Dict *DictSet::GetNextEntry()
149 gdcmAssertMacro (ItDictHt != Dicts.end());
152 if ( ItDictHt != Dicts.end() )
153 return ItDictHt->second;
158 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
159 * path to directory containing the dictionaries. When
160 * the environnement variable is absent the path is defaulted
162 * @return path to directory containing the dictionaries
164 std::string DictSet::BuildDictPath()
166 std::string resultPath;
167 const char *envPath = 0;
168 envPath = getenv("GDCM_DICT_PATH");
170 if (envPath && (strlen(envPath) != 0))
172 resultPath = envPath;
173 if ( resultPath[resultPath.length()-1] != '/' )
177 gdcmWarningMacro( "Dictionary path set from environnement");
181 resultPath = PUB_DICT_PATH;
187 //-----------------------------------------------------------------------------
190 * \brief Adds a Dictionary to a DictSet
191 * \return always true
193 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
195 Dicts[name] = newDict;
200 //-----------------------------------------------------------------------------
203 //-----------------------------------------------------------------------------
206 * \brief Print, in an informal fashion, the list of all the dictionaries
207 * contained is this DictSet, along with their respective content.
208 * @param os Output stream used for printing.
209 * @param indent Indentation string to be prepended during printing
211 void DictSet::Print(std::ostream &os, std::string const & )
213 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
215 os << "Printing dictionary " << dict->first << std::endl;
216 dict->second->Print(os);
220 //-----------------------------------------------------------------------------
221 } // end namespace gdcm