]> Creatis software - gdcm.git/commitdiff
* Change the DocEntry inheritance to RefCounter
authorregrain <regrain>
Mon, 24 Oct 2005 16:00:46 +0000 (16:00 +0000)
committerregrain <regrain>
Mon, 24 Oct 2005 16:00:46 +0000 (16:00 +0000)
   -- BeNours

18 files changed:
Testing/TestDataEntry.cxx
Testing/TestInline.cxx
src/gdcmDataEntry.h
src/gdcmDicomDir.cxx
src/gdcmDicomDirObject.cxx
src/gdcmDocEntry.h
src/gdcmDocEntryArchive.cxx
src/gdcmDocEntrySet.cxx
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmElementSet.cxx
src/gdcmElementSet.h
src/gdcmFile.cxx
src/gdcmFileHelper.cxx
src/gdcmSQItem.cxx
src/gdcmSQItem.h
src/gdcmSeqEntry.cxx
src/gdcmSeqEntry.h

index 73ad2d4c931d1075edece91e0e2556617fe39708..f0dc13f594b48e4c9727e351684bdaff91a08e53 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestDataEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/24 01:17:54 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2005/10/24 16:00:46 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -43,7 +43,7 @@ int TestDataEntry(int , char *[])
 
    //------------------------------------------------------------------
    dict = gdcm::DictEntry::New(0x0000,0x0000);
-   entry = new gdcm::DataEntry(dict);
+   entry = gdcm::DataEntry::New(dict);
    dict->SetVR("US");
 
    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
@@ -59,7 +59,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: 1" << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
 
@@ -74,7 +74,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: 2" << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
 
@@ -89,17 +89,17 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: 0" << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
 
    std::cout << std::endl;
    dict->Delete();
-   delete entry;
+   entry->Delete();
 
    //------------------------------------------------------------------
    dict = gdcm::DictEntry::New(0x0000,0x0000);
-   entry = new gdcm::DataEntry(dict);
+   entry = gdcm::DataEntry::New(dict);
    dict->SetVR("LT");
 
    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
@@ -114,7 +114,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetLength() 
                 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -124,7 +124,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
@@ -132,7 +132,7 @@ int TestDataEntry(int , char *[])
       std::cout << "   Failed" << std::endl
                 << "   Content of bin area is incorrect" << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
@@ -142,7 +142,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -154,18 +154,18 @@ int TestDataEntry(int , char *[])
                    << "   Found " << entry->GetValue(i)
                    << " - Must be " << svalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
 
    std::cout << std::endl;
    dict->Delete();
-   delete entry;
+   entry->Delete();
 
    //------------------------------------------------------------------
    dict = gdcm::DictEntry::New(0x0000,0x0000);
-   entry = new gdcm::DataEntry(dict);
+   entry = gdcm::DataEntry::New(dict);
    dict->SetVR("US");
 
    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
@@ -181,7 +181,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetLength()
                 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
@@ -191,7 +191,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -201,7 +201,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount()
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -213,7 +213,7 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << svalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
@@ -231,7 +231,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -241,7 +241,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -253,18 +253,18 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << svalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
 
    std::cout << std::endl;
    dict->Delete();
-   delete entry;
+   entry->Delete();
 
    //------------------------------------------------------------------
    dict = gdcm::DictEntry::New(0x0000,0x0000);
-   entry = new gdcm::DataEntry(dict);
+   entry = gdcm::DataEntry::New(dict);
    dict->SetVR("UL");
 
    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
@@ -280,7 +280,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetLength()
                 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
@@ -290,7 +290,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -300,7 +300,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -312,7 +312,7 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << lvalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
@@ -330,7 +330,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str() 
                 << " - Must be: " << data << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -340,7 +340,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -352,18 +352,18 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << lvalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
 
    std::cout << std::endl;
    dict->Delete();
-   delete entry;
+   entry->Delete();
 
    //------------------------------------------------------------------
    dict = gdcm::DictEntry::New(0x0000,0x0000);
-   entry = new gdcm::DataEntry(dict);
+   entry = gdcm::DataEntry::New(dict);
    dict->SetVR("FL");
 
    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
@@ -379,7 +379,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetLength() 
                 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
@@ -389,7 +389,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -399,7 +399,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -411,7 +411,7 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << fvalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
@@ -429,7 +429,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -439,7 +439,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -451,18 +451,18 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << fvalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
 
    std::cout << std::endl;
    dict->Delete();
-   delete entry;
+   entry->Delete();
 
    //------------------------------------------------------------------
    dict = gdcm::DictEntry::New(0x0000,0x0000);
-   entry = new gdcm::DataEntry(dict);
+   entry = gdcm::DataEntry::New(dict);
    dict->SetVR("FD");
 
    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
