1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2005/10/20 15:24:08 $
7 Version: $Revision: 1.71 $
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
23 #include <stdio.h> // For sprintf
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
31 * \brief The Dictionary Set obtained with this constructor simply
32 * contains the Default Public dictionary.
36 DictPath = BuildDictPath();
37 std::string pubDictFile(DictPath);
38 pubDictFile += PUB_DICT_FILENAME;
39 Dicts[PUB_DICT_NAME] = new Dict(pubDictFile);
47 // Remove dictionaries
48 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
50 Dict *entryToDelete = tag->second;
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 Dict *newDict = new Dict(filename);
74 AppendDict(newDict, name);
80 * \brief Retrieve the specified dictionary (when existing) from this
82 * @param dictName The symbolic name of the searched dictionary.
83 * \result The retrieved dictionary.
85 Dict *DictSet::GetDict(DictKey const &dictName)
87 DictSetHT::iterator dict = Dicts.find(dictName);
88 if ( dict != Dicts.end() )
96 * \brief Get the first dictionary while visiting the DictSet
97 * \return The first Dict if found, otherwhise NULL
99 Dict *DictSet::GetFirstDict()
101 ItDictHt = Dicts.begin();
102 if ( ItDictHt != Dicts.end() )
103 return ItDictHt->second;
108 * \brief Get the next dictionary while visiting the Hash table (DictSetHT)
109 * \note : meaningfull only if GetFirstEntry already called
110 * \return The next Dict if found, otherwhise NULL
112 Dict *DictSet::GetNextDict()
114 gdcmAssertMacro (ItDictHt != Dicts.end());
117 if ( ItDictHt != Dicts.end() )
118 return ItDictHt->second;
123 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
124 * path to directory containing the dictionaries. When
125 * the environnement variable is absent the path is defaulted
127 * @return path to directory containing the dictionaries
129 std::string DictSet::BuildDictPath()
131 std::string resultPath;
133 envPath = getenv("GDCM_DICT_PATH");
135 if (envPath && (strlen(envPath) != 0))
137 resultPath = envPath;
138 gdcmWarningMacro( "Dictionary path set from environnement");
142 resultPath = PUB_DICT_PATH;
144 if ( resultPath[resultPath.length()-1] != '/' )
152 //-----------------------------------------------------------------------------
155 * \brief Adds a Dictionary to a DictSet
156 * \return always true
158 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
160 Dicts[name] = newDict;
165 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
171 * \brief Print, in an informal fashion, the list of all the dictionaries
172 * contained is this DictSet, along with their respective content.
173 * @param os Output stream used for printing.
174 * @param indent Indentation string to be prepended during printing
176 void DictSet::Print(std::ostream &os, std::string const & )
178 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
180 os << "Printing dictionary " << dict->first << std::endl;
181 dict->second->Print(os);
185 //-----------------------------------------------------------------------------
186 } // end namespace gdcm