X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDict.cxx;h=a314a91a09b4a7caf3cc91c850117da3d106c7f9;hb=f2dd0107ba49eda3386b34715cdc0c046d12397f;hp=845114d235816d3fd7a8badef24a73ee3899207d;hpb=cb6cf86b2b3cc6b43d40561fb9552ebd19fdbc99;p=gdcm.git diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 845114d2..a314a91a 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.cxx,v $ Language: C++ - Date: $Date: 2005/10/23 15:32:30 $ - Version: $Revision: 1.82 $ + Date: $Date: 2007/05/23 14:18:09 $ + Version: $Revision: 1.87 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,7 +24,7 @@ #include #include -namespace gdcm +namespace GDCM_NAME_SPACE { //----------------------------------------------------------------------------- /// \brief auto generated function, to fill up the Dicom Dictionnary, @@ -47,7 +47,7 @@ Dict::Dict( ) */ Dict::Dict(std::string const &filename) { - + gdcmDebugMacro( "in Dict::Dict, filename =[" << filename << "]" ); std::ifstream from( filename.c_str() ); if ( !from ) { @@ -56,7 +56,9 @@ Dict::Dict(std::string const &filename) FillDefaultDataDict( this ); } else - { + { + gdcmDebugMacro( "in Dict::Dict, DoTheLoadingJob filename =[" + << filename << "]" ); DoTheLoadingJob(from); Filename = filename; } @@ -80,7 +82,6 @@ Dict::~Dict() */ bool Dict::AddDict(std::string const &filename) { - std::ifstream from( filename.c_str() ); if ( !from ) { @@ -94,7 +95,6 @@ bool Dict::AddDict(std::string const &filename) } } - /** * \brief Removes from the current Dicom Dict all the entries held in a source dictionary * \note it concerns only Private Dictionnary @@ -116,10 +116,14 @@ bool Dict::RemoveDict(std::string const &filename) TagName vm; TagName name; - while (!from.eof() && from) + while ( true ) { from >> std::hex; from >> group; + + if (from.eof()) + break; + from >> elem; from >> vr; from >> vm; @@ -155,12 +159,15 @@ bool Dict::AddEntry(DictEntry *newEntry) } } -/** - * \brief replaces an already existing Dicom Element by a new one - * @param newEntry new entry (overwrites any previous one with same tag) - * @return false if Dicom Element doesn't exist +/* + * \ brief replaces an already existing Dicom Element by a new one + * @ param newEntry new entry (overwrites any previous one with same tag) + * @ return false if Dicom Element doesn't exist */ -bool Dict::ReplaceEntry(DictEntry *newEntry) + + /* seems to be useless + +bool Dict::ReplaceEntry(DictEntry *newEntry) // seems to be useless { const TagKey &key = newEntry->GetKey(); if ( RemoveEntry(key) ) @@ -171,6 +178,7 @@ bool Dict::ReplaceEntry(DictEntry *newEntry) } return false; } +*/ /** * \brief removes an already existing Dicom Dictionary Entry, @@ -183,8 +191,8 @@ bool Dict::RemoveEntry(TagKey const &key) TagKeyHT::const_iterator it = KeyHt.find(key); if ( it != KeyHt.end() ) { - it->second->Unregister(); - KeyHt.erase(key); + it->second->Unregister(); // delete the entry + KeyHt.erase(key); // remove pointer from HTable return true; } @@ -215,9 +223,11 @@ void Dict::ClearEntry() // we assume all the pointed DictEntries are already cleaned-up // when we clean KeyHt. TagKeyHT::const_iterator it; + for(it = KeyHt.begin();it!=KeyHt.end();++it) - it->second->Unregister(); - KeyHt.clear(); + it->second->Unregister(); // delete the entry + KeyHt.clear(); // remove all the entries from HTable + } /** @@ -235,7 +245,7 @@ DictEntry *Dict::GetEntry(TagKey const &key) return it->second; } /** - * \brief Get the dictionary entry identified by it's "group" and "element") + * \brief Get the dictionary entry identified by its "group" and "element") * @param group Group number of the searched entry. * @param elem Element number of the searched entry. * @return the corresponding dictionary entry when existing, NULL otherwise @@ -289,6 +299,9 @@ DictEntry *Dict::GetNextEntry() */ void Dict::DoTheLoadingJob(std::ifstream &from) { + if (!from) + return; + uint16_t group; uint16_t elem; VRKey vr; @@ -296,16 +309,20 @@ void Dict::DoTheLoadingJob(std::ifstream &from) TagName name; DictEntry *newEntry; - while (!from.eof() && from) + while ( true ) { from >> std::hex; - from >> group; + from >> group; from >> elem; from >> vr; from >> vm; from >> std::ws; //remove white space std::getline(from, name); - + + if(from.eof()) { + break; + } + newEntry = DictEntry::New(group, elem, vr, vm, name); AddEntry(newEntry); newEntry->Delete(); @@ -322,19 +339,23 @@ void Dict::DoTheLoadingJob(std::ifstream &from) */ void Dict::Print(std::ostream &os, std::string const & ) { - os << "Dict file name : " << Filename << std::endl; + os << "Dict file name : [" << Filename << "]" << std::endl; std::ostringstream s; for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) - { + { +std::cout << tag->second->GetKey() << " " << tag->second->GetName() + << std::endl; s << "Entry : "; s << "(" << tag->second->GetKey() << ") = " << std::dec; s << tag->second->GetVR() << ", "; s << tag->second->GetVM() << ", "; s << tag->second->GetName() << "." << std::endl; + } os << s.str(); + } //-----------------------------------------------------------------------------