2 //-----------------------------------------------------------------------------
3 #include "gdcmDictSet.h"
6 #include <stdlib.h> // For getenv
8 //-----------------------------------------------------------------------------
9 // Constructor / Destructor
11 * \ingroup gdcmDictSet
12 * \brief The Dictionnary Set obtained with this constructor simply
13 * contains the Default Public dictionnary.
15 gdcmDictSet::gdcmDictSet(void)
17 DictPath = BuildDictPath();
18 std::string PubDictFile(DictPath);
19 PubDictFile += PUB_DICT_FILENAME; /// MEMORY LEAK std::string::operator+=
20 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
24 * \ingroup gdcmDictSet
27 gdcmDictSet::~gdcmDictSet()
29 // Remove dictionnaries
30 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
32 gdcmDict *EntryToDelete = tag->second;
39 // Remove virtual dictionnary entries
40 std::map<std::string,gdcmDictEntry *>::iterator it;
41 for(it=virtualEntry.begin(); it!=virtualEntry.end(); ++it)
43 gdcmDictEntry *Entry = it->second;
50 //-----------------------------------------------------------------------------
53 * \ingroup gdcmDictSet
54 * \brief Print, in an informal fashion, the list of all the dictionaries
55 * contained is this gdcmDictSet, along with their respective content.
56 * @param os Output stream used for printing.
58 void gdcmDictSet::Print(std::ostream& os)
60 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
62 os << "Printing dictionary " << dict->first << std::endl;
63 dict->second->Print(os);
67 //-----------------------------------------------------------------------------
70 * \ingroup gdcmDictSet
71 * \brief Consider all the entries of the public dicom dictionnary.
72 * Build all list of all the tag names of all those entries.
73 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
74 * @return A list of all entries of the public dicom dictionnary.
76 std::list<std::string> *gdcmDictSet::GetPubDictEntryNames(void)
78 return(GetDefaultPubDict()->GetDictEntryNames());
82 * \ingroup gdcmDictSet
84 * - Consider all the entries of the public dicom dictionnary.
85 * - Build an hashtable whose keys are the names of the groups
86 * (fourth field in each line of dictionary) and whose corresponding
87 * values are lists of all the dictionnary entries among that
88 * group. Note that apparently the Dicom standard doesn't explicitely
89 * define a name (as a string) for each group.
90 * - A typical usage of this method would be to enable a dynamic
91 * configuration of a Dicom file browser: the admin/user can
92 * select in the interface which Dicom tags should be displayed.
94 * - Dicom *doesn't* define any name for any 'categorie'
95 * (the dictionnary fourth field was formerly NIH defined
96 * -and no longer he is-
97 * and will be removed when Dicom provides us a text file
98 * with the 'official' Dictionnary, that would be more friendly
99 * than asking us to perform a line by line check of the dictionnary
100 * at the beginning of each year to -try to- guess the changes)
101 * - Therefore : please NEVER use that fourth field :-(
103 * @return An hashtable: whose keys are the names of the groups and whose
104 * corresponding values are lists of all the dictionnary entries
107 std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictEntryNamesByCategory(void)
109 return(GetDefaultPubDict()->GetDictEntryNamesByCategory());
113 * \ingroup gdcmDictSet
114 * \brief Loads a dictionary from a specified file, and add it
115 * to already the existing ones contained in this gdcmDictSet.
116 * @param FileName Absolute or relative filename containing the
117 * dictionary to load.
118 * @param Name Symbolic name that be used as identifier of the newly
119 * created dictionary.
121 gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name)
123 gdcmDict *NewDict = new gdcmDict(FileName);
124 AppendDict(NewDict,Name);
129 * \ingroup gdcmDictSet
130 * \brief Retrieve the specified dictionary (when existing) from this
132 * @param DictName The symbolic name of the searched dictionary.
133 * \result The retrieved dictionary.
135 gdcmDict *gdcmDictSet::GetDict(DictKey DictName)
137 DictSetHT::iterator dict = Dicts.find(DictName);
138 if(dict!=Dicts.end())
144 * \ingroup gdcmDictSet
145 * \brief Retrieve the default reference DICOM V3 public dictionary.
146 * \result The retrieved default dictionary.
148 gdcmDict *gdcmDictSet::GetDefaultPubDict()
150 return GetDict(PUB_DICT_NAME);
154 * \ingroup gdcmDictSet
155 * \brief Create a gdcmDictEntry which will be reference
157 * @return virtual entry
159 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
160 std::string vr,std::string fourth,
163 gdcmDictEntry *entry;
164 std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name;
165 std::map<std::string,gdcmDictEntry *>::iterator it;
167 it=virtualEntry.find(tag);
168 if(it!=virtualEntry.end())
174 entry=new gdcmDictEntry(group,element,vr,fourth,name);
175 virtualEntry[tag]=entry;
181 * \ingroup gdcmDictSet
182 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
183 * path to directory containing the dictionnaries. When
184 * the environnement variable is absent the path is defaulted
186 * @return path to directory containing the dictionnaries
188 std::string gdcmDictSet::BuildDictPath(void)
190 std::string ResultPath;
191 const char *EnvPath = (char*)0;
192 EnvPath = getenv("GDCM_DICT_PATH");
193 if (EnvPath && (strlen(EnvPath) != 0))
195 ResultPath = EnvPath;
196 if (ResultPath[ResultPath.length() -1] != '/' )
198 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
199 "Dictionary path set from environnement");
202 ResultPath = PUB_DICT_PATH;
206 //-----------------------------------------------------------------------------
208 bool gdcmDictSet::AppendDict(gdcmDict *NewDict,DictKey Name)
210 Dicts[Name] = NewDict;
214 //-----------------------------------------------------------------------------
217 //-----------------------------------------------------------------------------