]> Creatis software - gdcm.git/blobdiff - src/gdcmElementSet.cxx
ENH: Move the old setup.py to its new home
[gdcm.git] / src / gdcmElementSet.cxx
index 067896c88174593582f86f7b64d9fcdf82bf4e86..d071067ca02daf98552b910b5bfcb3f24069e691 100644 (file)
@@ -1,8 +1,26 @@
-// gdcmElementSet.cxx
-//-----------------------------------------------------------------------------
-//
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmElementSet.cxx,v $
+  Language:  C++
+  Date:      $Date: 2004/09/27 08:39:07 $
+  Version:   $Revision: 1.23 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+
 #include "gdcmElementSet.h"
 #include "gdcmDebug.h"
+#include "gdcmValEntry.h"
+#include "gdcmBinEntry.h"
+#include "gdcmSeqEntry.h"
 
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
  * \ingroup gdcmElementSet
  * \brief   Constructor from a given gdcmElementSet
  */
-gdcmElementSet::gdcmElementSet() {
-   //TagDocEntryHT tagHT est un champ de gdcmElementSet.
-   // inutile de faire new ?
-      
+//BOZ depthLevel is not usefull anymore
+gdcmElementSet::gdcmElementSet(int depthLevel) 
+              : gdcmDocEntrySet()
+{
+  (void)depthLevel;
 }
 
 /**
@@ -22,52 +41,119 @@ gdcmElementSet::gdcmElementSet() {
  */
 gdcmElementSet::~gdcmElementSet() 
 {
-  gdcmDocEntry* EntryToDelete;  
-  for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc)
+  for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
    {
-      EntryToDelete = cc->second;
-      if ( EntryToDelete )
-         delete EntryToDelete;  // TODO : a verifier
+      gdcmDocEntry* entryToDelete = cc->second;
+      if ( entryToDelete )
+      {
+         delete entryToDelete;
+      }
    }
-   tagHT.clear();
+   TagHT.clear();
 }
 
 
 //-----------------------------------------------------------------------------
 // Public
 
-bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
-   TagKey key;
-   key = NewEntry->GetKey();
 
-   if(tagHT.count(key) == 1)
+//-----------------------------------------------------------------------------
+// Print
+/**
+  * \brief   Prints the Header Entries (Dicom Elements)
+  *          from the H Table
+  * @return
+  */ 
+void gdcmElementSet::Print(std::ostream& os)
+{
+   for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
+   {
+      gdcmDocEntry* entry = i->second;
+      entry->Print(os);   
+      if ( gdcmSeqEntry* seqEntry = dynamic_cast<gdcmSeqEntry*>(entry) )
+      {
+         (void)seqEntry;
+         // Avoid the newline for a sequence:
+         continue;
+      }
+      os << std::endl;
+   }
+}
+
+/**
+  * \brief   Writes the Header Entries (Dicom Elements)
+  *          from the H Table
+  * @return
+  */ 
+void gdcmElementSet::Write(FILE* fp, FileType filetype)
+{
+   for (TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
    {
-      dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ", key.c_str());
+      i->second->Write(fp, filetype);
+   } 
+}
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Private
+
+/**
+ * \brief   add a new Dicom Element pointer to the H Table
+ * @param   newEntry entry to add
+ */
+bool gdcmElementSet::AddEntry( gdcmDocEntry* newEntry)
+{
+   gdcmTagKey key = newEntry->GetKey();
+
+   if( TagHT.count(key) == 1 )
+   {
+      dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
+                  key.c_str());
       return(false);
    } 
    else 
    {
-      tagHT[NewEntry->GetKey()] = NewEntry;
-      return(true);
+      TagHT[newEntry->GetKey()] = newEntry;
+      return true;
    }   
 }
 
-// end-user intended : the guy *wants* to create his own SeQuence ?!?
-gdcmDocEntry *gdcmElementSet::NewDocEntryByNumber(guint16 group,
-                                                  guint16 element) {
-// TODO                                  
-   gdcmDocEntry *a;   
-   return a;                             
-}
+/**
+ * \brief   Clear the hash table from given entry BUT keep the entry.
+ * @param   entryToRemove Entry to remove.
+ */
+bool gdcmElementSet::RemoveEntryNoDestroy( gdcmDocEntry* entryToRemove)
+{
+   gdcmTagKey key = entryToRemove->GetKey();
+   if( TagHT.count(key) == 1 )
+   {
+      TagHT.erase(key);
+      dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
+      return true;
+   }
 
-gdcmDocEntry *gdcmElementSet::NewDocEntryByName  (std::string Name) {
-// TODO        :                         
-   gdcmDocEntry *a;   
-   return a;
+   dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
+   return false ;
 }
 
-//-----------------------------------------------------------------------------
-// Protected
+/**
+ * \brief   Clear the hash table from given entry AND delete the entry.
+ * @param   entryToRemove Entry to remove AND delete.
+ */
+bool gdcmElementSet::RemoveEntry( gdcmDocEntry* entryToRemove)
+{
+   gdcmTagKey key = entryToRemove->GetKey();
+   if( TagHT.count(key) == 1 )
+   {
+      TagHT.erase(key);
+      dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
+      delete entryToRemove;
+      return true;
+   }
 
-//-----------------------------------------------------------------------------
-// Private
+   dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
+   return false ;
+}