1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2006/03/22 13:19:25 $
7 Version: $Revision: 1.74 $
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
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 // Remove dictionaries
51 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
54 tag->second->Delete();
59 //-----------------------------------------------------------------------------
62 * \brief Loads a dictionary from a specified file, and add it
63 * to already the existing ones contained in this DictSet.
64 * @param filename Absolute or relative filename containing the
66 * @param name Symbolic name that be used as identifier of the newly
69 Dict *DictSet::LoadDictFromFile(std::string const &filename,
72 Dict *newDict = Dict::New(filename);
73 Dicts[name] = newDict;
79 * \brief Retrieve the specified dictionary (when existing) from this
81 * @param dictName The symbolic name of the searched dictionary.
82 * \result The retrieved dictionary.
84 Dict *DictSet::GetDict(DictKey const &dictName)
86 DictSetHT::iterator dict = Dicts.find(dictName);
87 if ( dict != Dicts.end() )
95 * \brief Get the first dictionary while visiting the DictSet
96 * \return The first Dict if found, otherwhise NULL
98 Dict *DictSet::GetFirstDict()
100 ItDictHt = Dicts.begin();
101 if ( ItDictHt != Dicts.end() )
102 return ItDictHt->second;
107 * \brief Get the next dictionary while visiting the Hash table (DictSetHT)
108 * \note : meaningfull only if GetFirstEntry already called
109 * \return The next Dict if found, otherwhise NULL
111 Dict *DictSet::GetNextDict()
113 gdcmAssertMacro (ItDictHt != Dicts.end());
116 if ( ItDictHt != Dicts.end() )
117 return ItDictHt->second;
122 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
123 * path to directory containing the dictionaries. When
124 * the environnement variable is absent the path is defaulted
126 * @return path to directory containing the dictionaries
128 std::string DictSet::BuildDictPath()
130 std::string resultPath;
132 envPath = getenv("GDCM_DICT_PATH");
134 if (envPath && (strlen(envPath) != 0))
136 resultPath = envPath;
137 gdcmStaticWarningMacro( "Dictionary path set from environnement");
141 resultPath = PUB_DICT_PATH;
143 if ( resultPath[resultPath.length()-1] != '/' )
151 //-----------------------------------------------------------------------------
154 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
160 * \brief Print, in an informal fashion, the list of all the dictionaries
161 * contained is this DictSet, along with their respective content.
162 * @param os Output stream used for printing.
163 * @param indent Indentation string to be prepended during printing
165 void DictSet::Print(std::ostream &os, std::string const & )
167 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
169 os << "Printing dictionary " << dict->first << std::endl;
170 dict->second->Print(os);
174 //-----------------------------------------------------------------------------
175 } // end namespace gdcm