From: frog Date: Tue, 15 Apr 2003 10:32:20 +0000 (+0000) Subject: * Memory link hunt (by using valgrind --leak-check=yes PrintHeader). X-Git-Tag: Version0.3~60 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=541ed5b2824ff14630565a474b1406e58b677662;hp=4a0c2407ec81e041c2e43781acec4c78c83fc487;p=gdcm.git * 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) --- diff --git a/ChangeLog b/ChangeLog index 66c84436..9f957e19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-04-15 Eric Boix 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 with JPR * src/Makefile.am now exports all the necessary include files at make install stage. diff --git a/src/Makefile.am b/src/Makefile.am index 17438bae..dcd328a2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 = \ diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index 2d6d95fa..ace75222 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -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 diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index 3ccc09d9..c57ae166 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -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); diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 7588e008..66b97ce2 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -18,11 +18,11 @@ // 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); } /** diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index b082bd83..1834dfdb 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -5,6 +5,7 @@ #include #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); diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 127737e1..9b93e96c 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,6 +3,10 @@ #include // 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; diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 3432bf93..325bde91 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -1,8 +1,12 @@ // gdcmUtil.h +#ifndef GDCMUTIL_H +#define GDCMUTIL_H + #include #include #include +#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 index 00000000..802557d1 --- /dev/null +++ b/src/gdcmVR.cxx @@ -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 index 00000000..3be7fa4c --- /dev/null +++ b/src/gdcmVR.h @@ -0,0 +1,28 @@ +// gdcmVR.h + +#ifndef GDCMVR_H +#define GDCMVR_H + +#include +#include +#include "gdcmCommon.h" + +typedef string VRKey; +typedef string VRAtr; +typedef map 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