@@ -478,7 +478,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetLength()
                 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
@@ -488,7 +488,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -498,7 +498,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -512,7 +512,7 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << dvalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
@@ -530,7 +530,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    if( entry->GetValueCount() != nbvalue )
@@ -540,7 +540,7 @@ int TestDataEntry(int , char *[])
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
       dict->Delete();
-      delete entry;
+      entry->Delete();
       return 1;
    }
    for(i=0;i<entry->GetValueCount();i++)
@@ -552,14 +552,14 @@ int TestDataEntry(int , char *[])
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << dvalue[i] << std::endl;
          dict->Delete();
-         delete entry;
+         entry->Delete();
          return 1;
       }
    }
 
    std::cout << std::endl;
    dict->Delete();
-   delete entry;
+   entry->Delete();
 
    //------------------------------------------------------------------
    std::cout<<std::flush;
index 3b77056f727aa85f0c0c069bfa3371f4621fc760..27ad62ab5df633ebd1a31234c26136f573c876c6 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestInline.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/24 13:17:22 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2005/10/24 16:00:46 $
+  Version:   $Revision: 1.5 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -33,7 +33,7 @@
 #include "gdcmDebug.h"
 #include <iostream>
 
-#include <time.h>
+/*#include <time.h>
 #ifdef CMAKE_HAVE_SYS_TIMES_H
 #include <sys/times.h>
 #else
@@ -57,28 +57,6 @@ double     passDirect(double a,  double b);
 double     passRef(double &a, double &b);
 double     passPtr(double *a, double *b);
 
-/*  
-//To perform a full check, just put the two 'static' functions
-//hifpswap and  hNoifpswap in a .h
-
-   static inline void hifpswap(double *a, double *b)    
-   {
-      double tmp;
-      tmp = *a;
-      *a = *b;
-      *b = tmp;
-   }
-
-   static void hNoifpswap(double *a, double *b)    
-   {
-      double tmp;
-      tmp = *a;
-      *a = *b;
-      *b = tmp;
-   }
-    
-*/
-
 #define       \
 mswap(a, b)   \
 {             \
@@ -412,3 +390,9 @@ int TestInline(int argc, char *argv[])
 
    return 0;
 }
+*/
+
+int TestInline(int argc, char *argv[])
+{
+   return 0;
+}
index f8882df901ee27266ed7a7692e3782b6378b9272..d9e71a3a9d14552957b948e22cb4e9be63887bc5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDataEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/23 15:32:30 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.5 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -35,10 +35,11 @@ namespace gdcm
  */
 class GDCM_EXPORT DataEntry  : public DocEntry
 {
+   gdcmTypeMacro(DataEntry);
+
 public:
-   DataEntry(DictEntry *e);
-   DataEntry(DocEntry *d); 
-   ~DataEntry();
+   static DataEntry *New(DictEntry *e) {return new DataEntry(e);}
+   static DataEntry *New(DocEntry *d) {return new DataEntry(d);}
 
 // Print
    void Print(std::ostream &os = std::cout, std::string const &indent = "");
@@ -118,6 +119,10 @@ public:
    } TValueFlag;
 
 protected:
+   DataEntry(DictEntry *e);
+   DataEntry(DocEntry *d); 
+   ~DataEntry();
+
 // Methods :
    void NewBinArea(void);
    void DeleteBinArea(void);
index ee3fb0eb8709e330c88a5b5a5ed172ed8b0e1aab..f002e6f7ca0f174888cb41ba9c165f2ec073916d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/21 16:02:01 $
-  Version:   $Revision: 1.164 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.165 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -319,7 +319,7 @@ DicomDirMeta *DicomDir::NewMeta()
          if ( dynamic_cast<SeqEntry *>(entry) )
             break;
 
-         RemoveEntryNoDestroy(entry);
+         RemoveEntry(entry);
          MetaElems->AddEntry(entry);
 
          entry = GetFirstEntry();
@@ -737,6 +737,7 @@ void DicomDir::CreateDicomDir()
    //  3 - we find an other tag
    //       + we create the object for the precedent tag
    //       + loop to 1 -
+   gdcmDebugMacro("Create DicomDir");
 
    // Directory record sequence
    DocEntry *e = GetDocEntry(0x0004, 0x1220);
@@ -1092,7 +1093,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type,
       tmpEl     = it->Elem;
       dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
 
-      entry     = new DataEntry( dictEntry ); // Be sure it's never a DataEntry !
+      entry     = DataEntry::New( dictEntry ); // Be sure it's never a DataEntry !
 
       entry->SetOffset(0); // just to avoid further missprinting
 
@@ -1144,6 +1145,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type,
          gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
       }
       si->AddEntry(entry);
+      entry->Delete();
    }
 }
 
