]> Creatis software - gdcm.git/blob - src/gdcmDictSet.cxx
Remove using namespace std;
[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  * @return  An hashtable: whose keys are the names of the groups and whose
54  *          corresponding values are lists of all the dictionnary entries
55  *          among that group.
56  */
57 std::map<std::string, std::list<std::string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
58    std::map<std::string, std::list<std::string> > * Result = new map<std::string, std::list<std::string> >;
59    TagKeyHT entries = GetDefaultPubDict()->GetEntries();
60
61    for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
62       (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
63    }
64    return Result;
65 }
66
67 /**
68  * \ingroup gdcmDictSet
69  * \brief   Obtain from the GDCM_DICT_PATH environnement variable the
70  *          path to directory containing the dictionnaries. When
71  *          the environnement variable is absent the path is defaulted
72  *          to "../Dicts/".
73  */
74 std::string gdcmDictSet::BuildDictPath(void) {
75    std::string ResultPath;
76    const char* EnvPath = (char*)0;
77    EnvPath = getenv("GDCM_DICT_PATH");
78    if (EnvPath && (strlen(EnvPath) != 0)) {
79       ResultPath = EnvPath;
80       if (ResultPath[ResultPath.length() -1] != '/' )
81          ResultPath += '/';
82       dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
83                      "Dictionary path set from environnement");
84    } else
85       ResultPath = PUB_DICT_PATH;
86    return ResultPath;
87 }
88
89 /** 
90  * \ingroup gdcmDictSet
91  * \brief   The Dictionnary Set obtained with this constructor simply
92  *          contains the Default Public dictionnary.
93  */
94 gdcmDictSet::gdcmDictSet(void) {
95    DictPath = BuildDictPath();
96    std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
97    Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
98 }
99
100 gdcmDictSet::~gdcmDictSet() {
101    for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
102       gdcmDict* EntryToDelete = tag->second;
103       if ( EntryToDelete )
104          delete EntryToDelete;
105    }
106    Dicts.clear();
107 }
108
109 /**
110  * \ingroup gdcmDictSet
111  * \brief   Loads a dictionary from a specified file, and add it
112  *          to already the existing ones contained in this gdcmDictSet.
113  * @param   FileName Absolute or relative filename containing the
114  *          dictionary to load.
115  * @param   Name Symbolic name that be used as identifier of the newly 
116  *          created dictionary.
117  */
118 void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) {
119    gdcmDict *NewDict = new gdcmDict(FileName);
120    Dicts[Name] = NewDict;
121 }
122
123 /**
124  * \ingroup gdcmDictSet
125  * \brief   Print, in an informal fashion, the list of all the dictionaries
126  *          contained is this gdcmDictSet, along with their respective content.
127  * @param   os Output stream used for printing.
128  */
129 void gdcmDictSet::Print(ostream& os) {
130    for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
131       os << "Printing dictionary " << dict->first << " \n";
132       dict->second->Print(os);
133    }
134 }
135
136 /**
137  * \ingroup gdcmDictSet
138  * \brief   Retrieve the specified dictionary (when existing) from this
139  *          gdcmDictSet.
140  * @param   DictName The synbolic name of the searched dictionary.
141  * \result  The retrieved dictionary.
142  */
143 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
144    DictSetHT::iterator dict = Dicts.find(DictName);
145    return dict->second;
146 }
147
148 /**
149  * \ingroup gdcmDictSet
150  * \brief   Retrieve the default reference DICOM V3 public dictionary.
151  * \result  The retrieved default dictionary.
152  */
153 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
154    return GetDict(PUB_DICT_NAME);
155 }