1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2004/06/20 18:08:47 $
7 Version: $Revision: 1.31 $
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.htm 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
24 //-----------------------------------------------------------------------------
25 // Constructor / Destructor
27 * \ingroup gdcmDictSet
28 * \brief The Dictionnary Set obtained with this constructor simply
29 * contains the Default Public dictionnary.
31 gdcmDictSet::gdcmDictSet(void)
33 DictPath = BuildDictPath();
34 std::string PubDictFile(DictPath);
35 PubDictFile += PUB_DICT_FILENAME; /// MEMORY LEAK std::string::operator+=
36 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
40 * \ingroup gdcmDictSet
43 gdcmDictSet::~gdcmDictSet()
45 // Remove dictionnaries
46 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
48 gdcmDict *EntryToDelete = tag->second;
55 // Remove virtual dictionnary entries
56 std::map<std::string,gdcmDictEntry *>::iterator it;
57 for(it=virtualEntry.begin(); it!=virtualEntry.end(); ++it)
59 gdcmDictEntry *Entry = it->second;
66 //-----------------------------------------------------------------------------
69 * \ingroup gdcmDictSet
70 * \brief Print, in an informal fashion, the list of all the dictionaries
71 * contained is this gdcmDictSet, along with their respective content.
72 * @param os Output stream used for printing.
74 void gdcmDictSet::Print(std::ostream& os)
76 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
78 os << "Printing dictionary " << dict->first << std::endl;
79 dict->second->Print(os);
83 //-----------------------------------------------------------------------------
86 * \ingroup gdcmDictSet
87 * \brief Consider all the entries of the public dicom dictionnary.
88 * Build all list of all the tag names of all those entries.
89 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
90 * @return A list of all entries of the public dicom dictionnary.
92 std::list<std::string> *gdcmDictSet::GetPubDictEntryNames(void)
94 return(GetDefaultPubDict()->GetDictEntryNames());
98 * \ingroup gdcmDictSet
100 * - Consider all the entries of the public dicom dictionnary.
101 * - Build an hashtable whose keys are the names of the groups
102 * (fourth field in each line of dictionary) and whose corresponding
103 * values are lists of all the dictionnary entries among that
104 * group. Note that apparently the Dicom standard doesn't explicitely
105 * define a name (as a string) for each group.
106 * - A typical usage of this method would be to enable a dynamic
107 * configuration of a Dicom file browser: the admin/user can
108 * select in the interface which Dicom tags should be displayed.
110 * - Dicom *doesn't* define any name for any 'categorie'
111 * (the dictionnary fourth field was formerly NIH defined
112 * -and no longer he is-
113 * and will be removed when Dicom provides us a text file
114 * with the 'official' Dictionnary, that would be more friendly
115 * than asking us to perform a line by line check of the dictionnary
116 * at the beginning of each year to -try to- guess the changes)
117 * - Therefore : please NEVER use that fourth field :-(
119 * @return An hashtable: whose keys are the names of the groups and whose
120 * corresponding values are lists of all the dictionnary entries
123 std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictEntryNamesByCategory(void)
125 return(GetDefaultPubDict()->GetDictEntryNamesByCategory());
129 * \ingroup gdcmDictSet
130 * \brief Loads a dictionary from a specified file, and add it
131 * to already the existing ones contained in this gdcmDictSet.
132 * @param FileName Absolute or relative filename containing the
133 * dictionary to load.
134 * @param Name Symbolic name that be used as identifier of the newly
135 * created dictionary.
137 gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name)
139 gdcmDict *NewDict = new gdcmDict(FileName);
140 AppendDict(NewDict,Name);
145 * \ingroup gdcmDictSet
146 * \brief Retrieve the specified dictionary (when existing) from this
148 * @param DictName The symbolic name of the searched dictionary.
149 * \result The retrieved dictionary.
151 gdcmDict *gdcmDictSet::GetDict(DictKey DictName)
153 DictSetHT::iterator dict = Dicts.find(DictName);
154 if(dict!=Dicts.end())
160 * \ingroup gdcmDictSet
161 * \brief Retrieve the default reference DICOM V3 public dictionary.
162 * \result The retrieved default dictionary.
164 gdcmDict *gdcmDictSet::GetDefaultPubDict()
166 return GetDict(PUB_DICT_NAME);
170 * \ingroup gdcmDictSet
171 * \brief Create a gdcmDictEntry which will be reference
173 * @return virtual entry
175 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
176 std::string vr,std::string fourth,
179 gdcmDictEntry *entry;
180 std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name;
181 std::map<std::string,gdcmDictEntry *>::iterator it;
183 it=virtualEntry.find(tag);
184 if(it!=virtualEntry.end())
190 entry=new gdcmDictEntry(group,element,vr,fourth,name);
191 virtualEntry[tag]=entry;
197 * \ingroup gdcmDictSet
198 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
199 * path to directory containing the dictionnaries. When
200 * the environnement variable is absent the path is defaulted
202 * @return path to directory containing the dictionnaries
204 std::string gdcmDictSet::BuildDictPath(void)
206 std::string ResultPath;
207 const char *EnvPath = (char*)0;
208 EnvPath = getenv("GDCM_DICT_PATH");
209 if (EnvPath && (strlen(EnvPath) != 0))
211 ResultPath = EnvPath;
212 if (ResultPath[ResultPath.length() -1] != '/' )
214 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
215 "Dictionary path set from environnement");
218 ResultPath = PUB_DICT_PATH;
222 //-----------------------------------------------------------------------------
224 bool gdcmDictSet::AppendDict(gdcmDict *NewDict,DictKey Name)
226 Dicts[Name] = NewDict;
230 //-----------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------