@@ -1160,7 +1162,7 @@ void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
    entry = src->GetFirstEntry();
    while(entry)
    {
-      src->RemoveEntryNoDestroy(entry);
+      src->RemoveEntry(entry);
       dst->AddEntry(entry);
       // we destroyed -> the current iterator is not longer valid
       entry = src->GetFirstEntry();
index e53002695e95d7ada673d7a48a5d0cdaa6d6e435..b287b7f7a62f06357126de346d8b675d780dabda 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirObject.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:49 $
-  Version:   $Revision: 1.21 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.22 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -67,11 +67,12 @@ void DicomDirObject::FillObject(ListDicomDirMetaElem const &elemList)
       tmpGr = it->Group;
       tmpEl = it->Elem;
       dictEntry = Global::GetDicts()->GetDefaultPubDict()->GetEntry(tmpGr,tmpEl);
-      entry = new DataEntry(dictEntry);
+      entry = DataEntry::New(dictEntry);
       entry->SetOffset(0); // just to avoid further missprinting
       entry->SetString(it->Value);
 
       AddEntry(entry);
+      entry->Delete();
    }   
 }  
 
index 6791b02e20cf1edd4e72f4bb6ca06ddc7e460f7a..b779a89a5e54fb34d5e3ac723491a95a28665515 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/23 15:32:31 $
-  Version:   $Revision: 1.54 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.55 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -19,7 +19,7 @@
 #ifndef GDCMDOCENTRY_H
 #define GDCMDOCENTRY_H
 
-#include "gdcmBase.h"
+#include "gdcmRefCounter.h"
 #include "gdcmDictEntry.h"
 
 #include <iostream>
@@ -35,12 +35,11 @@ class SeqEntry;
  * \brief   The dicom header of a Dicom file contains a set of such entries
  *          (when successfuly parsed against a given Dicom dictionary)
  */
-class GDCM_EXPORT DocEntry : public Base
+class GDCM_EXPORT DocEntry : public RefCounter
 {
-public:
-   DocEntry(DictEntry*);
-   virtual ~DocEntry();
+   gdcmTypeMacro(DocEntry);
 
+public:
    virtual void Print (std::ostream &os = std::cout, std::string const &indent = ""); 
    virtual void WriteContent(std::ofstream *fp, FileType filetype);
 
@@ -126,6 +125,9 @@ public:
    virtual void Copy(DocEntry *e);
 
 protected:
+   DocEntry(DictEntry*);
+   virtual ~DocEntry();
+
    /// \brief pointer to the underlying Dicom dictionary element
    DictEntry *DicomDict;
    
index 0e9b2d5366c51b29dcfb816edc2581f824ed8bb3..c82a1e96c2c779a8010788813bf56c45468b87b5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntryArchive.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/11 14:40:40 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -66,7 +66,10 @@ bool DocEntryArchive::Push(DocEntry *newEntry)
       DocEntry *old = ArchFile->GetDocEntry(group, elem);
       Archive[key]  = old;
       if ( old )
-         ArchFile->RemoveEntryNoDestroy(old);
+      {
+         old->Register();
+         ArchFile->RemoveEntry(old);
+      }
 
       // Set the new DocEntry
       ArchFile->AddEntry(newEntry);
@@ -94,7 +97,10 @@ bool DocEntryArchive::Push(uint16_t group, uint16_t elem)
       DocEntry *old = ArchFile->GetDocEntry(group, elem);
       Archive[key] = old;
       if ( old )
-         ArchFile->RemoveEntryNoDestroy(old);
+      {
+         old->Register();
+         ArchFile->RemoveEntry(old);
+      }
 
       return true;
    }
@@ -119,11 +125,16 @@ bool DocEntryArchive::Restore(uint16_t group, uint16_t elem)
       // Delete the new value
       DocEntry *rem = ArchFile->GetDocEntry(group, elem);
       if ( rem )
+      {
          ArchFile->RemoveEntry(rem);
+      }
 
       // Restore the old value
-      if ( Archive[key] )
-         ArchFile->AddEntry(Archive[key]);
+      if ( restoreIt->second )
+      {
+         ArchFile->AddEntry(restoreIt->second);
+         restoreIt->second->Unregister();
+      }
 
       Archive.erase(restoreIt);
 
@@ -142,7 +153,8 @@ void DocEntryArchive::ClearArchive( )
        it!=Archive.end();
        ++it)
    {
-      delete it->second;
+      if(it->second)
+         it->second->Unregister();
    }
    Archive.clear();
 }
index b3cfe401bd19af2ab6a7e46bc9f8a6e73a96e90f..cc91b75fd8ce796120041c6886c125405292e2d8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/21 10:48:16 $
-  Version:   $Revision: 1.64 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.65 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -287,7 +287,7 @@ DataEntry *DocEntrySet::InsertEntryString(std::string const &value,
       {
          gdcmWarningMacro("AddEntry failed although this is a creation.");
 
-         delete dataEntry;
+         dataEntry->Delete();
          return NULL;
       }
    }
