]> Creatis software - gdcm.git/commitdiff
* Add a RefCounter object that is deleted only when it's reference count is
authorregrain <regrain>
Thu, 20 Oct 2005 15:24:05 +0000 (15:24 +0000)
committerregrain <regrain>
Thu, 20 Oct 2005 15:24:05 +0000 (15:24 +0000)
     to 0.
   * DicomEntry (thus, DictEntry) inherits from RefCounter... next stage to do,
     all classes inherit from RefCounter
   * Remove the VirtualDictEntry use, now useless due to the reference
     counting. So, there will be no memory leaks.
   -- BeNours

24 files changed:
Testing/TestDataEntry.cxx
Testing/TestDict.cxx
gdcmPython/gdcm.i
src/CMakeLists.txt
src/gdcmBase.cxx
src/gdcmBase.h
src/gdcmCommon.h
src/gdcmDefaultDicts.cxx.in
src/gdcmDicomEntry.h
src/gdcmDict.cxx
src/gdcmDict.h
src/gdcmDictEntry.cxx
src/gdcmDictEntry.h
src/gdcmDictSet.cxx
src/gdcmDictSet.h
src/gdcmDocEntry.cxx
src/gdcmDocEntry.h
src/gdcmDocEntrySet.cxx
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmFile.cxx
src/gdcmMacro.h [new file with mode: 0644]
src/gdcmRefCounter.cxx [new file with mode: 0644]
src/gdcmRefCounter.h [new file with mode: 0644]

index d57dd7324f08845b55c4da73c7f3b759c12793e7..7c2977c65753c98222f4ae888491c78df3577c0b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestDataEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/20 08:58:15 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2005/10/20 15:24:05 $
+  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
@@ -40,7 +40,7 @@ int TestDataEntry(int , char *[])
    gdcm::DataEntry *entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("US");
 
@@ -56,7 +56,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: 1" << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -71,7 +71,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: 2" << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -86,17 +86,17 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: 0" << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("LT");
 
