00001 /*========================================================================= 00002 00003 Program: gdcm 00004 Module: $RCSfile: gdcmDictSet.cxx,v $ 00005 Language: C++ 00006 Date: $Date: 2005/11/28 15:20:33 $ 00007 Version: $Revision: 1.73 $ 00008 00009 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00010 l'Image). All rights reserved. See Doc/License.txt or 00011 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. 00012 00013 This software is distributed WITHOUT ANY WARRANTY; without even 00014 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 PURPOSE. See the above copyright notices for more information. 00016 00017 =========================================================================*/ 00018 00019 #include "gdcmDictSet.h" 00020 #include "gdcmDebug.h" 00021 #include <fstream> 00022 #include <stdlib.h> // For getenv 00023 #include <stdio.h> // For sprintf 00024 00025 namespace gdcm 00026 { 00027 00028 //----------------------------------------------------------------------------- 00029 // Constructor / Destructor 00034 DictSet::DictSet() 00035 { 00036 DictPath = BuildDictPath(); 00037 std::string pubDictFile(DictPath); 00038 pubDictFile += PUB_DICT_FILENAME; 00039 Dicts[PUB_DICT_NAME] = Dict::New(pubDictFile); 00040 } 00041 00045 DictSet::~DictSet() 00046 { 00047 // Remove dictionaries 00048 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) 00049 { 00050 if ( tag->second ) 00051 tag->second->Delete(); 00052 } 00053 Dicts.clear(); 00054 } 00055 00056 //----------------------------------------------------------------------------- 00057 // Public 00066 Dict *DictSet::LoadDictFromFile(std::string const &filename, 00067 DictKey const &name) 00068 { 00069 Dict *newDict = Dict::New(filename); 00070 Dicts[name] = newDict; 00071 00072 return newDict; 00073 } 00074 00081 Dict *DictSet::GetDict(DictKey const &dictName) 00082 { 00083 DictSetHT::iterator dict = Dicts.find(dictName); 00084 if ( dict != Dicts.end() ) 00085 { 00086 return dict->second; 00087 } 00088 return NULL; 00089 } 00090 00095 Dict *DictSet::GetFirstDict() 00096 { 00097 ItDictHt = Dicts.begin(); 00098 if ( ItDictHt != Dicts.end() ) 00099 return ItDictHt->second; 00100 return NULL; 00101 } 00102 00108 Dict *DictSet::GetNextDict() 00109 { 00110 gdcmAssertMacro (ItDictHt != Dicts.end()); 00111 00112 ++ItDictHt; 00113 if ( ItDictHt != Dicts.end() ) 00114 return ItDictHt->second; 00115 return NULL; 00116 } 00117 00125 std::string DictSet::BuildDictPath() 00126 { 00127 std::string resultPath; 00128 const char *envPath; 00129 envPath = getenv("GDCM_DICT_PATH"); 00130 00131 if (envPath && (strlen(envPath) != 0)) 00132 { 00133 resultPath = envPath; 00134 gdcmStaticWarningMacro( "Dictionary path set from environnement"); 00135 } 00136 else 00137 { 00138 resultPath = PUB_DICT_PATH; 00139 } 00140 if ( resultPath[resultPath.length()-1] != '/' ) 00141 { 00142 resultPath += '/'; 00143 } 00144 00145 return resultPath; 00146 } 00147 00148 //----------------------------------------------------------------------------- 00149 // Protected 00150 00151 //----------------------------------------------------------------------------- 00152 // Private 00153 00154 //----------------------------------------------------------------------------- 00155 // Print 00162 void DictSet::Print(std::ostream &os, std::string const & ) 00163 { 00164 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict) 00165 { 00166 os << "Printing dictionary " << dict->first << std::endl; 00167 dict->second->Print(os); 00168 } 00169 } 00170 00171 //----------------------------------------------------------------------------- 00172 } // end namespace gdcm