]> Creatis software - gdcm.git/blob - src/gdcmDictSet.cxx
e24e8d0a9a3f4237bf89db1720bc65eb931db82d
[gdcm.git] / src / gdcmDictSet.cxx
1 // gdcmDictEntry
2
3 #include <fstream>
4 #include <stdlib.h>  // For getenv
5 #include "gdcm.h"
6 #include "gdcmUtil.h"
7
8 #define PUB_DICT_NAME     "DicomV3Dict"
9 #ifndef PUB_DICT_PATH
10 #  define PUB_DICT_PATH     "../Dicts/"
11 #endif
12 #define PUB_DICT_FILENAME "dicomV3.dic"
13
14 gdcmDictSet::gdcmDictSet(void) {
15         SetDictPath();
16         if (! LoadDicomV3Dict())
17                           return;
18 }
19
20 void gdcmDictSet::SetDictPath(void) {
21         const char* EnvPath = (char*)0;
22         EnvPath = getenv("GDCM_DICT_PATH");
23         if (EnvPath && (strlen(EnvPath) != 0)) {
24                 DictPath = EnvPath;
25                 if (DictPath[DictPath.length() -1] != '/' )
26                         DictPath += '/';
27                 dbg.Verbose(1, "gdcmDictSet::SetDictPath:",
28                      "Dictionary path set from environnement");
29         } else
30                 DictPath = PUB_DICT_PATH;
31 }
32
33 int gdcmDictSet::LoadDicomV3Dict(void) {
34         if (dicts.count(PUB_DICT_NAME))
35                 return 1;
36         return LoadDictFromFile(DictPath + PUB_DICT_FILENAME, PUB_DICT_NAME);
37 }
38
39 int gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) {
40         gdcmDict *NewDict = new gdcmDict(FileName.c_str());
41         dicts[Name] = NewDict;
42         return 0;   //FIXME if this is a dummy return make the method void
43 }
44
45 void gdcmDictSet::Print(ostream& os) {
46         for (DictSetHT::iterator dict = dicts.begin(); dict != dicts.end(); ++dict){
47                 os << "Printing dictionary " << dict->first << " \n";
48                 dict->second->Print(os);
49         }
50 }
51
52 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
53         DictSetHT::iterator dict = dicts.find(DictName);
54         return dict->second;
55 }
56
57 gdcmDict * gdcmDictSet::GetDefaultPublicDict() {
58         return GetDict(PUB_DICT_NAME);
59 }