@@ -346,7 +346,7 @@ DataEntry *DocEntrySet::InsertEntryBinArea(uint8_t *binArea, int lgth,
       {
          gdcmWarningMacro( "AddEntry failed although this is a creation.");
 
-         delete dataEntry;
+         dataEntry->Delete();
          return NULL;
       }
    }
@@ -415,7 +415,7 @@ SeqEntry *DocEntrySet::InsertSeqEntry(uint16_t group, uint16_t elem)
       {
          gdcmWarningMacro( "AddEntry failed although this is a creation.");
 
-         delete seqEntry;
+         seqEntry->Delete();
          return NULL;
       }
    }
@@ -443,13 +443,14 @@ bool DocEntrySet::CheckIfEntryExist(uint16_t group, uint16_t elem )
  * @param   group Group number   of the new Entry
  * @param   elem  Element number of the new Entry
  * @param   vr    V(alue) R(epresentation) of the new Entry 
+ * \remarks The user of this method must destroy the DataEntry when unused
  */
 DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem,
                                      VRKey const &vr) 
 {
    DictEntry *dictEntry = GetDictEntry(group, elem, vr);
 
-   DataEntry *newEntry = new DataEntry(dictEntry);
+   DataEntry *newEntry = DataEntry::New(dictEntry);
    dictEntry->Unregister(); // GetDictEntry register it
    if (!newEntry) 
    {
@@ -465,12 +466,13 @@ DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem,
  *          a default one when absent.
  * @param   group Group   number of the new Entry
  * @param   elem  Element number of the new Entry
+ * \remarks The user of this method must destroy the SeqEntry when unused
  */
 SeqEntry* DocEntrySet::NewSeqEntry(uint16_t group, uint16_t elem) 
 {
    DictEntry *dictEntry = GetDictEntry(group, elem, "SQ");
 
-   SeqEntry *newEntry = new SeqEntry( dictEntry );
+   SeqEntry *newEntry = SeqEntry::New( dictEntry );
    dictEntry->Unregister(); // GetDictEntry register it
    if (!newEntry)
    {
index 0173958a015a6c936bbd18374775808ace0e646d..3448c892f9db5646269541c7b19a21d077d556ad 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/20 15:24:09 $
-  Version:   $Revision: 1.60 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.61 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -73,8 +73,6 @@ public:
    virtual bool AddEntry(DocEntry *entry) = 0;
    /// \brief Removes any type of entry out of the entry set, and destroys it
    virtual bool RemoveEntry(DocEntry *entryToRemove) = 0;
-   /// \brief Removes any type of entry out of the entry set, DOESN'T destroy it
-   virtual bool RemoveEntryNoDestroy(DocEntry *entryToRemove) = 0;
    /// Gets the first entry of any type of set
    virtual DocEntry *GetFirstEntry()=0;
    /// Gets the next entry of any type of set
index d4410d1b47a6ca947374137ca51b9c5e360ebba2..665604a2996f5f997ac008d2cfdf8e8b4db89cca 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/23 15:28:26 $
-  Version:   $Revision: 1.303 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.304 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1057,7 +1057,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
                (!delim_mode && ((long)(Fp->tellg())-offset) >= l_max) )
          {
             if ( !used )
-               delete newDocEntry;
+               newDocEntry->Delete();
             break;
          }
 
@@ -1087,7 +1087,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
             if ( newDocEntry->GetGroup()%2 != 0 )
             {
                 Fp->seekg( l, std::ios::cur);
-                delete newDocEntry;  // Delete, not in the set 
+                newDocEntry->Delete();  // Delete, not in the set 
                 continue;  
             } 
          } 
@@ -1095,7 +1095,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          {
            // User asked to skip *any* SeQuence
             Fp->seekg( l, std::ios::cur);
-            delete newDocEntry; // Delete, not in the set
+            newDocEntry->Delete(); // Delete, not in the set
             continue;
          }
          // delay the dynamic cast as late as possible
@@ -1148,14 +1148,14 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
          {
             if ( !used )
-               delete newDocEntry;  
+               newDocEntry->Delete();
                break;
          }
       }  // end SeqEntry : VR = "SQ"
 
       if ( !used )
       {
-         delete newDocEntry;
+         newDocEntry->Delete();
       }
       first = false;
    }                               // end While
@@ -1194,7 +1194,7 @@ void Document::ParseSQ( SeqEntry *seqEntry,
       }
       if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
       {
-         delete newDocEntry;
+         newDocEntry->Delete();
          break;
       }
       // create the current SQItem
