1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2005/11/28 15:20:33 $
7 Version: $Revision: 1.73 $
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] = Dict::New(pubDictFile);
47 // Remove dictionaries
48 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
51 tag->second->Delete();
56 //-----------------------------------------------------------------------------
59 * \brief Loads a dictionary from a specified file, and add it
60 * to already the existing ones contained in this DictSet.
61 * @param filename Absolute or relative filename containing the
63 * @param name Symbolic name that be used as identifier of the newly
66 Dict *DictSet::LoadDictFromFile(std::string const &filename,
69 Dict *newDict = Dict::New(filename);
70 Dicts[name] = newDict;
76 * \brief Retrieve the specified dictionary (when existing) from this
78 * @param dictName The symbolic name of the searched dictionary.
79 * \result The retrieved dictionary.
81 Dict *DictSet::GetDict(DictKey const &dictName)
83 DictSetHT::iterator dict = Dicts.find(dictName);
84 if ( dict != Dicts.end() )
92 * \brief Get the first dictionary while visiting the DictSet
93 * \return The first Dict if found, otherwhise NULL
95 Dict *DictSet::GetFirstDict()
97 ItDictHt = Dicts.begin();
98 if ( ItDictHt != Dicts.end() )
99 return ItDictHt->second;
104 * \brief Get the next dictionary while visiting the Hash table (DictSetHT)
105 * \note : meaningfull only if GetFirstEntry already called
106 * \return The next Dict if found, otherwhise NULL
108 Dict *DictSet::GetNextDict()
110 gdcmAssertMacro (ItDictHt != Dicts.end());
113 if ( ItDictHt != Dicts.end() )
114 return ItDictHt->second;
119 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
120 * path to directory containing the dictionaries. When
121 * the environnement variable is absent the path is defaulted
123 * @return path to directory containing the dictionaries
125 std::string DictSet::BuildDictPath()
127 std::string resultPath;
129 envPath = getenv("GDCM_DICT_PATH");
131 if (envPath && (strlen(envPath) != 0))
133 resultPath = envPath;
134 gdcmStaticWarningMacro( "Dictionary path set from environnement");
138 resultPath = PUB_DICT_PATH;
140 if ( resultPath[resultPath.length()-1] != '/' )
148 //-----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
154 //-----------------------------------------------------------------------------
157 * \brief Print, in an informal fashion, the list of all the dictionaries
158 * contained is this DictSet, along with their respective content.
159 * @param os Output stream used for printing.
160 * @param indent Indentation string to be prepended during printing
162 void DictSet::Print(std::ostream &os, std::string const & )
164 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
166 os << "Printing dictionary " << dict->first << std::endl;
167 dict->second->Print(os);
171 //-----------------------------------------------------------------------------
172 } // end namespace gdcm