X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDict.cxx;h=845114d235816d3fd7a8badef24a73ee3899207d;hb=692c278613503559a7e64e475374f3e06f6da257;hp=5744e79040aebb373879a1700c87bd1ee808de1b;hpb=67aacdcd9af99ca00b8333adaac5057d95912bff;p=gdcm.git diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 5744e790..845114d2 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/09/02 07:00:04 $ - Version: $Revision: 1.79 $ + Date: $Date: 2005/10/23 15:32:30 $ + Version: $Revision: 1.82 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -74,7 +74,7 @@ Dict::~Dict() // Public /** - * \brief Add a all the entries held in a source dictionary + * \brief Add all the entries held in a source dictionary * \note it concerns only Private Dictionnary * @param filename from which to build the dictionary. */ @@ -126,7 +126,7 @@ bool Dict::RemoveDict(std::string const &filename) // from >> std::ws; //remove white space std::getline(from, name); - RemoveEntry(DictEntry::TranslateToKey(group, elem)); + RemoveEntry(group,elem); } from.close(); return true; @@ -138,9 +138,9 @@ bool Dict::RemoveDict(std::string const &filename) * @param newEntry entry to add * @return false if Dicom Element already exists */ -bool Dict::AddEntry(DictEntry const &newEntry) +bool Dict::AddEntry(DictEntry *newEntry) { - const TagKey &key = newEntry.GetKey(); + const TagKey &key = newEntry->GetKey(); if ( KeyHt.count(key) == 1 ) { @@ -149,7 +149,8 @@ bool Dict::AddEntry(DictEntry const &newEntry) } else { - KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry)); + newEntry->Register(); + KeyHt.insert( TagKeyHT::value_type(key, newEntry)); return true; } } @@ -159,12 +160,14 @@ bool Dict::AddEntry(DictEntry const &newEntry) * @param newEntry new entry (overwrites any previous one with same tag) * @return false if Dicom Element doesn't exist */ -bool Dict::ReplaceEntry(DictEntry const &newEntry) +bool Dict::ReplaceEntry(DictEntry *newEntry) { - if ( RemoveEntry(newEntry.GetKey()) ) + const TagKey &key = newEntry->GetKey(); + if ( RemoveEntry(key) ) { - KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry)); - return true; + newEntry->Register(); + KeyHt.insert( TagKeyHT::value_type(key, newEntry)); + return true; } return false; } @@ -180,6 +183,7 @@ bool Dict::RemoveEntry(TagKey const &key) TagKeyHT::const_iterator it = KeyHt.find(key); if ( it != KeyHt.end() ) { + it->second->Unregister(); KeyHt.erase(key); return true; @@ -210,12 +214,15 @@ 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(); } /** * \brief Get the dictionary entry identified by a given tag ("group|element") - * @param key tag of the entry to be found + * @param key tag of the searched entry * @return the corresponding dictionary entry when existing, NULL otherwise */ DictEntry *Dict::GetEntry(TagKey const &key) @@ -225,9 +232,14 @@ DictEntry *Dict::GetEntry(TagKey const &key) { return 0; } - return &(it->second); + return it->second; } - +/** + * \brief Get the dictionary entry identified by it's "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 + */ DictEntry *Dict::GetEntry(uint16_t group, uint16_t elem) { TagKey key = DictEntry::TranslateToKey(group, elem); @@ -236,7 +248,7 @@ DictEntry *Dict::GetEntry(uint16_t group, uint16_t elem) { return 0; } - return &(it->second); + return it->second; } /** @@ -247,7 +259,7 @@ DictEntry *Dict::GetFirstEntry() { ItKeyHt = KeyHt.begin(); if ( ItKeyHt != KeyHt.end() ) - return &(ItKeyHt->second); + return ItKeyHt->second; return NULL; } @@ -262,7 +274,7 @@ DictEntry *Dict::GetNextEntry() ++ItKeyHt; if (ItKeyHt != KeyHt.end()) - return &(ItKeyHt->second); + return ItKeyHt->second; return NULL; } @@ -279,10 +291,11 @@ void Dict::DoTheLoadingJob(std::ifstream &from) { uint16_t group; uint16_t elem; - TagName vr; + VRKey vr; TagName vm; TagName name; + DictEntry *newEntry; while (!from.eof() && from) { from >> std::hex; @@ -293,8 +306,9 @@ void Dict::DoTheLoadingJob(std::ifstream &from) from >> std::ws; //remove white space std::getline(from, name); - const DictEntry newEntry(group, elem, vr, vm, name); + newEntry = DictEntry::New(group, elem, vr, vm, name); AddEntry(newEntry); + newEntry->Delete(); } from.close(); } @@ -314,12 +328,11 @@ void Dict::Print(std::ostream &os, std::string const & ) for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) { s << "Entry : "; - s << "(" << std::hex << std::setw(4) << tag->second.GetGroup() << ','; - s << std::hex << std::setw(4) << tag->second.GetElement() << ") = " + s << "(" << tag->second->GetKey() << ") = " << std::dec; - s << tag->second.GetVR() << ", "; - s << tag->second.GetVM() << ", "; - s << tag->second.GetName() << "." << std::endl; + s << tag->second->GetVR() << ", "; + s << tag->second->GetVM() << ", "; + s << tag->second->GetName() << "." << std::endl; } os << s.str(); }