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 + PUB_DICT_FILENAME;
19 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
23 * \ingroup gdcmDictSet
26 gdcmDictSet::~gdcmDictSet()
28 // Remove dictionnaries
29 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
31 gdcmDict *EntryToDelete = tag->second;
38 // Remove virtual dictionnary entries
39 std::map<std::string,gdcmDictEntry *>::iterator it;
40 for(it=virtualEntry.begin(); it!=virtualEntry.end(); ++it)
42 gdcmDictEntry *Entry = it->second;
49 //-----------------------------------------------------------------------------
52 * \ingroup gdcmDictSet
53 * \brief Print, in an informal fashion, the list of all the dictionaries
54 * contained is this gdcmDictSet, along with their respective content.
55 * @param os Output stream used for printing.
57 void gdcmDictSet::Print(std::ostream& os)
59 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
61 os << "Printing dictionary " << dict->first << std::endl;
62 dict->second->Print(os);
66 //-----------------------------------------------------------------------------
69 * \ingroup gdcmDictSet
70 * \brief Consider all the entries of the public dicom dictionnary.
71 * Build all list of all the tag names of all those entries.
72 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
73 * @return A list of all entries of the public dicom dictionnary.
75 std::list<std::string> *gdcmDictSet::GetPubDictEntryNames(void)
77 return(GetDefaultPubDict()->GetDictEntryNames());
81 * \ingroup gdcmDictSet
83 * - Consider all the entries of the public dicom dictionnary.
84 * - Build an hashtable whose keys are the names of the groups
85 * (fourth field in each line of dictionary) and whose corresponding
86 * values are lists of all the dictionnary entries among that
87 * group. Note that apparently the Dicom standard doesn't explicitely
88 * define a name (as a string) for each group.
89 * - A typical usage of this method would be to enable a dynamic
90 * configuration of a Dicom file browser: the admin/user can
91 * select in the interface which Dicom tags should be displayed.
93 * - Dicom *doesn't* define any name for any 'categorie'
94 * (the dictionnary fourth field was formerly NIH defined
95 * -and no longer he is-
96 * and will be removed when Dicom provides us a text file
97 * with the 'official' Dictionnary, that would be more friendly
98 * than asking us to perform a line by line check of the dictionnary
99 * at the beginning of each year to -try to- guess the changes)
100 * - Therefore : please NEVER use that fourth field :-(
102 * @return An hashtable: whose keys are the names of the groups and whose
103 * corresponding values are lists of all the dictionnary entries
106 std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictEntryNamesByCategory(void)
108 return(GetDefaultPubDict()->GetDictEntryNamesByCategory());
112 * \ingroup gdcmDictSet
113 * \brief Loads a dictionary from a specified file, and add it
114 * to already the existing ones contained in this gdcmDictSet.
115 * @param FileName Absolute or relative filename containing the
116 * dictionary to load.
117 * @param Name Symbolic name that be used as identifier of the newly
118 * created dictionary.
120 gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name)
122 gdcmDict *NewDict = new gdcmDict(FileName);
123 AppendDict(NewDict,Name);
128 * \ingroup gdcmDictSet
129 * \brief Retrieve the specified dictionary (when existing) from this
131 * @param DictName The symbolic name of the searched dictionary.
132 * \result The retrieved dictionary.
134 gdcmDict *gdcmDictSet::GetDict(DictKey DictName)
136 DictSetHT::iterator dict = Dicts.find(DictName);
137 if(dict!=Dicts.end())
143 * \ingroup gdcmDictSet
144 * \brief Retrieve the default reference DICOM V3 public dictionary.
145 * \result The retrieved default dictionary.
147 gdcmDict *gdcmDictSet::GetDefaultPubDict()
149 return GetDict(PUB_DICT_NAME);
153 * \ingroup gdcmDictSet
154 * \brief Create a gdcmDictEntry which will be reference
156 * @return virtual entry
158 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
159 std::string vr,std::string fourth,
162 gdcmDictEntry *entry;
163 std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name;
164 std::map<std::string,gdcmDictEntry *>::iterator it;
166 it=virtualEntry.find(tag);
167 if(it!=virtualEntry.end())
173 entry=new gdcmDictEntry(group,element,vr,fourth,name);
174 virtualEntry[tag]=entry;
180 * \ingroup gdcmDictSet
181 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
182 * path to directory containing the dictionnaries. When
183 * the environnement variable is absent the path is defaulted
185 * @return path to directory containing the dictionnaries
187 std::string gdcmDictSet::BuildDictPath(void)
189 std::string ResultPath;
190 const char *EnvPath = (char*)0;
191 EnvPath = getenv("GDCM_DICT_PATH");
192 if (EnvPath && (strlen(EnvPath) != 0))
194 ResultPath = EnvPath;
195 if (ResultPath[ResultPath.length() -1] != '/' )
197 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
198 "Dictionary path set from environnement");
201 ResultPath = PUB_DICT_PATH;
205 //-----------------------------------------------------------------------------
207 bool gdcmDictSet::AppendDict(gdcmDict *NewDict,DictKey Name)
209 Dicts[Name] = NewDict;
213 //-----------------------------------------------------------------------------
216 //-----------------------------------------------------------------------------