]> Creatis software - gdcm.git/commitdiff
* Memory link hunt (by using valgrind --leak-check=yes PrintHeader).
authorfrog <frog>
Tue, 15 Apr 2003 10:32:20 +0000 (10:32 +0000)
committerfrog <frog>
Tue, 15 Apr 2003 10:32:20 +0000 (10:32 +0000)
        - added src/gdcmVR.cxx gdcmVR.h that objectify the previous
          gdcmHeader::_dicom_vr.
        - gdcmHeader::InitVRDict transfered as gdcmVR::gdcmVR().
        - gdcmHeader::dicom_vr is now of type gdcmVR* as opposed to
          VRHT*.
        - gdcmGlobal global object contained class added (see src/gdcmUtil.x)

ChangeLog
src/Makefile.am
src/gdcmDictSet.cxx
src/gdcmDictSet.h
src/gdcmHeader.cxx
src/gdcmHeader.h
src/gdcmUtil.cxx
src/gdcmUtil.h
src/gdcmVR.cxx [new file with mode: 0644]
src/gdcmVR.h [new file with mode: 0644]

index 66c844365a174d3b4b3d0b85868901a75d27b27c..9f957e190033f9c747f234d8d2f74410cd0a4f7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-04-15  Eric Boix <Eric.Boix@creatis.insa-lyon.fr> with JPR
+      * Memory link hunt (by using valgrind --leak-check=yes PrintHeader).
+        - added src/gdcmVR.cxx gdcmVR.h that objectify the previous
+          gdcmHeader::_dicom_vr.
+        - gdcmHeader::InitVRDict transfered as gdcmVR::gdcmVR().
+        - gdcmHeader::dicom_vr is now of type gdcmVR* as opposed to
+          VRHT*.
+        - gdcmGlobal global object contained class added (see src/gdcmUtil.x)
+
 2003-04-9  Eric Boix <Eric.Boix@creatis.insa-lyon.fr> with JPR
       * src/Makefile.am now exports all the necessary include files at
         make install stage.
index 17438bae021be51f7ee812bcb0b932a6f40400f4..dcd328a2ea9d9aa5229734d4abe6bbe96f883216 100644 (file)
@@ -28,6 +28,7 @@ libgdcm_la_SOURCES=           \
        gdcmElValSet.cxx  \
        gdcmHeaderIdo.cxx \
        gdcmFile.cxx    \
+       gdcmVR.cxx      \
        gdcmJpeg.cxx
 
 libgdcmincludedir = $(includedir)
@@ -41,6 +42,7 @@ libgdcminclude_HEADERS = \
        gdcmDictEntry.h \
        gdcmElValue.h   \
        gdcmElValSet.h  \
+       gdcmVR.h        \
        gdcmFile.h
 
 EXTRA_DIST = \
index 2d6d95fab70f4063fb0c9355f491d2074da9df9c..ace75222b3241d7624543308938177bc7f4fcdf5 100644 (file)
@@ -97,6 +97,11 @@ gdcmDictSet::gdcmDictSet(void) {
    dicts[PUB_DICT_NAME] = DefaultPubDict;
 }
 
