Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmDictSet.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDictSet.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/05 01:37:08 $
00007   Version:   $Revision: 1.60 $
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 
00024 namespace gdcm 
00025 {
00026 
00027 //-----------------------------------------------------------------------------
00028 // Constructor / Destructor
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    // Remove dictionaries
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    // Remove virtual dictionary entries
00059    VirtualEntry.clear();
00060 }
00061 
00062 //-----------------------------------------------------------------------------
00063 // Public
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 // Protected
00193 bool DictSet::AppendDict(Dict *newDict, DictKey const &name)
00194 {
00195    Dicts[name] = newDict;
00196 
00197    return true;
00198 }
00199 
00200 //-----------------------------------------------------------------------------
00201 // Private
00202 
00203 //-----------------------------------------------------------------------------
00204 // Print
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 } // end namespace gdcm

Generated on Thu Feb 10 22:17:57 2005 for gdcm by doxygen 1.3.6