00001
00002
00003 #include "gdcmDictSet.h"
00004 #include "gdcmUtil.h"
00005 #include <fstream>
00006 #include <stdlib.h>
00007
00008 #define PUB_DICT_NAME "DicomV3Dict"
00009 #ifndef PUB_DICT_PATH
00010 # define PUB_DICT_PATH "../Dicts/"
00011 #endif
00012 #define PUB_DICT_FILENAME "dicomV3.dic"
00013
00014
00015
00021 gdcmDictSet::gdcmDictSet(void)
00022 {
00023 DictPath = BuildDictPath();
00024 std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
00025 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
00026 }
00027
00032 gdcmDictSet::~gdcmDictSet()
00033 {
00034
00035 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
00036 {
00037 gdcmDict *EntryToDelete = tag->second;
00038 if ( EntryToDelete )
00039 delete EntryToDelete;
00040 tag->second=NULL;
00041 }
00042 Dicts.clear();
00043
00044
00045 std::map<std::string,gdcmDictEntry *>::iterator it;
00046 for(it=virtualEntry.begin(); it!=virtualEntry.end(); ++it)
00047 {
00048 gdcmDictEntry *Entry = it->second;
00049 if ( Entry )
00050 delete Entry;
00051 it->second=NULL;
00052 }
00053 }
00054
00055
00056
00063 void gdcmDictSet::Print(std::ostream& os)
00064 {
00065 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
00066 {
00067 os << "Printing dictionary " << dict->first << std::endl;
00068 dict->second->Print(os);
00069 }
00070 }
00071
00072
00073
00081 std::list<std::string> *gdcmDictSet::GetPubDictEntryNames(void)
00082 {
00083 return(GetDefaultPubDict()->GetDictEntryNames());
00084 }
00085
00111 std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictEntryNamesByCategory(void)
00112 {
00113 return(GetDefaultPubDict()->GetDictEntryNamesByCategory());
00114 }
00115
00125 gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name)
00126 {
00127 gdcmDict *NewDict = new gdcmDict(FileName);
00128 AppendDict(NewDict,Name);
00129 return(NewDict);
00130 }
00131
00139 gdcmDict *gdcmDictSet::GetDict(DictKey DictName)
00140 {
00141 DictSetHT::iterator dict = Dicts.find(DictName);
00142 if(dict!=Dicts.end())
00143 return dict->second;
00144 return NULL;
00145 }
00146
00152 gdcmDict *gdcmDictSet::GetDefaultPubDict()
00153 {
00154 return GetDict(PUB_DICT_NAME);
00155 }
00156
00163 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
00164 std::string vr,std::string fourth,
00165 std::string name)
00166 {
00167 gdcmDictEntry *entry;
00168 std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name;
00169 std::map<std::string,gdcmDictEntry *>::iterator it;
00170
00171 it=virtualEntry.find(tag);
00172 if(it!=virtualEntry.end())
00173 {
00174 entry=it->second;
00175 }
00176 else
00177 {
00178 entry=new gdcmDictEntry(group,element,vr,fourth,name);
00179 virtualEntry[tag]=entry;
00180 }
00181 return(entry);
00182 }
00183
00192 std::string gdcmDictSet::BuildDictPath(void)
00193 {
00194 std::string ResultPath;
00195 const char *EnvPath = (char*)0;
00196 EnvPath = getenv("GDCM_DICT_PATH");
00197 if (EnvPath && (strlen(EnvPath) != 0))
00198 {
00199 ResultPath = EnvPath;
00200 if (ResultPath[ResultPath.length() -1] != '/' )
00201 ResultPath += '/';
00202 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
00203 "Dictionary path set from environnement");
00204 }
00205 else
00206 ResultPath = PUB_DICT_PATH;
00207 return ResultPath;
00208 }
00209
00210
00211
00212 bool gdcmDictSet::AppendDict(gdcmDict *NewDict,DictKey Name)
00213 {
00214 Dicts[Name] = NewDict;
00215 return(true);
00216 }
00217
00218
00219
00220
00221
00222
00223