00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmDictSet.h"
00020 #include "gdcmDebug.h"
00021 #include <fstream>
00022 #include <stdlib.h>
00023
00024 namespace gdcm
00025 {
00026
00027
00028
00033 DictSet::DictSet()
00034 {
00035 DictPath = BuildDictPath();
00036 std::string pubDictFile(DictPath);
00037 pubDictFile += PUB_DICT_FILENAME;
00038 Dicts[PUB_DICT_NAME] = new Dict(pubDictFile);
00039 }
00040
00044 DictSet::~DictSet()
00045 {
00046
00047 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
00048 {
00049 Dict *entryToDelete = tag->second;
00050 if ( entryToDelete )
00051 {
00052 delete entryToDelete;
00053 }
00054 tag->second = NULL;
00055 }
00056 Dicts.clear();
00057
00058
00059 VirtualEntry.clear();
00060 }
00061
00062
00063
00072 Dict *DictSet::LoadDictFromFile(std::string const &filename,
00073 DictKey const &name)
00074 {
00075 Dict *newDict = new Dict(filename);
00076 AppendDict(newDict, name);
00077
00078 return newDict;
00079 }
00080
00087 Dict *DictSet::GetDict(DictKey const &dictName)
00088 {
00089 DictSetHT::iterator dict = Dicts.find(dictName);
00090 if(dict != Dicts.end())
00091 {
00092 return dict->second;
00093 }
00094 return NULL;
00095 }
00096
00102 DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
00103 uint16_t element,
00104 TagName vr,
00105 TagName vm,
00106 TagName name)
00107 {
00108 DictEntry *entry;
00109 const std::string tag = DictEntry::TranslateToKey(group,element)
00110 + "#" + vr + "#" + vm + "#" + name;
00111 TagKeyHT::iterator it;
00112
00113 it = VirtualEntry.find(tag);
00114 if(it != VirtualEntry.end())
00115 {
00116 entry = &(it->second);
00117 }
00118 else
00119 {
00120 DictEntry ent(group, element, vr, vm, name);
00121 VirtualEntry.insert(
00122 std::map<TagKey, DictEntry>::value_type
00123 (tag, ent));
00124 entry = &(VirtualEntry.find(tag)->second);
00125 }
00126
00127 return entry;
00128 }
00129
00134 Dict *DictSet::GetFirstEntry()
00135 {
00136 ItDictHt = Dicts.begin();
00137 if( ItDictHt != Dicts.end() )
00138 return ItDictHt->second;
00139 return NULL;
00140 }
00141
00147 Dict *DictSet::GetNextEntry()
00148 {
00149 gdcmAssertMacro (ItDictHt != Dicts.end());
00150
00151 ++ItDictHt;
00152 if ( ItDictHt != Dicts.end() )
00153 return ItDictHt->second;
00154 return NULL;
00155 }
00156
00164 std::string DictSet::BuildDictPath()
00165 {
00166 std::string resultPath;
00167 const char *envPath = 0;
00168 envPath = getenv("GDCM_DICT_PATH");
00169
00170 if (envPath && (strlen(envPath) != 0))
00171 {
00172 resultPath = envPath;
00173 if ( resultPath[resultPath.length()-1] != '/' )
00174 {
00175 resultPath += '/';
00176 }
00177 gdcmWarningMacro( "Dictionary path set from environnement");
00178 }
00179 else
00180 {
00181 resultPath = PUB_DICT_PATH;
00182 }
00183
00184 return resultPath;
00185 }
00186
00187
00188
00193 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
00194 {
00195 Dicts[name] = newDict;
00196
00197 return true;
00198 }
00199
00200
00201
00202
00203
00204
00211 void DictSet::Print(std::ostream &os, std::string const & )
00212 {
00213 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
00214 {
00215 os << "Printing dictionary " << dict->first << std::endl;
00216 dict->second->Print(os);
00217 }
00218 }
00219
00220
00221 }