]> Creatis software - gdcm.git/blob - src/gdcmDictSet.cxx
warning added in doxygen part
[gdcm.git] / src / gdcmDictSet.cxx
1 // gdcmDictEntry
2
3 #ifdef _MSC_VER
4 //'identifier' : decorated name length exceeded, name was truncated
5 //#pragma warning ( disable : 4503 )
6 // 'identifier' : class 'type' needs to have dll-interface to be used by
7 // clients of class 'type2'
8 #pragma warning ( disable : 4251 )
9 // 'identifier' : identifier was truncated to 'number' characters in the
10 // debug information
11 #pragma warning ( disable : 4786 )
12 #endif //_MSC_VER
13
14 #include <fstream>
15 #include <stdlib.h>  // For getenv
16 #include "gdcmUtil.h"
17 #include "gdcmDictSet.h"
18
19 #define PUB_DICT_NAME     "DicomV3Dict"
20 #ifndef PUB_DICT_PATH
21 #  define PUB_DICT_PATH     "../Dicts/"
22 #endif
23 #define PUB_DICT_FILENAME "dicomV3.dic"
24
25 /** 
26  * \ingroup gdcmDictSet
27  * \brief   Consider all the entries of the public dicom dictionnary. 
28  *          Build all list of all the tag names of all those entries.
29  * \sa      gdcmDictSet::GetPubDictTagNamesByCategory
30  * @return  A list of all entries of the public dicom dictionnary.
31  */
32 std::list<std::string> * gdcmDictSet::GetPubDictTagNames(void) {
33    std::list<std::string> * Result = new std::list<std::string>;
34    TagKeyHT entries = GetDefaultPubDict()->GetEntries();
35    
36    for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
37       Result->push_back( tag->second->GetName() );
38    }
39    return Result;
40 }
41
42 /** 
43  * \ingroup gdcmDictSet
44  * \brief   Consider all the entries of the public dicom dictionnary.
45  *          Build an hashtable whose keys are the names of the groups
46  *          (fourth field in each line of dictionary) and whose corresponding
47  *          values are lists of all the dictionnary entries among that
48  *          group. Note that apparently the Dicom standard doesn't explicitely
49  *          define a name (as a string) for each group.
50  *          A typical usage of this method would be to enable a dynamic
51  *          configuration of a Dicom file browser: the admin/user can
52  *          select in the interface which Dicom tags should be displayed.
53  * \warning Dicom *doesn't* define any name for any 'categorie'
54  *          (the dictionnary fourth field was formerly NIH defined
55  *           - and no longer he is-
56  *           and will be removed when Dicom provides us a text file
57  *           with the 'official' Dictionnary, that would be more friendly
58  *           than asking us to perform a line by line check od thhe dictionnary
59  *           at the beginning of each year to -try to- guess the changes)
60  *           Therefore : please NEVER use that fourth field :-(
61  *
62  * @return  An hashtable: whose keys are the names of the groups and whose
63  *          corresponding values are lists of all the dictionnary entries
64  *          among that group.
65  */
66 std::map<std::string, std::list<std::string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
67    std::map<std::string, std::list<std::string> > * Result = new std::map<std::string, std::list<std::string> >;
68    TagKeyHT entries = GetDefaultPubDict()->GetEntries();
69
70    for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
71       (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
72    }
73    return Result;
74 }
75
76 /**
77  * \ingroup gdcmDictSet
78  * \brief   Obtain from the GDCM_DICT_PATH environnement variable the
79  *          path to directory containing the dictionnaries. When
80  *          the environnement variable is absent the path is defaulted
81  *          to "../Dicts/".
82  */
83 std::string gdcmDictSet::BuildDictPath(void) {
84    std::string ResultPath;
85    const char* EnvPath = (char*)0;
86    EnvPath = getenv("GDCM_DICT_PATH");
87    if (EnvPath && (strlen(EnvPath) != 0)) {
88       ResultPath = EnvPath;
89       if (ResultPath[ResultPath.length() -1] != '/' )
90          ResultPath += '/';
91       dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
92                      "Dictionary path set from environnement");
93    } else
94       ResultPath = PUB_DICT_PATH;
95    return ResultPath;
96 }
97
98 /** 
99  * \ingroup gdcmDictSet
100  * \brief   The Dictionnary Set obtained with this constructor simply
101  *          contains the Default Public dictionnary.
102  */
103 gdcmDictSet::gdcmDictSet(void) {
104    DictPath = BuildDictPath();
105    std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
106    Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
107 }
108
109 gdcmDictSet::~gdcmDictSet() {
110    for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
111       gdcmDict* EntryToDelete = tag->second;
112       if ( EntryToDelete )
113          delete EntryToDelete;
114    }
115    Dicts.clear();
116 }
117
118 /**
119  * \ingroup gdcmDictSet
120  * \brief   Loads a dictionary from a specified file, and add it
121  *          to already the existing ones contained in this gdcmDictSet.
122  * @param   FileName Absolute or relative filename containing the
123  *          dictionary to load.
124  * @param   Name Symbolic name that be used as identifier of the newly 
125  *          created dictionary.
126  */
127 void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) {
128    gdcmDict *NewDict = new gdcmDict(FileName);
129    Dicts[Name] = NewDict;
130 }
131
132 /**
133  * \ingroup gdcmDictSet
134  * \brief   Print, in an informal fashion, the list of all the dictionaries
135  *          contained is this gdcmDictSet, along with their respective content.
136  * @param   os Output stream used for printing.
137  */
138 void gdcmDictSet::Print(std::ostream& os) {
139    for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
140       std::os << "Printing dictionary " << dict->first << std::endl;
141       dict->second->Print(os);
142    }
143 }
144
145 /**
146  * \ingroup gdcmDictSet
147  * \brief   Retrieve the specified dictionary (when existing) from this
148  *          gdcmDictSet.
149  * @param   DictName The synbolic name of the searched dictionary.
150  * \result  The retrieved dictionary.
151  */
152 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
153    DictSetHT::iterator dict = Dicts.find(DictName);
154    return dict->second;
155 }
156
157 /**
158  * \ingroup gdcmDictSet
159  * \brief   Retrieve the default reference DICOM V3 public dictionary.
160  * \result  The retrieved default dictionary.
161  */
162 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
163    return GetDict(PUB_DICT_NAME);
164 }