@@ -1212,7 +1212,7 @@ void Document::ParseSQ( SeqEntry *seqEntry,
 
       // Let's try :------------
       // remove fff0,e000, created out of the SQItem
-      delete newDocEntry;
+      newDocEntry->Delete();
       Fp->seekg(offsetStartCurrentSQItem, std::ios::beg);
       // fill up the current SQItem, starting at the beginning of fff0,e000
 
@@ -1240,7 +1240,7 @@ DocEntry *Document::Backtrack(DocEntry *docEntry)
 {
    // delete the Item Starter, built erroneously out of any Sequence
    // it's not yet in the HTable/chained list
-   delete docEntry;
+   docEntry->Delete();
 
    // Get all info we can from PreviousDocEntry
    uint16_t group = PreviousDocEntry->GetGroup();
@@ -2012,7 +2012,7 @@ DocEntry *Document::ReadNextDocEntry()
    catch ( FormatError )
    {
       // Call it quits
-      delete newEntry;
+      newEntry->Delete();
       return 0;
    }
 
index 215589b811bd10ac6c4c3e2b29101ae0e8bd2916..6f1d984071ee71bcb01c84b97a2a04c75ad88073 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 09:17:08 $
-  Version:   $Revision: 1.66 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.67 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -75,6 +75,7 @@ bool ElementSet::AddEntry(DocEntry *newEntry)
    else
    {
       TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
+      newEntry->Register();
       return true;
    }
 }
@@ -89,8 +90,7 @@ bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
    if ( TagHT.count(key) == 1 )
    {
       TagHT.erase(key);
-      //gdcmWarningMacro( "One element erased.");
-      delete entryToRemove;
+      entryToRemove->Unregister();
       return true;
    }
 
@@ -98,24 +98,6 @@ bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
    return false ;
 }
 
-/**
- * \brief   Clear the hash table from given entry BUT keep the entry.
- * @param   entryToRemove Entry to remove.
- */
-bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
-{
-   const TagKey &key = entryToRemove->GetKey();
-   if ( TagHT.count(key) == 1 )
-   {
-      TagHT.erase(key);
-      //gdcmWarningMacro( "One element erased.");
-      return true;
-   }
-
-   gdcmWarningMacro( "Key not present " << key);
-   return false ;
-}
-
 /**
  * \brief   delete all entries in the ElementSet
  */
@@ -125,7 +107,7 @@ void ElementSet::ClearEntry()
    {
       if ( cc->second )
       {
-         delete cc->second;
+         cc->second->Unregister();
       }
    }
    TagHT.clear();
index fdcb3d0a04f87c4c4d4b63022ea6e384c75ed99b..d924c6e867ed2106d94a46d2f5c0667e5c622116 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 09:17:08 $
-  Version:   $Revision: 1.47 $
+  Date:      $Date: 2005/10/24 16:00:47 $
+  Version:   $Revision: 1.48 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -52,7 +52,6 @@ public:
 
    bool AddEntry(DocEntry *Entry);
    bool RemoveEntry(DocEntry *EntryToRemove);
-   bool RemoveEntryNoDestroy(DocEntry *EntryToRemove);
    void ClearEntry();
    
    DocEntry *GetFirstEntry();
index b26c57d831b59495ceb2d1c672dbccbe757b29c4..189987accea4fe82f10ee617dc004136775a3ac2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/23 15:26:43 $
-  Version:   $Revision: 1.289 $
+  Date:      $Date: 2005/10/24 16:00:48 $
+  Version:   $Revision: 1.290 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -233,7 +233,7 @@ bool File::DoTheLoadingJob( )
             DictEntry* newDict = DictEntry::New(GrPixel,NumPixel,
                                                 PixelVR,"1","Pixel Data");
 
-            DataEntry *newEntry = new DataEntry(newDict);
+            DataEntry *newEntry = DataEntry::New(newDict);
             newDict->Delete();
             newEntry->Copy(entry);
             newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea());
@@ -241,6 +241,7 @@ bool File::DoTheLoadingJob( )
 
             RemoveEntry(oldEntry);
             AddEntry(newEntry);
+            newEntry->Delete();
          }
       }
    }
@@ -630,7 +631,7 @@ float File::GetXOrigin()
 
    if( entry->GetValueCount() == 3 )
    {
-      gdcmAssertMacro( entry->IsValueCountValid() );
+      gdcmErrorMacro( entry->IsValueCountValid() );
       return (float)entry->GetValue(0);
    }
    return 0.0f;
@@ -658,7 +659,7 @@ float File::GetYOrigin()
 
    if( entry->GetValueCount() == 3 )
    {
-      gdcmAssertMacro( entry->IsValueCountValid() );
+      gdcmErrorMacro( entry->IsValueCountValid() );
       return (float)entry->GetValue(1);
    }
    return 0.0f;
