]> Creatis software - gdcm.git/blobdiff - src/gdcmDict.cxx
ENH: Slightly bigger patch:
[gdcm.git] / src / gdcmDict.cxx
index 01acd68d5f82eab8835e9ea16297fa258fc16fa6..19b9363999d81d478884c554acff33f6c60dc107 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/27 22:31:12 $
-  Version:   $Revision: 1.48 $
+  Date:      $Date: 2004/11/16 02:54:35 $
+  Version:   $Revision: 1.52 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -26,7 +26,7 @@
 
 namespace gdcm 
 {
-
+void FillDefaultDataDict(Dict *d);
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 /**
@@ -42,25 +42,31 @@ Dict::Dict(std::string const & filename)
    TagName name;
 
    std::ifstream from( filename.c_str() );
-   dbg.Error(!from, "Dict::Dict: can't open dictionary",
-                    filename.c_str());
-
-   while (!from.eof())
+   if( !from )
    {
-      from >> std::hex;
-      from >> group;
-      from >> element;
-      from >> vr;
-      from >> fourth;
-      from >> std::ws;  //remove white space
-      std::getline(from, name);
+      dbg.Verbose(2,"Dict::Dict: can't open dictionary", filename.c_str());
+      // Using default embeded one:
+      FillDefaultDataDict( this );
+   }
+   else
+   {
+      while (!from.eof())
+      {
+         from >> std::hex;
+         from >> group;
+         from >> element;
+         from >> vr;
+         from >> fourth;
+         from >> std::ws;  //remove white space
+         std::getline(from, name);
+   
+         const DictEntry newEntry(group, element, vr, fourth, name);
+         AddNewEntry(newEntry);
+      }
 
-      DictEntry newEntry(group, element, vr, fourth, name);
-      AddNewEntry(newEntry);
+      Filename = filename;
    }
    from.close();
-
-   Filename = filename;
 }
 
 /**
@@ -68,14 +74,6 @@ Dict::Dict(std::string const & filename)
  */
 Dict::~Dict()
 {
-/*   for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
-   {
-      DictEntry* entryToDelete = tag->second;
-      if ( entryToDelete )
-      {
-         delete entryToDelete;
-      }
-   }*/
    // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
    // assume all the pointed DictEntries are already cleaned-up when
    // we cleaned KeyHt.
@@ -161,14 +159,8 @@ bool Dict::AddNewEntry(DictEntry const & newEntry)
    } 
    else 
    {
-      //KeyHt[newEntry.GetKey()] = newEntry;
-      KeyHt.insert( 
-         TagKeyHT::value_type<TagKey, DictEntry>
-            (newEntry.GetKey(), newEntry));
-      //NameHt[newEntry.GetName()] = newEntry;
-      NameHt.insert(
-         TagNameHT::value_type<TagName, DictEntry>
-            (newEntry.GetName(), newEntry ));
+      KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry));
+      NameHt.insert( TagNameHT::value_type(newEntry.GetName(), newEntry ));
       return true;
    }
 }
@@ -183,14 +175,8 @@ bool Dict::ReplaceEntry(DictEntry const & newEntry)
 {
    if ( RemoveEntry(newEntry.GetKey()) )
    {
-      //KeyHt[newEntry.GetKey()] = newEntry;
-      KeyHt.insert( 
-         TagKeyHT::value_type<TagKey, DictEntry>
-            (newEntry.GetKey(), newEntry));
-      //NameHt[newEntry.GetName()] = newEntry;
-      NameHt.insert(
-         TagNameHT::value_type<TagName, DictEntry>
-            (newEntry.GetName(), newEntry ));
+       KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry));
+       NameHt.insert( TagNameHT::value_type(newEntry.GetName(), newEntry ));
        return true;
    } 
    return false;
@@ -208,7 +194,7 @@ bool Dict::RemoveEntry (TagKey const & key)
    TagKeyHT::const_iterator it = KeyHt.find(key);
    if(it != KeyHt.end()) 
    {
-      const DictEntry & entryToDelete = it->second;
+      const DictEntry& entryToDelete = it->second;
       NameHt.erase(entryToDelete.GetName());
       KeyHt.erase(key);
 
@@ -237,7 +223,7 @@ bool Dict::RemoveEntry (uint16_t group, uint16_t element)
  * \brief   Get the dictionnary entry identified by it's name.
  * @param   name element of the ElVal to modify
  * \warning : NEVER use it !
- *            the 'name' IS NOT an identifier within the Dicom Dicom Dictionary
+ *            the 'name' IS NOT an identifier within the Dicom Dictionary
  *            the name MAY CHANGE between two versions !
  * @return  the corresponding dictionnary entry when existing, NULL otherwise
  */