2 //-----------------------------------------------------------------------------
3 #include "gdcmDictSet.h"
6 #include <stdlib.h> // For getenv
8 #define PUB_DICT_NAME "DicomV3Dict"
10 # define PUB_DICT_PATH "../Dicts/"
12 #define PUB_DICT_FILENAME "dicomV3.dic"
14 //-----------------------------------------------------------------------------
15 // Constructor / Destructor
17 * \ingroup gdcmDictSet
18 * \brief The Dictionnary Set obtained with this constructor simply
19 * contains the Default Public dictionnary.
21 gdcmDictSet::gdcmDictSet(void) {
22 DictPath = BuildDictPath();
23 std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
24 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
28 * \ingroup gdcmDictSet
31 gdcmDictSet::~gdcmDictSet() {
32 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
33 gdcmDict* EntryToDelete = tag->second;
40 //-----------------------------------------------------------------------------
43 * \ingroup gdcmDictSet
44 * \brief Print, in an informal fashion, the list of all the dictionaries
45 * contained is this gdcmDictSet, along with their respective content.
46 * @param os Output stream used for printing.
48 void gdcmDictSet::Print(std::ostream& os) {
49 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
50 os << "Printing dictionary " << dict->first << std::endl;
51 dict->second->Print(os);
55 //-----------------------------------------------------------------------------
58 * \ingroup gdcmDictSet
59 * \brief Consider all the entries of the public dicom dictionnary.
60 * Build all list of all the tag names of all those entries.
61 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
62 * @return A list of all entries of the public dicom dictionnary.
64 std::list<std::string> * gdcmDictSet::GetPubDictTagNames(void) {
65 std::list<std::string> * Result = new std::list<std::string>;
66 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
68 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
69 Result->push_back( tag->second->GetName() );
75 * \ingroup gdcmDictSet
76 * \brief Consider all the entries of the public dicom dictionnary.
77 * Build an hashtable whose keys are the names of the groups
78 * (fourth field in each line of dictionary) and whose corresponding
79 * values are lists of all the dictionnary entries among that
80 * group. Note that apparently the Dicom standard doesn't explicitely
81 * define a name (as a string) for each group.
82 * A typical usage of this method would be to enable a dynamic
83 * configuration of a Dicom file browser: the admin/user can
84 * select in the interface which Dicom tags should be displayed.
85 * \warning Dicom *doesn't* define any name for any 'categorie'
86 * (the dictionnary fourth field was formerly NIH defined
87 * - and no longer he is-
88 * and will be removed when Dicom provides us a text file
89 * with the 'official' Dictionnary, that would be more friendly
90 * than asking us to perform a line by line check of the dictionnary
91 * at the beginning of each year to -try to- guess the changes)
92 * Therefore : please NEVER use that fourth field :-(
94 * @return An hashtable: whose keys are the names of the groups and whose
95 * corresponding values are lists of all the dictionnary entries
98 std::map<std::string, std::list<std::string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
99 std::map<std::string, std::list<std::string> > * Result = new std::map<std::string, std::list<std::string> >;
100 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
102 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
103 (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
109 * \ingroup gdcmDictSet
110 * \brief Loads a dictionary from a specified file, and add it
111 * to already the existing ones contained in this gdcmDictSet.
112 * @param FileName Absolute or relative filename containing the
113 * dictionary to load.
114 * @param Name Symbolic name that be used as identifier of the newly
115 * created dictionary.
117 void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) {
118 gdcmDict *NewDict = new gdcmDict(FileName);
119 AppendDict(NewDict,Name);
123 * \ingroup gdcmDictSet
124 * \brief Retrieve the specified dictionary (when existing) from this
126 * @param DictName The symbolic name of the searched dictionary.
127 * \result The retrieved dictionary.
129 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
130 DictSetHT::iterator dict = Dicts.find(DictName);
135 * \ingroup gdcmDictSet
136 * \brief Retrieve the default reference DICOM V3 public dictionary.
137 * \result The retrieved default dictionary.
139 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
140 return GetDict(PUB_DICT_NAME);
144 * \ingroup gdcmDictSet
145 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
146 * path to directory containing the dictionnaries. When
147 * the environnement variable is absent the path is defaulted
149 * @return path to directory containing the dictionnaries
151 std::string gdcmDictSet::BuildDictPath(void) {
152 std::string ResultPath;
153 const char* EnvPath = (char*)0;
154 EnvPath = getenv("GDCM_DICT_PATH");
155 if (EnvPath && (strlen(EnvPath) != 0)) {
156 ResultPath = EnvPath;
157 if (ResultPath[ResultPath.length() -1] != '/' )
159 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
160 "Dictionary path set from environnement");
162 ResultPath = PUB_DICT_PATH;
166 //-----------------------------------------------------------------------------
168 bool gdcmDictSet::AppendDict(gdcmDict* NewDict,DictKey Name)
170 Dicts[Name] = NewDict;
174 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------