1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2007/05/23 14:18:09 $
7 Version: $Revision: 1.78 $
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"
21 #include "gdcmGlobal.h"
23 #include <stdlib.h> // For getenv
24 #include <stdio.h> // For sprintf
26 namespace GDCM_NAME_SPACE
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
32 * \brief The Dictionary Set obtained with this constructor simply
33 * contains the Default Public dictionary.
37 DictPath = BuildDictPath();
38 std::string pubDictFile(DictPath);
39 pubDictFile += PUB_DICT_FILENAME;
40 Dicts[PUB_DICT_NAME] = Dict::New(pubDictFile);
41 // Stored redundantly to avoid at access HTable DictSet every time.
42 Global::DefaultPubDict = Dicts[PUB_DICT_NAME];
50 Global::DefaultPubDict = 0; // just a pointer!
51 // Remove dictionaries
52 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
55 tag->second->Delete();
60 //-----------------------------------------------------------------------------
63 * \brief Loads a dictionary from a specified file, and add it
64 * to already the existing ones contained in this DictSet.
65 * @param filename Absolute or relative filename containing the
67 * @param name Symbolic name that be used as identifier of the newly
70 Dict *DictSet::LoadDictFromFile(std::string const &filename,
73 assert(Dicts.find(name)==Dicts.end());
74 ///\todo RemoveDict(name); when Dict already exist
75 Dict *newDict = Dict::New(filename);
76 Dicts[name] = newDict;
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 Get the first dictionary while visiting the DictSet
99 * \return The first Dict if found, otherwhise NULL
101 Dict *DictSet::GetFirstDict()
103 ItDictHt = Dicts.begin();
104 if ( ItDictHt != Dicts.end() )
105 return ItDictHt->second;
110 * \brief Get the next dictionary while visiting the Hash table (DictSetHT)
111 * \note : meaningfull only if GetFirstEntry already called
112 * \return The next Dict if found, otherwhise NULL
114 Dict *DictSet::GetNextDict()
116 gdcmAssertMacro (ItDictHt != Dicts.end());
119 if ( ItDictHt != Dicts.end() )
120 return ItDictHt->second;
125 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
126 * path to directory containing the dictionaries. When
127 * the environnement variable is absent the path is defaulted
129 * @return path to directory containing the dictionaries
131 std::string DictSet::BuildDictPath()
133 std::string resultPath;
134 const char *envPath = getenv("GDCM_DICT_PATH");
136 if (envPath && (strlen(envPath) != 0))
138 resultPath = envPath;
139 gdcmStaticWarningMacro( "Dictionary path set from environnement");
143 resultPath = PUB_DICT_PATH;
145 if ( resultPath.length() && resultPath[resultPath.length()-1] != '/' )
152 //-----------------------------------------------------------------------------
155 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
161 * \brief Print, in an informal fashion, the list of all the dictionaries
162 * contained is this DictSet, along with their respective content.
163 * @param os Output stream used for printing.
164 * @param indent Indentation string to be prepended during printing
166 void DictSet::Print(std::ostream &os, std::string const & )
168 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
170 os << "Printing dictionary " << dict->first << std::endl;
171 dict->second->Print(os);
175 //-----------------------------------------------------------------------------
176 } // end namespace gdcm