]> Creatis software - gdcm.git/blobdiff - src/gdcmDict.cxx
Removal of useless and dangerous methods :
[gdcm.git] / src / gdcmDict.cxx
index ffcd2dc7efbc718453163eb409b24c38bad408e8..8887d8b21d6d9ce79deb9cf5e84f395d1506938d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/27 22:47:20 $
-  Version:   $Revision: 1.49 $
+  Date:      $Date: 2005/01/06 20:03:27 $
+  Version:   $Revision: 1.54 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 namespace gdcm 
 {
-
+void FillDefaultDataDict(Dict *d);
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 /**
- * \brief   Construtor
+ * \brief   Constructor
  * @param   filename from which to build the dictionary.
  */
-Dict::Dict(std::string const & filename)
+Dict::Dict(std::string const &filename)
 {
    uint16_t group;
    uint16_t element;
@@ -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;
 }
 
 /**
@@ -117,7 +123,7 @@ void Dict::PrintByKey(std::ostream &os)
  *                           unpredictable result
  * @param   os The output stream to be written to.
  */
-void Dict::PrintByName(std::ostreamos)
+void Dict::PrintByName(std::ostream &os)
 {
    std::ostringstream s;
 
@@ -142,9 +148,9 @@ void Dict::PrintByName(std::ostream& os)
  * @param   newEntry entry to add 
  * @return  false if Dicom Element already exists
  */
-bool Dict::AddNewEntry(DictEntry const & newEntry) 
+bool Dict::AddNewEntry(DictEntry const &newEntry) 
 {
-   const TagKey & key = newEntry.GetKey();
+   const TagKey &key = newEntry.GetKey();
 
    if(KeyHt.count(key) == 1)
    {
@@ -153,12 +159,8 @@ bool Dict::AddNewEntry(DictEntry const & newEntry)
    } 
    else 
    {
-      KeyHt.insert( 
-         TagKeyHT::value_type<TagKey, DictEntry>
-            (newEntry.GetKey(), 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;
    }
 }
@@ -169,16 +171,12 @@ bool Dict::AddNewEntry(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 const &newEntry)
 {
    if ( RemoveEntry(newEntry.GetKey()) )
    {
-      KeyHt.insert( 
-         TagKeyHT::value_type<TagKey, DictEntry>
-            (newEntry.GetKey(), 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;
@@ -191,12 +189,12 @@ bool Dict::ReplaceEntry(DictEntry const & newEntry)
  * @param   key (group|element)
  * @return  false if Dicom Dictionary Entry doesn't exist
  */
-bool Dict::RemoveEntry (TagKey const & key) 
+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);
 
@@ -213,12 +211,12 @@ bool Dict::RemoveEntry (TagKey const & key)
  * \brief  removes an already existing Dicom Dictionary Entry, 
  *          identified by its group,element number
  * @param   group   Dicom group number of the Dicom Element
- * @param   element Dicom element number of the Dicom Element
+ * @param   elem Dicom element number of the Dicom Element
  * @return  false if Dicom Dictionary Entry doesn't exist
  */
-bool Dict::RemoveEntry (uint16_t group, uint16_t element)
+bool Dict::RemoveEntry (uint16_t group, uint16_t elem)
 {
-   return RemoveEntry(DictEntry::TranslateToKey(group, element));
+   return RemoveEntry(DictEntry::TranslateToKey(group, elem));
 }
 
 /**
@@ -229,7 +227,7 @@ bool Dict::RemoveEntry (uint16_t group, uint16_t element)
  *            the name MAY CHANGE between two versions !
  * @return  the corresponding dictionnary entry when existing, NULL otherwise
  */
-DictEntry* Dict::GetDictEntryByName(TagName const & name)
+DictEntry *Dict::GetDictEntryByName(TagName const &name)
 {
    TagNameHT::iterator it = NameHt.find(name);
    if ( it == NameHt.end() )
@@ -245,7 +243,7 @@ DictEntry* Dict::GetDictEntryByName(TagName const & name)
  * @param   element element of the entry to be found
  * @return  the corresponding dictionnary entry when existing, NULL otherwise
  */
-DictEntryDict::GetDictEntryByNumber(uint16_t group, uint16_t element)
+DictEntry *Dict::GetDictEntryByNumber(uint16_t group, uint16_t element)
 {
    TagKey key = DictEntry::TranslateToKey(group, element);
    TagKeyHT::iterator it = KeyHt.find(key);
@@ -262,7 +260,7 @@ DictEntry* Dict::GetDictEntryByNumber(uint16_t group, uint16_t element)
  * \sa      DictSet::GetPubDictTagNamesByCategory
  * @return  A list of all entries of the public dicom dictionnary.
  */
-EntryNamesListDict::GetDictEntryNames() 
+EntryNamesList *Dict::GetDictEntryNames() 
 {
    EntryNamesList *result = new EntryNamesList;
    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)