]> Creatis software - gdcm.git/blob - src/gdcmDictSet.cxx
* Python wrapping process moved away from src/Makefile to
[gdcm.git] / src / gdcmDictSet.cxx
1 #include <fstream>
2 #include <stdlib.h>  // For getenv
3 #include "gdcm.h"
4 #include "gdcmUtil.h"
5
6 #define PUB_DICT_NAME     "DicomV3Dict"
7 #define PUB_DICT_PATH     "../Dicts/"
8 #define PUB_DICT_FILENAME "dicomV3.dic"
9
10 gdcmDictSet::gdcmDictSet(void) {
11         SetDictPath();
12         if (! LoadDicomV3Dict())
13                           return;
14 }
15
16 void gdcmDictSet::SetDictPath(void) {
17         const char* EnvPath = (char*)0;
18         EnvPath = getenv("GDCM_DICT_PATH");
19         if (EnvPath && (strlen(EnvPath) != 0))
20                 DictPath = EnvPath;
21         else
22                 DictPath = PUB_DICT_PATH;
23 }
24
25 int gdcmDictSet::LoadDicomV3Dict(void) {
26         if (dicts.count(PUB_DICT_NAME))
27                 return 1;
28         return LoadDictFromFile(DictPath + PUB_DICT_FILENAME, PUB_DICT_NAME);
29 }
30
31 int gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) {
32         gdcmDict *NewDict = new gdcmDict(FileName.c_str());
33         dicts[Name] = NewDict; 
34 }
35
36 void gdcmDictSet::Print(ostream& os) {
37         for (DictSetHT::iterator dict = dicts.begin(); dict != dicts.end(); ++dict){
38                 os << "Printing dictionary " << dict->first << " \n";
39                 dict->second->Print(os);
40         }
41 }
42
43 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
44         DictSetHT::iterator dict = dicts.find(DictName);
45         return dict->second;
46 }
47
48 gdcmDict * gdcmDictSet::GetDefaultPublicDict() {
49         return GetDict(PUB_DICT_NAME);
50 }