@@ -679,7 +680,7 @@ float File::GetZOrigin()
    {
       if( entry->GetValueCount() == 3 )
       {
-         gdcmAssertMacro( entry->IsValueCountValid() );
+         gdcmErrorMacro( entry->IsValueCountValid() );
          return (float)entry->GetValue(2);
       }
       gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)");
@@ -691,7 +692,7 @@ float File::GetZOrigin()
    {
       if( entry->GetValueCount() == 3 )
       {
-         gdcmAssertMacro( entry->IsValueCountValid() );
+         gdcmErrorMacro( entry->IsValueCountValid() );
          return (float)entry->GetValue(2);
       }
       gdcmWarningMacro( "Wrong Image Position (RET) (0020,0030)");
@@ -704,7 +705,7 @@ float File::GetZOrigin()
    {
       if( entry->GetValueCount() == 1 )
       {
-         gdcmAssertMacro( entry->IsValueCountValid() );
+         gdcmErrorMacro( entry->IsValueCountValid() );
          return (float)entry->GetValue(0); // VM=1 !
       }
       gdcmWarningMacro( "Wrong Slice Location (0020,1041)");
@@ -716,7 +717,7 @@ float File::GetZOrigin()
    {
       if( entry->GetValueCount() == 1 )
       {
-         gdcmAssertMacro( entry->IsValueCountValid() );
+         gdcmErrorMacro( entry->IsValueCountValid() );
          return (float)entry->GetValue(0);
       }
       gdcmWarningMacro( "Wrong Location (0020,0050)");
index e014d45510db3ae4c4e3cd94faddb77789499838..51d66886d649b81cd7e9e429502e9b79e0c27778 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2005/10/23 15:24:47 $
-  Version:   $Revision: 1.69 $
+  Date:      $Date: 2005/10/24 16:00:48 $
+  Version:   $Revision: 1.70 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -100,7 +100,7 @@ fh1->Write(newFileName);
    fp = opens file(fileName);
    ComputeGroup0002Length( );
    BitsAllocated 12->16
-      RemoveEntryNoDestroy(palettes, etc)
+      RemoveEntry(palettes, etc)
       Document::WriteContent(fp, writetype);
    RestoreWrite();
       (moves back to the File all the archived elements)
@@ -865,6 +865,9 @@ void FileHelper::SetWriteToRaw()
 
       Archive->Push(photInt);
       Archive->Push(pixel);
+
+      photInt->Delete();
+      pixel->Delete();
    }
 }
 
@@ -917,6 +920,11 @@ void FileHelper::SetWriteToRGB()
       Archive->Push(photInt);
       Archive->Push(pixel);
 
+      spp->Delete();
+      planConfig->Delete();
+      photInt->Delete();
+      pixel->Delete();
+
       // Remove any LUT
       Archive->Push(0x0028,0x1101);
       Archive->Push(0x0028,0x1102);
@@ -945,6 +953,10 @@ void FileHelper::SetWriteToRGB()
          Archive->Push(bitsAlloc);
          Archive->Push(bitsStored);
          Archive->Push(highBit);
+
+         bitsAlloc->Delete();
+         bitsStored->Delete();
+         highBit->Delete();
       }
    }
    else
@@ -1026,6 +1038,7 @@ void FileHelper::SetWriteFileTypeToJPEG()
    tss->SetString(ts);
 
    Archive->Push(tss);
+   tss->Delete();
 }
 
 void FileHelper::SetWriteFileTypeToExplicitVR()
@@ -1037,6 +1050,7 @@ void FileHelper::SetWriteFileTypeToExplicitVR()
    tss->SetString(ts);
 
    Archive->Push(tss);