@@ -111,7 +111,7 @@ int TestDataEntry(int , char *[])
                 << "   Size of string is incorrect" << std::endl
                 << "   Found: " << entry->GetLength() 
                 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -121,7 +121,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -129,7 +129,7 @@ int TestDataEntry(int , char *[])
    {
       std::cout << "   Failed" << std::endl
                 << "   Content of bin area is incorrect" << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -139,7 +139,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -151,18 +151,18 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found " << entry->GetValue(i)
                    << " - Must be " << svalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("US");
 
@@ -178,7 +178,7 @@ int TestDataEntry(int , char *[])
                 << "   BinArea length is incorrect" << std::endl
                 << "   Found: " << entry->GetLength()
                 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -188,7 +188,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -198,7 +198,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount()
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -210,7 +210,7 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << svalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -228,7 +228,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -238,7 +238,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -250,18 +250,18 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << svalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("UL");
 
@@ -277,7 +277,7 @@ int TestDataEntry(int , char *[])
                 << "   BinArea length is incorrect" << std::endl
                 << "   Found: " << entry->GetLength()
                 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -287,7 +287,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << data << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -297,7 +297,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -309,7 +309,7 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << lvalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -327,7 +327,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str() 
                 << " - Must be: " << data << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -337,7 +337,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -349,18 +349,18 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << lvalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("FL");
 
@@ -376,7 +376,7 @@ int TestDataEntry(int , char *[])
                 << "   BinArea length is incorrect" << std::endl
                 << "   Found: " << entry->GetLength() 
                 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -386,7 +386,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -396,7 +396,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -408,7 +408,7 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << fvalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -426,7 +426,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -436,7 +436,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -448,18 +448,18 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << fvalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("FD");
 
@@ -475,7 +475,7 @@ int TestDataEntry(int , char *[])
                 << "   BinArea length is incorrect" << std::endl
                 << "   Found: " << entry->GetLength()
                 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -485,7 +485,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -495,7 +495,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -507,7 +507,7 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << dvalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -525,7 +525,7 @@ int TestDataEntry(int , char *[])
                 << "   Content of string is incorrect" << std::endl
                 << "   Found: " << entry->GetString().c_str()
                 << " - Must be: " << fdata << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -535,7 +535,7 @@ int TestDataEntry(int , char *[])
                 << "   Number of content values is incorrect" << std::endl
                 << "   Found: " << entry->GetValueCount() 
                 << " - Must be: " << nbvalue << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -547,14 +547,14 @@ int TestDataEntry(int , char *[])
                    << "   Content of entry's values is incorrect : id " << i << std::endl
                    << "   Found: " << entry->GetValue(i)
                    << " - Must be: " << dvalue[i] << std::endl;
-         delete dict;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
index a883b4774a22f36910111e74a69d5114c72a29dd..232bbb01d5a9b62051fb7d5304efbe9bc012eada 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/11 14:53:15 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2005/10/20 15:24:05 $
+  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
@@ -48,7 +48,7 @@ int TestDict(int , char *[])
 
    std::cout<<"DictSet content :\n";
 
-   gdcm::Dict *d = dicts->GetFirstEntry();
+   gdcm::Dict *d = dicts->GetFirstDict();
    if (!d)
    {
       std::cout << "Dictset is empty" << std::endl;
@@ -63,7 +63,7 @@ int TestDict(int , char *[])
    {
       std::cout << "------------- a Dict is found : ----------" << std::endl;
       d->Print();
-      d = dicts->GetNextEntry();
+      d = dicts->GetNextDict();
    }
 
    // Print the Dict (public)
index 1849a9a01462b9e0e6dee3652ec3bf0f1d06c20d..a3bdeda9376ce002ba132a39683e3b5118cf8ef9 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "gdcmCommon.h"
 #include "gdcmBase.h"
+#include "gdcmRefCounter.h"
 #include "gdcmTagKey.h"
 #include "gdcmVRKey.h"
 #include "gdcmDict.h"
@@ -242,6 +243,7 @@ typedef unsigned long long uint64_t;
 // Warning: Order matters !
 %include "gdcmCommon.h"
 %include "gdcmBase.h"
+%include "gdcmRefCounter.h"
 %include "gdcmTagKey.h"
 %include "gdcmVRKey.h"
 %include "gdcmDicomEntry.h"
index 3b1710f743d6f89ad5f46294d7aa678cc9d8bb22..51109483437adbe271f0bb57b407707c2a92b685 100644 (file)
@@ -58,6 +58,7 @@ SET(libgdcm_la_SOURCES
    gdcmOrientation.cxx
    gdcmPixelReadConvert.cxx
    gdcmPixelWriteConvert.cxx
+   gdcmRefCounter.cxx
    gdcmRLEFrame.cxx
    gdcmRLEFramesInfo.cxx
    gdcmSeqEntry.cxx
index 3a94b08b132ed79845ee31fc54f50abfafc78b6f..873e442f9a8a8ddf5a5f0b2754b7c6839b406123 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBase.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 10:29:54 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -22,22 +22,6 @@ namespace gdcm
 {
 //-------------------------------------------------------------------------
 // Constructor / Destructor
-/**
- * \brief canonical constructor
- */
-Base::Base( )
-{
-   PrintLevel = 0;
-}
-
-/**
- * \brief canonical destructor
- * \note  If the Header was created by the File constructor,
- *        it is destroyed by the File
- */
-Base::~Base()
-{ 
-}
 
 //-----------------------------------------------------------------------------
 // Public
@@ -50,14 +34,6 @@ Base::~Base()
 
 //-----------------------------------------------------------------------------
 // Print
-/**
- * \brief   Print all the object
- * @param   os The output stream to be written to.
- * @param indent Indentation string to be prepended during printing
- */
-void Base::Print(std::ostream &, std::string const & )
-{
-}
 
 //-----------------------------------------------------------------------------
 } // end namespace gdcm
index c8151f2d6779c081d5e5a397200099596ef1bfb8..3e6097d86a8949cd52fb7e7db0037d8ac0324999 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBase.h,v $
   Language:  C++
-  Date:      $Date: 2005/09/02 07:10:03 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.8 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -34,11 +34,11 @@ namespace gdcm
 class GDCM_EXPORT Base
 {
 public:
-   Base( );
-   virtual ~Base();
+   Base( ) {PrintLevel = 0;}
+   virtual ~Base() {}
 
    virtual void Print(std::ostream &os = std::cout, 
-                      std::string const & indent = "" )
+                      std::string const & indent = "" ) {};
 
    /// \brief Sets the print level for the Dicom Header Elements
    /// \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy Print
index e7875ede4d3f2f703ad6c0f6bc5aeb585eb69063..1361a75487f4f69374dd3008ad9c2ac1cc822334 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmCommon.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:04 $
-  Version:   $Revision: 1.99 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.100 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -21,6 +21,7 @@
 
 #include "gdcmConfigure.h"
 #include "gdcmSystem.h"
+#include "gdcmMacro.h"
 
 #include <string>
 
index 6418c31e46dbc2b5116dbdf452de16c9f861e3ab..21d39605d90972db675831fec5444b7e21d4ee50 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDefaultDicts.cxx.in,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 12:01:50 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.11 $
 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -44,12 +44,14 @@ static DICT_ENTRY datadir[] = {
 
 void FillDefaultDataDict(Dict *d)
 {
+   DictEntry *e;
    unsigned int i = 0;
    DICT_ENTRY n = datadir[i];
    while( n.name != 0 )
    {
-      const DictEntry e( n.group, n.element, n.vr, n.vm, n.name);
+      e = DictEntry::New( n.group, n.element, n.vr, n.vm, n.name);
       d->AddEntry( e );
+      e->Delete();
       n = datadir[++i];
    }
 }
index d74dca86cc1925d733f6de829445d1d9c3bcd8c3..ddd9eaa708db047883b61f4860563b8133105305 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:05 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -20,7 +20,7 @@
 #define GDCMDICOMENTRY_H
 
 #include "gdcmCommon.h"
-#include "gdcmBase.h"
+#include "gdcmRefCounter.h"
 #include "gdcmVRKey.h"
 #include "gdcmTagKey.h"
 
@@ -38,13 +38,12 @@ namespace gdcm
  *  - the VM (Value Multplicity)
  *  - the corresponding name in english
  */
-class GDCM_EXPORT DicomEntry : public Base
+class GDCM_EXPORT DicomEntry : public RefCounter
 {
 public:
-   DicomEntry(const uint16_t &group,const uint16_t &elt,
-              const VRKey &vr = GDCM_VRUNKNOWN);
-   ~DicomEntry();
+   gdcmTypeMacro(DicomEntry);
 
+public:
 // Print
    void Print(std::ostream &os = std::cout, std::string const &indent = "");
 
@@ -71,6 +70,11 @@ public:
 // Key creation
    static TagKey TranslateToKey(uint16_t group, uint16_t elem);
 
+protected:
+   DicomEntry(const uint16_t &group,const uint16_t &elt,
+              const VRKey &vr = GDCM_VRUNKNOWN);
+   ~DicomEntry();
+
 private:
    /// Dicom \ref TagKey. Contains DicomGroup number and DicomElement number
    TagKey Tag;
index 321f168a5de35e8a33e553d43d6070853264977d..b01a84f65b4f793058fcbab7c841e3f0bbcbc670 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 12:58:27 $
-  Version:   $Revision: 1.80 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.81 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -126,7 +126,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 +138,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 +149,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,12 +160,14 @@ 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)
+bool Dict::ReplaceEntry(DictEntry *newEntry)
 {
-   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;
 }
@@ -180,6 +183,7 @@ bool Dict::RemoveEntry(TagKey const &key)
    TagKeyHT::const_iterator it = KeyHt.find(key);
    if ( it != KeyHt.end() ) 
    {
+      it->second->Unregister();
       KeyHt.erase(key);
 
       return true;
@@ -210,6 +214,9 @@ void Dict::ClearEntry()
 {
    // we assume all the pointed DictEntries are already cleaned-up
    // when we clean KeyHt.
+   TagKeyHT::const_iterator it;
+   for(it = KeyHt.begin();it!=KeyHt.end();++it)
+      it->second->Unregister();
    KeyHt.clear();
 }
 
@@ -225,7 +232,7 @@ DictEntry *Dict::GetEntry(TagKey const &key)
    {
       return 0;
    }
-   return &(it->second);
+   return it->second;
 }
 
 DictEntry *Dict::GetEntry(uint16_t group, uint16_t elem)
@@ -236,7 +243,7 @@ DictEntry *Dict::GetEntry(uint16_t group, uint16_t elem)
    {
       return 0;
    }
-   return &(it->second);
+   return it->second;
 }
 
 /**
@@ -247,7 +254,7 @@ DictEntry *Dict::GetFirstEntry()
 {
    ItKeyHt = KeyHt.begin();
    if ( ItKeyHt != KeyHt.end() )
-      return &(ItKeyHt->second);
+      return ItKeyHt->second;
    return NULL;
 }
 
@@ -262,7 +269,7 @@ DictEntry *Dict::GetNextEntry()
 
    ++ItKeyHt;
    if (ItKeyHt != KeyHt.end())
-      return &(ItKeyHt->second);
+      return ItKeyHt->second;
    return NULL;
 }
 
@@ -283,6 +290,7 @@ void Dict::DoTheLoadingJob(std::ifstream &from)
    TagName vm;
    TagName name;
 
+   DictEntry *newEntry;
    while (!from.eof() && from)
    {
       from >> std::hex;
@@ -293,8 +301,9 @@ void Dict::DoTheLoadingJob(std::ifstream &from)
       from >> std::ws;  //remove white space
       std::getline(from, name);
  
-      DictEntry newEntry(group, elem, vr, vm, name);
+      newEntry = DictEntry::New(group, elem, vr, vm, name);
       AddEntry(newEntry);
+      newEntry->Delete();
    }
    from.close();
 }
@@ -314,12 +323,11 @@ void Dict::Print(std::ostream &os, std::string const & )
    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
    {
       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();
 }
index 06b78f3e655b56a03840421e0faef8469dcce59f..455afd0d1b99b832f42505e8de3fc107d9f32e2d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/20 08:58:18 $
-  Version:   $Revision: 1.42 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.43 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -32,7 +32,7 @@ namespace gdcm
 
 //-----------------------------------------------------------------------------
 typedef std::string DictKey;
-typedef std::map<TagKey, DictEntry>  TagKeyHT;
+typedef std::map<TagKey, DictEntry *>  TagKeyHT;
 
 //-----------------------------------------------------------------------------
 /**
@@ -57,8 +57,8 @@ public:
    void Print(std::ostream &os = std::cout, std::string const &indent = "");
 
 // Entries
-   bool AddEntry(DictEntry const &newEntry);
-   bool ReplaceEntry(DictEntry const &newEntry);
+   bool AddEntry(DictEntry *newEntry);
+   bool ReplaceEntry(DictEntry *newEntry);
    bool RemoveEntry (TagKey const &key);
    bool RemoveEntry (uint16_t group, uint16_t elem);
    void ClearEntry();
index cfe420d81a88496853dc6fe7a6aedf1eaf537607..4939bf6333b6469189ae412c8e8641e4152949b0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:04 $
-  Version:   $Revision: 1.53 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  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
@@ -36,7 +36,6 @@ namespace gdcm
  * @param   vm         Value Multiplicity 
  * @param   name       description of the element
 */
-
 DictEntry::DictEntry(uint16_t group, uint16_t elem,
                      VRKey const &vr, 
                      TagName const &vm,
@@ -49,6 +48,22 @@ DictEntry::DictEntry(uint16_t group, uint16_t elem,
 
 //-----------------------------------------------------------------------------
 // Public
+/**
+ * \brief Class allocator
+ * @param   group      DICOM-Group Number
+ * @param   elem       DICOM-Element Number
+ * @param   vr         Value Representation
+ * @param   vm         Value Multiplicity 
+ * @param   name       description of the element
+*/
+DictEntry *DictEntry::New(uint16_t group, uint16_t elem,
+                          VRKey const &vr,
+                          TagName const &vm,
+                          TagName const &name)
+{
+   return new DictEntry(group,elem,vr,vm,name);
+}
+
 /**
  * \brief       If-and only if-the V(alue) R(epresentation)
  * \            is unset then overwrite it.
index 2be34877348a41cc5102059deda8185d8573c4e0..9c0e679fe87f30fbf00271878e779ba79f799b5a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:04 $
-  Version:   $Revision: 1.38 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.39 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -38,8 +38,10 @@ namespace gdcm
 class GDCM_EXPORT DictEntry : public DicomEntry
 {
 public:
-   DictEntry(uint16_t group, 
-             uint16_t elem,
+   gdcmTypeMacro(DictEntry);
+
+public:
+   static DictEntry *New(uint16_t group, uint16_t elem,
              VRKey const &vr       = GDCM_VRUNKNOWN,
              TagName const &vm     = GDCM_UNKNOWN,
              TagName const &name   = GDCM_UNKNOWN);
@@ -62,7 +64,13 @@ public:
    ///         e.g. "Patient Name" for Dicom Tag (0x0010, 0x0010) 
    /// @return the Dicom Name
    const TagName &GetName() const { return Name; } 
+
+protected:
+   DictEntry(uint16_t group, uint16_t elem,
+             VRKey const &vr       = GDCM_VRUNKNOWN,
+             TagName const &vm     = GDCM_UNKNOWN,
+             TagName const &name   = GDCM_UNKNOWN);
+
 private:
    /// \brief Value Multiplicity (e.g. "1", "1-n", "6")
    TagName VM; 
index 2e7167d098ee9354c956952543d67900a9e39f55..32a5023a73c2f85391bc159403fe899d852da4c1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/20 09:23:24 $
-  Version:   $Revision: 1.70 $
+  Date:      $Date: 2005/10/20 15:24:08 $
+  Version:   $Revision: 1.71 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -55,9 +55,6 @@ DictSet::~DictSet()
       tag->second = NULL;
    }
    Dicts.clear();
-
-   // Remove virtual dictionary entries
-   VirtualEntries.clear();
 }
 
 //-----------------------------------------------------------------------------
@@ -96,51 +93,10 @@ Dict *DictSet::GetDict(DictKey const &dictName)
 }
 
 /**
- * \brief   Create a DictEntry which will be referenced in no dictionary
- * @param   group   Group number of the Entry 
- * @param   elem  Element number of the Entry
- * @param   vr  Value Representation of the Entry
- * @param   vm  Value Multiplicity of the Entry
- * @param   name  English name of the Entry
- * @return  virtual entry
- */
-DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
-                                         uint16_t elem,
-                                         const VRKey &vr,
-                                         const TagName &vm,
-                                         const TagName &name)
-{
-   DictEntry *entry;
-
-   // Let's follow 'Purify' advice
-   // const std::string tag = DictEntry::TranslateToKey(group,elem)
-   //                         + "#" + vr + "#" + vm + "#" + name;
-   ExtendedTagKey tag = DictEntry::TranslateToKey(group,elem).str();
-   tag += "#" + vr.str() + "#" + vm + "#" + name;  
-
-   ExtendedTagKeyHT::iterator it;
-   
-   it = VirtualEntries.find(tag);
-   if ( it != VirtualEntries.end() )
-   {
-      entry = &(it->second);
-   }
-   else
-   {
-      DictEntry ent(group, elem, vr, vm, name);
-      VirtualEntries.insert(
-         ExtendedTagKeyHT::value_type(tag, ent) );
-      entry = &(VirtualEntries.find(tag)->second);
-   }
-
-   return entry;
-}
-
-/**
- * \brief   Get the first entry while visiting the DictSet
+ * \brief   Get the first dictionary while visiting the DictSet
  * \return  The first Dict if found, otherwhise NULL
  */
-Dict *DictSet::GetFirstEntry()
+Dict *DictSet::GetFirstDict()
 {
    ItDictHt = Dicts.begin();
    if ( ItDictHt != Dicts.end() )
@@ -149,11 +105,11 @@ Dict *DictSet::GetFirstEntry()
 }
 
 /**
- * \brief   Get the next entry while visiting the Hash table (DictSetHT)
+ * \brief   Get the next dictionary while visiting the Hash table (DictSetHT)
  * \note : meaningfull only if GetFirstEntry already called
  * \return  The next Dict if found, otherwhise NULL
  */
-Dict *DictSet::GetNextEntry()
+Dict *DictSet::GetNextDict()
 {
    gdcmAssertMacro (ItDictHt != Dicts.end());
   
index c05e1b5c7a31d4de53a14029f7d03eb8ed43df5f..237bbe80a653c101795b9b12e25454b27c61414c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictSet.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 12:58:28 $
-  Version:   $Revision: 1.46 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.47 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -27,9 +27,8 @@
 
 namespace gdcm 
 {
+//-----------------------------------------------------------------------------
 typedef std::map<DictKey, Dict*> DictSetHT;
-typedef std::string ExtendedTagKey;
-typedef std::map<ExtendedTagKey, DictEntry>  ExtendedTagKeyHT;
 
 //-----------------------------------------------------------------------------
 /**
@@ -63,13 +62,8 @@ public:
    // \ warning : not end user intended
    // Dict *GetVirtualDict() { return &VirtualEntries; }
 
-   DictEntry *NewVirtualDictEntry(uint16_t group, uint16_t elem,
-                                  const VRKey &vr     = GDCM_VRUNKNOWN,
-                                  const TagName &vm   = GDCM_UNKNOWN,
-                                  const TagName &name = GDCM_UNKNOWN);
-
-   Dict *GetFirstEntry();
-   Dict *GetNextEntry();
+   Dict *GetFirstDict();
+   Dict *GetNextDict();
 
    static std::string BuildDictPath();
 
@@ -83,9 +77,6 @@ private:
 
    /// Directory path to dictionaries
    std::string DictPath;
-
-   /// H table for the on the fly created DictEntries  
-   ExtendedTagKeyHT VirtualEntries; 
 };
 } // end namespace gdcm
 
index 18dfdf57283f902f49313d24a8fed41af2af3035..e54f0c987178fd52aa5ab66949aa38102c15ad04 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/20 07:29:43 $
-  Version:   $Revision: 1.74 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.75 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -44,6 +44,19 @@ DocEntry::DocEntry(DictEntry *in)
    // init some variables
    ReadLength = 0;
    Length = 0;
+
+   gdcmAssertMacro(DicomDict);
+   DicomDict->Register();
+}
+
+/**
+ * \brief   Destructor from a given DictEntry
+ */
+DocEntry::~DocEntry()
+{
+   gdcmAssertMacro(DicomDict);
+
+   DicomDict->Unregister();
 }
 
 //-----------------------------------------------------------------------------
index cf12bdfadf5a6396e062931f832e34f5df7d68fb..acd1eb731691de927405863b826d33f7ec9661bc 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:04 $
-  Version:   $Revision: 1.52 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.53 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -39,8 +39,7 @@ class GDCM_EXPORT DocEntry : public Base
 {
 public:
    DocEntry(DictEntry*);
-   /// \brief Canonical Destructor
-   virtual ~DocEntry() {}
+   virtual ~DocEntry();
 
    virtual void Print (std::ostream &os = std::cout, std::string const &indent = ""); 
    virtual void WriteContent(std::ofstream *fp, FileType filetype);
index 0b4ff26d8456da0553535c17bd24f7cd6a48ce11..8a622d928c90107126f5d4c8c528acbb8a41a279 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 12:58:28 $
-  Version:   $Revision: 1.61 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.62 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -448,9 +448,9 @@ DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem,
                                      VRKey const &vr) 
 {
    DictEntry *dictEntry = GetDictEntry(group, elem, vr);
-   gdcmAssertMacro(dictEntry);
 
    DataEntry *newEntry = new DataEntry(dictEntry);
+   dictEntry->Unregister(); // GetDictEntry register it
    if (!newEntry) 
    {
       gdcmWarningMacro( "Failed to allocate DataEntry");
@@ -469,9 +469,9 @@ DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem,
 SeqEntry* DocEntrySet::NewSeqEntry(uint16_t group, uint16_t elem) 
 {
    DictEntry *dictEntry = GetDictEntry(group, elem, "SQ");
-   gdcmAssertMacro(dictEntry);
 
    SeqEntry *newEntry = new SeqEntry( dictEntry );
+   dictEntry->Unregister(); // GetDictEntry register it
    if (!newEntry)
    {
       gdcmWarningMacro( "Failed to allocate SeqEntry");
@@ -480,22 +480,6 @@ SeqEntry* DocEntrySet::NewSeqEntry(uint16_t group, uint16_t elem)
    return newEntry;
 }
 
-/**
- * \brief   Request a new virtual dict entry to the dict set
- * @param   group Group   number of the underlying DictEntry
- * @param   elem  Element number of the underlying DictEntry
- * @param   vr    V(alue) R(epresentation) of the underlying DictEntry
- * @param   vm    V(alue) M(ultiplicity)   of the underlying DictEntry
- * @param   name   english name
- */
-DictEntry* DocEntrySet::NewVirtualDictEntry( uint16_t group, uint16_t elem,
-                                             VRKey const &vr,
-                                             TagName const &vm,
-                                             TagName const &name )
-{
-   return Global::GetDicts()->NewVirtualDictEntry(group,elem,vr,vm,name);
-}
-
 //-----------------------------------------------------------------------------
 // Protected
 /**
@@ -506,6 +490,7 @@ DictEntry* DocEntrySet::NewVirtualDictEntry( uint16_t group, uint16_t elem,
  * @param   group  Group number of the searched DictEntry
  * @param   elem Element number of the searched DictEntry
  * @return  Corresponding DictEntry when it exists, NULL otherwise.
+ * \remarks The returned DictEntry is registered when existing
  */
 DictEntry *DocEntrySet::GetDictEntry(uint16_t group,uint16_t elem) 
 {
@@ -517,7 +502,9 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group,uint16_t elem)
    }
    else
    {
-      found = pubDict->GetEntry(group, elem);  
+      found = pubDict->GetEntry(group, elem);
+      if( found )
+         found->Register();
    }
    return found;
 }
@@ -530,6 +517,7 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group,uint16_t elem)
  * @param   elem element number of the searched DictEntry
  * @param   vr V(alue) R(epresentation) to use, if necessary 
  * @return  Corresponding DictEntry when it exists, NULL otherwise.
+ * \remarks The returned DictEntry is registered
  */
 DictEntry *DocEntrySet::GetDictEntry(uint16_t group, uint16_t elem,
                                      VRKey const &vr)
@@ -538,7 +526,8 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group, uint16_t elem,
    DictEntry *goodEntry = dictEntry;
    VRKey goodVR = vr;
 
-   if (elem == 0x0000) goodVR="UL";
+   if (elem == 0x0000) 
+      goodVR="UL";
 
    if ( goodEntry )
    {
@@ -554,14 +543,18 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group, uint16_t elem,
    {
       if (dictEntry)
       {
-         goodEntry = NewVirtualDictEntry(group, elem, goodVR, "FIXME", 
-                                         dictEntry->GetName() );
+         goodEntry = DictEntry::New(group, elem, goodVR, "FIXME", 
+                                    dictEntry->GetName() );
       }
       else
       {
-         goodEntry = NewVirtualDictEntry(group, elem, goodVR);
+         goodEntry = DictEntry::New(group, elem, goodVR);
       }
    }
+   else
+   {
+      goodEntry->Register();
+   }
    return goodEntry;
 }
 
index bcf22dd3199ccb8123e66d546d116ac85c998c3d..0173958a015a6c936bbd18374775808ace0e646d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:17:05 $
-  Version:   $Revision: 1.59 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.60 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -115,12 +115,6 @@ public:
                          VRKey const &vr = GDCM_VRUNKNOWN);
    SeqEntry *NewSeqEntry(uint16_t group, uint16_t elem);
 
-// DictEntry  related utilities 
-   DictEntry *NewVirtualDictEntry(uint16_t group,uint16_t elem,
-                                  VRKey const &vr     = GDCM_VRUNKNOWN,
-                                  TagName const &vm     = GDCM_UNKNOWN,
-                                  TagName const &name   = GDCM_UNKNOWN );
-
 protected:
 // DictEntry  related utilities
    DictEntry *GetDictEntry(uint16_t group, uint16_t elem);
index 5e33c4c1d1575b85ef3c0e4c35df649fa48d658e..4a82467dc7b63a8d593423cf383a59db1c249745 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/20 13:55:05 $
-  Version:   $Revision: 1.300 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.301 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1965,6 +1965,7 @@ DocEntry *Document::ReadNextDocEntry()
          if ( dictEntry )
          {
             realVR = dictEntry->GetVR();
+            dictEntry->Unregister();
          }
       }
    }
index 95a51268bcf8845d491ad62902790b867b4f8a54..88986f539279d14b3a622de674fde247a40d9515 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 19:36:54 $
-  Version:   $Revision: 1.283 $
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.284 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -230,10 +230,11 @@ bool File::DoTheLoadingJob( )
          // Change only made if usefull
          if ( PixelVR != oldEntry->GetVR() )
          {
-            DictEntry* newDict = NewVirtualDictEntry(GrPixel,NumPixel,
-                                                     PixelVR,"1","Pixel Data");
+            DictEntry* newDict = DictEntry::New(GrPixel,NumPixel,
+                                                PixelVR,"1","Pixel Data");
 
             DataEntry *newEntry = new DataEntry(newDict);
+            newDict->Delete();
             newEntry->Copy(entry);
             newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea());
             oldEntry->SetSelfArea(false);
diff --git a/src/gdcmMacro.h b/src/gdcmMacro.h
new file mode 100644 (file)
index 0000000..0bd2b43
--- /dev/null
@@ -0,0 +1,29 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmMacro.h,v $
+  Language:  C++
+  Date:      $Date: 2005/10/20 15:24:09 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  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.
+                                                                                
+=========================================================================*/
+
+#ifndef GDCMMACRO_H
+#define GDCMMACRO_H
+
+//-----------------------------------------------------------------------------
+#define gdcmTypeMacro(type) \
+   private : \
+      type(type &); /* Not implemented */ \
+      type &operator=(type &); /* Not implemented */
+
+//-----------------------------------------------------------------------------
+#endif
diff --git a/src/gdcmRefCounter.cxx b/src/gdcmRefCounter.cxx
new file mode 100644 (file)
index 0000000..0af71e9
--- /dev/null
@@ -0,0 +1,40 @@
+  /*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmRefCounter.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/10/20 15:24:10 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  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 "gdcmRefCounter.h"
+
+namespace gdcm 
+{
+//-------------------------------------------------------------------------
+// Constructor / Destructor
+
+//-----------------------------------------------------------------------------
+// Public
+
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+// Private
+
+//-----------------------------------------------------------------------------
+// Print
+
+//-----------------------------------------------------------------------------
+} // end namespace gdcm
+
diff --git a/src/gdcmRefCounter.h b/src/gdcmRefCounter.h
new file mode 100644 (file)
index 0000000..cb3471a
--- /dev/null
@@ -0,0 +1,83 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmRefCounter.h,v $
+  Language:  C++
+  Date:      $Date: 2005/10/20 15:24:10 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  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.
+                                                                                
+=========================================================================*/
+
+#ifndef GDCMREFCOUNTER_H
+#define GDCMREFCOUNTER_H
+
+#include "gdcmBase.h"
+#include "gdcmDebug.h"
+
+namespace gdcm 
+{
+//-----------------------------------------------------------------------------
+/**
+ * \brief Integration of reference counting with a destruction of the
+ *        object only when the reference is to zero
+ */
+class GDCM_EXPORT RefCounter : public Base
+{
+public:
+   gdcmTypeMacro(RefCounter);
+
+public:
+// Allocator / Unallocator
+   /// Delete the object
+   /// \remarks The object is deleted only if its reference counting is to zero
+   inline virtual void Delete(void)
+   {
+      Unregister();
+   }
+
+// Reference count
+   /// Register the object
+   /// \remarks It increments the reference counting
+   inline void Register(void)
+   {
+      RefCount++;
+   }
+   /// Unregister the object
+   /// \remarks It decrements the reference counting
+   inline void Unregister(void)
+   {
+      RefCount--;
+      if(RefCount==0)
+      {
+         delete this;
+      }
+   }
+   /// Get the reference counting
+   /// \return Reference count
+   inline const unsigned long &GetRefCount(void) const
+   {
+      return(RefCount);
+   }
+
+protected:
+   /// Constructor
+   RefCounter() { RefCount = 1; }
+   /// Destructor
+   virtual ~RefCounter() {}
+
+private:
+   /// \brief Reference count
+   unsigned long RefCount;
+};
+} // end namespace gdcm
+
+//-----------------------------------------------------------------------------
+#endif