]> Creatis software - gdcm.git/blobdiff - src/gdcmDict.cxx
Remove useless accesses to the Dicom Dictionnary std::map
[gdcm.git] / src / gdcmDict.cxx
index 5744e79040aebb373879a1700c87bd1ee808de1b..6d20d5eb0ac5ed39b0fe8d6ff9ebaaf8f98c0ade 100644 (file)
@@ -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: 2006/04/11 16:03:26 $
+  Version:   $Revision: 1.84 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -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 )
    {
@@ -57,6 +57,8 @@ Dict::Dict(std::string const &filename)
    }
    else
    {
+      gdcmDebugMacro( "in Dict::Dict, DoTheLoadingJob filename =[" 
+                    << filename << "]" );
       DoTheLoadingJob(from);
       Filename = filename;
    }
@@ -74,7 +76,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 +128,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 +140,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 +151,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,16 +162,21 @@ 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)
+ /* seems to be useless
+bool Dict::ReplaceEntry(DictEntry *newEntry) // seems to be useless
 {
-   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;
 }
-
+*/
 /**
  * \brief  removes an already existing Dicom Dictionary Entry,
  *         identified by its Tag
@@ -180,7 +188,8 @@ bool Dict::RemoveEntry(TagKey const &key)
    TagKeyHT::const_iterator it = KeyHt.find(key);
    if ( it != KeyHt.end() ) 
    {
-      KeyHt.erase(key);
+      it->second->Unregister(); // delete the entry
+      KeyHt.erase(key);         // remove pointer from HTable
 
       return true;
    } 
@@ -210,12 +219,17 @@ void Dict::ClearEntry()
 {
    // we assume all the pointed DictEntries are already cleaned-up
    // when we clean KeyHt.
-   KeyHt.clear();
+   TagKeyHT::const_iterator it;
+
+   for(it = KeyHt.begin();it!=KeyHt.end();++it)
+      it->second->Unregister(); // delete the entry
+   KeyHt.clear();               // remove all the entries from HTable
+
 }
 
 /**
  * \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 +239,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 +255,7 @@ DictEntry *Dict::GetEntry(uint16_t group, uint16_t elem)
    {
       return 0;
    }
-   return &(it->second);
+   return it->second;
 }
 
 /**
@@ -247,7 +266,7 @@ DictEntry *Dict::GetFirstEntry()
 {
    ItKeyHt = KeyHt.begin();
    if ( ItKeyHt != KeyHt.end() )
-      return &(ItKeyHt->second);
+      return ItKeyHt->second;
    return NULL;
 }
 
@@ -262,7 +281,7 @@ DictEntry *Dict::GetNextEntry()
 
    ++ItKeyHt;
    if (ItKeyHt != KeyHt.end())
-      return &(ItKeyHt->second);
+      return ItKeyHt->second;
    return NULL;
 }
 
@@ -279,10 +298,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;
@@ -292,9 +312,10 @@ void Dict::DoTheLoadingJob(std::ifstream &from)
       from >> vm;
       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();
 }
@@ -308,20 +329,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 << "(" << 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();
+
 }
 
 //-----------------------------------------------------------------------------