+   tss->Delete();
 }
 
 /**
@@ -1051,6 +1065,7 @@ void FileHelper::SetWriteFileTypeToImplicitVR()
    tss->SetString(ts);
 
    Archive->Push(tss);
+   tss->Delete();
 }
 
 
@@ -1073,8 +1088,8 @@ void FileHelper::SetWriteToLibido()
    {
       std::string rows, columns; 
 
-      DataEntry *newRow=new DataEntry(oldRow->GetDictEntry());
-      DataEntry *newCol=new DataEntry(oldCol->GetDictEntry());
+      DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry());
+      DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry());
 
       newRow->Copy(oldCol);
       newCol->Copy(oldRow);
@@ -1084,11 +1099,15 @@ void FileHelper::SetWriteToLibido()
 
       Archive->Push(newRow);
       Archive->Push(newCol);
+
+      newRow->Delete();
+      newCol->Delete();
    }
 
    DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
    libidoCode->SetString("ACRNEMA_LIBIDO_1.1");
    Archive->Push(libidoCode);
+   libidoCode->Delete();
 }
 
 /**
@@ -1104,6 +1123,7 @@ void FileHelper::SetWriteToNoLibido()
          DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
          libidoCode->SetString("");
          Archive->Push(libidoCode);
+         libidoCode->Delete();
       }
    }
 }
@@ -1144,7 +1164,7 @@ DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem,
 
    if ( oldE )
    {
-      newE = new DataEntry(oldE->GetDictEntry());
+      newE = DataEntry::New(oldE->GetDictEntry());
       newE->Copy(oldE);
    }
    else
@@ -1288,19 +1308,19 @@ void FileHelper::CheckMandatoryElements()
    if ( e_0008_0016 )
    {
       // Create 'Source Image Sequence' SeqEntry
-      SeqEntry *sis = new SeqEntry (
+      SeqEntry *sis = SeqEntry::New (
             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
       SQItem *sqi = new SQItem(1);
       // (we assume 'SOP Instance UID' exists too) 
       // create 'Referenced SOP Class UID'
-      DataEntry *e_0008_1150 = new DataEntry(
+      DataEntry *e_0008_1150 = DataEntry::New(
             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
       e_0008_1150->SetString( e_0008_0016->GetString());
       sqi->AddEntry(e_0008_1150);
       
       // create 'Referenced SOP Instance UID'
       DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018);
-      DataEntry *e_0008_1155 = new DataEntry(
+      DataEntry *e_0008_1155 = DataEntry::New(
             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
       e_0008_1155->SetString( e_0008_0018->GetString());
       sqi->AddEntry(e_0008_1155);
@@ -1308,6 +1328,7 @@ void FileHelper::CheckMandatoryElements()
       sis->AddSQItem(sqi,1); 
       // temporarily replaces any previous 'Source Image Sequence' 
       Archive->Push(sis);
+      sis->Delete();
  
       // 'Image Type' (The written image is no longer an 'ORIGINAL' one)
       CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY");
@@ -1399,17 +1420,19 @@ void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string va
    DataEntry *entry = FileInternal->GetDataEntry(group,elem);
    if ( !entry )
    {
-      entry = new DataEntry(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
+      entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
       entry->SetString(value);
       Archive->Push(entry);
+      entry->Delete();
    }
 }
 
 void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
 {
-   DataEntry *entry = new DataEntry(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
+   DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
    entry->SetString(value);
    Archive->Push(entry);
+   entry->Delete();
 }
 
 void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
@@ -1417,6 +1440,7 @@ void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string val
    DataEntry *entry = CopyDataEntry(group,elem);
    entry->SetString(value);
    Archive->Push(entry);
+   entry->Delete();
 }
 
 /**
@@ -1452,7 +1476,6 @@ void FileHelper::RestoreWriteMandatory()
 
    Archive->Restore(0x0020,0x000d);
    Archive->Restore(0x0020,0x000e);
-
 }
 
 //-----------------------------------------------------------------------------
index 0ed62981aeec4deb87fe99b01256ed36350abb12..7c8d61c6e5373241d79a2ecac1a420541bfbc4cf 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:50 $
-  Version:   $Revision: 1.76 $
+  Date:      $Date: 2005/10/24 16:00:48 $
+  Version:   $Revision: 1.77 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -110,6 +110,7 @@ bool SQItem::AddEntry(DocEntry *entry)
    if (DocEntries.empty() )
    {
       DocEntries.push_back(entry);
+      entry->Register();
       return true;
    }
  
@@ -131,9 +132,11 @@ bool SQItem::AddEntry(DocEntry *entry)
             break;
    } while (it != DocEntries.begin() );
   
-   insertSpot = it++;
-   insertSpot++; // ?!?
+   ++it;
+   insertSpot = it;
+   //++insertSpot; // ?!?
    DocEntries.insert(insertSpot, entry); 
+   entry->Register();
    return true;
 }   
 
@@ -152,7 +155,7 @@ bool SQItem::RemoveEntry( DocEntry *entryToRemove )
       {
          DocEntries.erase(it);
          gdcmWarningMacro( "One element erased: " << entryToRemove->GetKey() );
-         delete entryToRemove;
+         entryToRemove->Unregister();
          return true;
       }
    }
@@ -160,30 +163,6 @@ bool SQItem::RemoveEntry( DocEntry *entryToRemove )
    return false ;
 }
 
-/**
- * \brief   Clear the std::list from given entry BUT keep the entry.
- * @param   entryToRemove Entry to remove.
- * @return true if the entry was found and removed; false otherwise
- */
-bool SQItem::RemoveEntryNoDestroy(DocEntry *entryToRemove)
-{
-   for(ListDocEntry::iterator it =  DocEntries.begin();
-                              it != DocEntries.end();
-                            ++it)
-   {
-      if ( *it == entryToRemove )
-      {
-         DocEntries.erase(it);
-         gdcmWarningMacro( "One element removed, no destroyed: "
-                            << entryToRemove->GetKey() );
-         return true;
-      }
-   }
-                                                                                
-   gdcmWarningMacro( "Entry not found:" << entryToRemove->GetKey() );
-   return false ;
-}
-                                                                                
 /**
  * \brief  Remove all entry in the Sequence Item 
  */