+gdcmDictSet::~gdcmDictSet() {
+   //FIXME : first destroy pointed dictionaries before trashing hash table.
+   dicts.clear();
+}
+
 /**
  * \ingroup gdcmDictSet
  * \brief   Loads a dictionary from a specified file, and add it
index 3ccc09d97f26fbcc36953643644b4d9f0e428100..c57ae16603bf1a34ee17a0e21ce150f880fee1d6 100644 (file)
@@ -41,6 +41,7 @@ public:
        // TODO Swig int LoadAllDictFromDirectory(string DirectoryName);
        // TODO Swig string* GetAllDictNames();
        gdcmDictSet(void);
+       ~gdcmDictSet(void);
        void Print(ostream&);
        gdcmDict* GetDict(DictKey DictName);
        gdcmDict* GetDefaultPubDict(void);
index 7588e008f181abf29f7350615c43f2577b595d21..66b97ce2b8ac093cc7de8d98392bc7793040cebd 100644 (file)
 // Refer to gdcmHeader::SetMaxSizeLoadElementValue()
 #define _MaxSizeLoadElementValue_   1024
 
-VRHT * gdcmHeader::dicom_vr = (VRHT*)0;
+gdcmVR * gdcmHeader::dicom_vr = (gdcmVR*)0;
 
 void gdcmHeader::Initialise(void) {
    if (!gdcmHeader::dicom_vr)
-      InitVRDict();
+      gdcmHeader::dicom_vr = gdcmGlobal::GetVR();
    Dicts = new gdcmDictSet();
    RefPubDict = Dicts->GetDefaultPubDict();
    RefShaDict = (gdcmDict*)0;
@@ -61,45 +61,11 @@ bool gdcmHeader::CloseFile(void) {
 }
 
 gdcmHeader::~gdcmHeader (void) {
+   delete Dicts;
    //FIXME obviously there is much to be done here !
    return;
 }
 
-void gdcmHeader::InitVRDict (void) {
-   if (dicom_vr) {
-      dbg.Verbose(0, "gdcmHeader::InitVRDict:", "VR dictionary allready set");
-      return;
-   }
-   VRHT *vr = new VRHT;
-   (*vr)["AE"] = "Application Entity";       // At most 16 bytes
-   (*vr)["AS"] = "Age String";               // Exactly 4 bytes
-   (*vr)["AT"] = "Attribute Tag";            // 2 16-bit unsigned short integers
-   (*vr)["CS"] = "Code String";              // At most 16 bytes
-   (*vr)["DA"] = "Date";                     // Exactly 8 bytes
-   (*vr)["DS"] = "Decimal String";           // At most 16 bytes
-   (*vr)["DT"] = "Date Time";                // At most 26 bytes
-   (*vr)["FL"] = "Floating Point Single";    // 32-bit IEEE 754:1985 float
-   (*vr)["FD"] = "Floating Point Double";    // 64-bit IEEE 754:1985 double
-   (*vr)["IS"] = "Integer String";           // At most 12 bytes
-   (*vr)["LO"] = "Long String";              // At most 64 chars
-   (*vr)["LT"] = "Long Text";                // At most 10240 chars
-   (*vr)["OB"] = "Other Byte String";        // String of bytes (vr independant)
-   (*vr)["OW"] = "Other Word String";        // String of 16-bit words (vr dep)
-   (*vr)["PN"] = "Person Name";              // At most 64 chars
-   (*vr)["SH"] = "Short String";             // At most 16 chars
-   (*vr)["SL"] = "Signed Long";              // Exactly 4 bytes
-   (*vr)["SQ"] = "Sequence of Items";        // Not Applicable
-   (*vr)["SS"] = "Signed Short";             // Exactly 2 bytes
-   (*vr)["ST"] = "Short Text";               // At most 1024 chars
-   (*vr)["TM"] = "Time";                     // At most 16 bytes
-   (*vr)["UI"] = "Unique Identifier";        // At most 64 bytes
-   (*vr)["UL"] = "Unsigned Long ";           // Exactly 4 bytes
-   (*vr)["UN"] = "Unknown";                  // Any length of bytes
-   (*vr)["US"] = "Unsigned Short ";          // Exactly 2 bytes
-   (*vr)["UT"] = "Unlimited Text";           // At most 2^32 -1 chars
-   dicom_vr = vr; 
-}
-
 // Fourth semantics:
 // CMD      Command        
 // META     Meta Information 
@@ -324,7 +290,7 @@ void gdcmHeader::FindVR( gdcmElValue *ElVal) {
    // CLEANME searching the dicom_vr at each occurence is expensive.
    // PostPone this test in an optional integrity check at the end
    // of parsing or only in debug mode.
-   if ( RealExplicit && !dicom_vr->count(vr) )
+   if ( RealExplicit && !dicom_vr->Count(vr) )
       RealExplicit= false;
 
    if ( RealExplicit ) {
@@ -851,6 +817,7 @@ void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) {
       return;
    }
    ElVal->SetValue(NewValue);
+   free(NewValue);
 }
 
 /**
index b082bd8336f0a3a3a4368e0930a58515cbe8eceb..1834dfdbd811d60c9011eb80acf9668f994f9839 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <map>
 #include "gdcmCommon.h"
+#include "gdcmUtil.h"
 #include "gdcmException.h"
 #include "gdcmDictSet.h"
 #include "gdcmElValue.h"
@@ -36,7 +37,7 @@ class GDCM_EXPORT gdcmHeader {
 private:
    /// Pointer to the Value Representation Hash Table which contains all
    /// the VR of the DICOM version3 public dictionary. 
-   static VRHT *dicom_vr;
+   static gdcmVR *dicom_vr;
  
    /// Global dictionary container
    gdcmDictSet* Dicts;
@@ -76,7 +77,6 @@ private:
    guint32 FindLengthOB(void);
    void Initialise(void);
    void CheckSwap(void);
-   void InitVRDict(void);
    void SwitchSwapToBigEndian(void);
    // CLEAN ME: NewManualElValToPubDict is NOT called any more.
    gdcmElValue*  NewManualElValToPubDict(string NewTagName, string VR);
index 127737e1d95a7773f62577eccbae3f5f3ebea1c7..9b93e96cef69cb519e7e5e2fc4e24183faec1856 100644 (file)
@@ -3,6 +3,10 @@
 #include <ctype.h>   // For isspace
 #include "gdcmUtil.h"
 
+// Library globals.
+gdcmDebug dbg;
+gdcmVR * gdcmGlobal::VR = new gdcmVR();
+
 gdcmDebug::gdcmDebug(int level) {
        DebugLevel = level;
 }
@@ -43,8 +47,19 @@ void gdcmDebug::Exit(int a) {
 #endif
 }
 
-gdcmDebug dbg;
+///////////////////////////////////////////////////////////////////////////
+gdcmGlobal::gdcmGlobal(void) {
+}
+
+gdcmGlobal::~gdcmGlobal(void) {
+   delete VR;
+}
+
+gdcmVR * gdcmGlobal::GetVR(void) {
+   return VR;
+}
 
+///////////////////////////////////////////////////////////////////////////
 // Because is not yet available in g++2.96
 istream& eatwhite(istream& is) {
        char c;
index 3432bf933ae2ecfd2f3fa33e50ccde5bef15db19..325bde910b5bdf53f33cb03e3b8ce960b633d05c 100644 (file)
@@ -1,8 +1,12 @@
 // gdcmUtil.h
 
+#ifndef GDCMUTIL_H
+#define GDCMUTIL_H
+
 #include <iostream>
 #include <vector>
 #include <string>
+#include "gdcmVR.h"
 using namespace std;
 
 class gdcmDebug {
@@ -17,6 +21,15 @@ public:
        void Exit(int);
 };
 
+class gdcmGlobal {
+private:
+   static gdcmVR *VR; 
+public:
+   gdcmGlobal(void);
+   ~gdcmGlobal(void);
+   static gdcmVR * GetVR(void);
+};
+
 istream & eatwhite(istream & is);
 
 void Tokenize (const string& str,
@@ -24,3 +37,5 @@ void Tokenize (const string& str,
                const string& delimiters = " ");
 
 extern gdcmDebug dbg;
+
+#endif
diff --git a/src/gdcmVR.cxx b/src/gdcmVR.cxx
new file mode 100644 (file)
index 0000000..802557d
--- /dev/null
@@ -0,0 +1,47 @@
+// gdcmVR.cxx
+
+#include "gdcmVR.h"
+#include "gdcmUtil.h"
+
+gdcmVR::gdcmVR () {
+   // NOTE: making the affectation directely to dicom_vr instead of passing
+   //       through an apparently unncessary local variable vr, crashes with
+   //       gcc... Beware.
+   VRHT *vr = new VRHT;
+   (*vr)["AE"] = "Application Entity";    // At most 16 bytes
+   (*vr)["AS"] = "Age String";            // Exactly 4 bytes
+   (*vr)["AT"] = "Attribute Tag";         // 2 16-bit unsigned short integers
+   (*vr)["CS"] = "Code String";           // At most 16 bytes
+   (*vr)["DA"] = "Date";                  // Exactly 8 bytes
+   (*vr)["DS"] = "Decimal String";        // At most 16 bytes
+   (*vr)["DT"] = "Date Time";             // At most 26 bytes
+   (*vr)["FL"] = "Floating Point Single"; // 32-bit IEEE 754:1985 float
+   (*vr)["FD"] = "Floating Point Double"; // 64-bit IEEE 754:1985 double
+   (*vr)["IS"] = "Integer String";        // At most 12 bytes
+   (*vr)["LO"] = "Long String";           // At most 64 chars
+   (*vr)["LT"] = "Long Text";             // At most 10240 chars
+   (*vr)["OB"] = "Other Byte String";     // String of bytes (vr independant)
+   (*vr)["OW"] = "Other Word String";     // String of 16-bit words (vr dep)
+   (*vr)["PN"] = "Person Name";           // At most 64 chars
+   (*vr)["SH"] = "Short String";          // At most 16 chars
+   (*vr)["SL"] = "Signed Long";           // Exactly 4 bytes
+   (*vr)["SQ"] = "Sequence of Items";     // Not Applicable
+   (*vr)["SS"] = "Signed Short";          // Exactly 2 bytes
+   (*vr)["ST"] = "Short Text";            // At most 1024 chars
+   (*vr)["TM"] = "Time";                  // At most 16 bytes
+   (*vr)["UI"] = "Unique Identifier";     // At most 64 bytes
+   (*vr)["UL"] = "Unsigned Long ";        // Exactly 4 bytes
+   (*vr)["UN"] = "Unknown";               // Any length of bytes
+   (*vr)["US"] = "Unsigned Short ";       // Exactly 2 bytes
+   (*vr)["UT"] = "Unlimited Text";        // At most 2^32 -1 chars
+   dicom_vr = vr;
+}
+
+gdcmVR::~gdcmVR() {
+   dicom_vr->clear();
+   delete dicom_vr;
+}
+
+int gdcmVR::Count(VRKey key) {
+   return dicom_vr->count(key);
+}
diff --git a/src/gdcmVR.h b/src/gdcmVR.h
new file mode 100644 (file)
index 0000000..3be7fa4
--- /dev/null
@@ -0,0 +1,28 @@
+// gdcmVR.h
+
+#ifndef GDCMVR_H
+#define GDCMVR_H
+
+#include <map>
+#include <string>
+#include "gdcmCommon.h"
+
+typedef string VRKey;
+typedef string VRAtr;
+typedef map<VRKey, VRAtr> VRHT;    // Value Representation Hash Table
+
+/*
+ * \defgroup gdcmVR
+ * \brief  Container for dicom Value Representation Hash Table
+ * \note   This is a singleton
+ */
+class GDCM_EXPORT gdcmVR {
+private:
+   VRHT *dicom_vr;
+public:
+       gdcmVR();
+   ~gdcmVR();
+   int Count(VRKey);
+};
+
+#endif