]> Creatis software - gdcm.git/blob - src/gdcmDictSet.cxx
* src/*.cxx : added pragma disable 4786/4251 to get rid of ~4300 warning
[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 using namespace std;
19
20 #define PUB_DICT_NAME     "DicomV3Dict"
21 #ifndef PUB_DICT_PATH
22 #  define PUB_DICT_PATH     "../Dicts/"
23 #endif
24 #define PUB_DICT_FILENAME "dicomV3.dic"
25
26 /** 
27  * \ingroup gdcmDictSet
28  * \brief   Consider all the entries of the public dicom dictionnary. 
29  *          Build all list of all the tag names of all those entries.
30  * \sa      gdcmDictSet::GetPubDictTagNamesByCategory
31  * @return  A list of all entries of the public dicom dictionnary.
32  */
33 list<string> * gdcmDictSet::GetPubDictTagNames(void) {
34    list<string> * Result = new list<string>;
35    TagKeyHT entries = GetDefaultPubDict()->GetEntries();
36    
37    for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
38       Result->push_back( tag->second->GetName() );
39    }
40    return Result;
41 }
42
43 /** 
44  * \ingroup gdcmDictSet
45  * \brief   Consider all the entries of the public dicom dictionnary.
46  *          Build an hashtable whose keys are the names of the groups
47  *          (fourth field in each line of dictionary) and whose corresponding
48  *          values are lists of all the dictionnary entries among that
49  *          group. Note that apparently the Dicom standard doesn't explicitely
50  *          define a name (as a string) for each group.
51  *          A typical usage of this method would be to enable a dynamic
52  *          configuration of a Dicom file browser: the admin/user can
53  *          select in the interface which Dicom tags should be displayed.
54  * @return  An hashtable: whose keys are the names of the groups and whose
55  *          corresponding values are lists of all the dictionnary entries
56  *          among that group.
57  */
58 map<string, list<string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
59    map<string, list<string> > * Result = new map<string, list<string> >;
60    TagKeyHT entries = GetDefaultPubDict()->GetEntries();
61
62    for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
63       (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
64    }
65    return Result;
66 }
67
68 /**
69  * \ingroup gdcmDictSet
70  * \brief   Obtain from the GDCM_DICT_PATH environnement variable the
71  *          path to directory containing the dictionnaries. When
72  *          the environnement variable is absent the path is defaulted
73  *          to "../Dicts/".
74  */
75 string gdcmDictSet::BuildDictPath(void) {
76    string ResultPath;
77    const char* EnvPath = (char*)0;
78    EnvPath = getenv("GDCM_DICT_PATH");
79    if (EnvPath && (strlen(EnvPath) != 0)) {
80       ResultPath = EnvPath;
81       if (ResultPath[ResultPath.length() -1] != '/' )
82          ResultPath += '/';
83       dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
84                      "Dictionary path set from environnement");
85    } else
86       ResultPath = PUB_DICT_PATH;
87    return ResultPath;
88 }
89
90 /** 
91  * \ingroup gdcmDictSet
92  * \brief   The Dictionnary Set obtained with this constructor simply
93  *          contains the Default Public dictionnary.
94  */
95 gdcmDictSet::gdcmDictSet(void) {
96    DictPath = BuildDictPath();
97    string PubDictFile = DictPath + PUB_DICT_FILENAME;
98    Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
99 }
100
101 gdcmDictSet::~gdcmDictSet() {
102    for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
103       gdcmDict* EntryToDelete = tag->second;
104       if ( EntryToDelete )
105          delete EntryToDelete;
106    }
107    Dicts.clear();
108 }
109
110 /**
111  * \ingroup gdcmDictSet
112  * \brief   Loads a dictionary from a specified file, and add it
113  *          to already the existing ones contained in this gdcmDictSet.
114  * @param   FileName Absolute or relative filename containing the
115  *          dictionary to load.
116  * @param   Name Symbolic name that be used as identifier of the newly 
117  *          created dictionary.
118  */
119 void gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) {
120    gdcmDict *NewDict = new gdcmDict(FileName);
121    Dicts[Name] = NewDict;
122 }
123
124 /**
125  * \ingroup gdcmDictSet
126  * \brief   Print, in an informal fashion, the list of all the dictionaries
127  *          contained is this gdcmDictSet, along with their respective content.
128  * @param   os Output stream used for printing.
129  */
130 void gdcmDictSet::Print(ostream& os) {
131    for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
132       os << "Printing dictionary " << dict->first << " \n";
133       dict->second->Print(os);
134    }
135 }
136
137 /**
138  * \ingroup gdcmDictSet
139  * \brief   Retrieve the specified dictionary (when existing) from this
140  *          gdcmDictSet.
141  * @param   DictName The synbolic name of the searched dictionary.
142  * \result  The retrieved dictionary.
143  */
144 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
145    DictSetHT::iterator dict = Dicts.find(DictName);
146    return dict->second;
147 }
148
149 /**
150  * \ingroup gdcmDictSet
151  * \brief   Retrieve the default reference DICOM V3 public dictionary.
152  * \result  The retrieved default dictionary.
153  */
154 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
155    return GetDict(PUB_DICT_NAME);
156 }