@@ -193,27 +172,18 @@ void SQItem::ClearEntry()
                               cc != DocEntries.end();
                             ++cc)
    {
-      delete *cc;
+      (*cc)->Unregister();
    }
    DocEntries.clear();
 }
 
-/**
- * \brief  Clear the std::list from given Sequence Item  BUT keep the entries
- */
-void SQItem::ClearEntryNoDestroy()
-{
-   DocEntries.clear();
-}
-
-
 /**
  * \brief  Move all the entries from a given Sequence Item 
  */
 void SQItem::MoveObject(SQItem *source)
 {
    DocEntries = source->DocEntries;
-   source->ClearEntryNoDestroy();
+   source->DocEntries.clear();
 }
 
 /**
index 4dca0cff00baa92473ecab82833edda5afeb3033..42567308ea3d3fcd30d4d694814ab33ad9aa709f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:05 $
-  Version:   $Revision: 1.45 $
+  Date:      $Date: 2005/10/24 16:00:48 $
+  Version:   $Revision: 1.46 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -49,9 +49,7 @@ public:
 
    bool AddEntry(DocEntry *Entry); // add to the List
    bool RemoveEntry(DocEntry *EntryToRemove);
-   bool RemoveEntryNoDestroy(DocEntry *EntryToRemove);
    void ClearEntry();
-   void ClearEntryNoDestroy();
    void MoveObject(SQItem *source);
   
    DocEntry *GetFirstEntry();
index 0cfd3643ab4be942ce125f1382c6a07b0938b1ad..c0647f9ded94d166f1bcea0f79c146e0d725bd02 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:50 $
-  Version:   $Revision: 1.58 $
+  Date:      $Date: 2005/10/24 16:00:48 $
+  Version:   $Revision: 1.59 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -129,7 +129,7 @@ void SeqEntry::ClearSQItem()
    }
    if (SeqTerm)
    {
-      delete SeqTerm;
+      SeqTerm->Unregister();
    }
 }
 
@@ -195,6 +195,22 @@ unsigned int SeqEntry::GetNumberOfSQItems()
    return Items.size();
 }
 
+/**
+ * \brief Sets the Sequence Delimitation Item
+ * \param e Delimitation item
+ */
+void SeqEntry::SetDelimitationItem(DocEntry *e)
+{
+   if( SeqTerm != e )
+   {
+      if( SeqTerm )
+         SeqTerm->Unregister();
+      SeqTerm = e;
+      if( SeqTerm )
+         SeqTerm->Register();
+   }
+}
+
 //-----------------------------------------------------------------------------
 // Protected
 
index cae73c898a2b56a68c3760b6aa7fbd3cbc09bce4..7836f8c0afbe490bc47abebc07aa4a31938defbd 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:50 $
-  Version:   $Revision: 1.35 $
+  Date:      $Date: 2005/10/24 16:00:48 $
+  Version:   $Revision: 1.36 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -39,11 +39,12 @@ typedef std::list<SQItem *> ListSQItem;
  */ 
 class GDCM_EXPORT SeqEntry : public DocEntry 
 {
+   gdcmTypeMacro(SeqEntry);
+
 public:
-   SeqEntry( DictEntry *e);
-   SeqEntry( DocEntry *d, int depth );
-   ~SeqEntry();
-   
+   static SeqEntry *New(DictEntry *e) {return new SeqEntry(e);}
+   static SeqEntry *New(DocEntry *d, int depth) {return new SeqEntry(d,depth);}
+
    void Print(std::ostream &os = std::cout, std::string const &indent = "" ); 
    void WriteContent(std::ofstream *fp, FileType filetype);
 
@@ -57,8 +58,8 @@ public:
    /// Sets the delimitor mode
    void SetDelimitorMode(bool dm) { DelimitorMode = dm; }
 
-   /// Sets the Sequence Delimitation Item
-   void SetDelimitationItem(DocEntry *e) { SeqTerm = e;   }
+   
+   void SetDelimitationItem(DocEntry *e);
 
    /// Gets the Sequence Delimitation Item
    DocEntry *GetDelimitationItem()       { return SeqTerm;}
@@ -71,6 +72,10 @@ public:
 protected:
 
 private:
+   SeqEntry( DictEntry *e);
+   SeqEntry( DocEntry *d, int depth );
+   ~SeqEntry();
+
 // Variables
    /// If this Sequence is in delimitor mode (length =0xffffffff) or not
    bool DelimitorMode;