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