X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDict.cxx;h=1af0d6b5da07990c6b495ff6199187f8bd2ebf15;hb=779c8f5232ad160d353b90d3fa47d0503e17965d;hp=321f168a5de35e8a33e553d43d6070853264977d;hpb=1d9ac5cec02b9daa18b16835882b531731b125ad;p=gdcm.git diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 321f168a..1af0d6b5 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/18 12:58:27 $ - Version: $Revision: 1.80 $ + Date: $Date: 2005/11/05 13:25:26 $ + Version: $Revision: 1.83 $ 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; } @@ -283,6 +295,7 @@ void Dict::DoTheLoadingJob(std::ifstream &from) TagName vm; TagName name; + DictEntry *newEntry; while (!from.eof() && from) { from >> std::hex; @@ -292,9 +305,10 @@ void Dict::DoTheLoadingJob(std::ifstream &from) from >> vm; from >> std::ws; //remove white space std::getline(from, name); - - 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(); }