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