From: regrain Date: Wed, 11 Feb 2004 10:52:37 +0000 (+0000) Subject: * FIX : memory leaks and the set of ArgDelete methods in gdcmDicomDir X-Git-Tag: Version0.5.bp~309 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b442d0142cdd33c0d02fd3fa6e57138a7c4a9e0a;p=gdcm.git * FIX : memory leaks and the set of ArgDelete methods in gdcmDicomDir when using from python -- BeNours --- diff --git a/ChangeLog b/ChangeLog index 05fe4f15..39fd0fa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-02-11 Benoit Regrain + * FIX : memory leaks and the set of ArgDelete methods in gdcmDicomDir + when using from python + 2004-02-10 Benoit Regrain * FIX : bug fix in the gdcmDirList for the recursivity in directories * FIX : in gdcmDicomDir when the directory is empty diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index 71b026de..b731cedd 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -21,6 +21,7 @@ using namespace std; +//////////////////////////////////////////////////////////////////////////// // Utility functions on strings for removing leading and trailing spaces void EatLeadingAndTrailingSpaces(string & s) { while ( s.length() && (s[0] == ' ') ) @@ -215,10 +216,11 @@ extern gdcmGlobal gdcmGlob; //////////////////////////////////////////////////////////////////////////// // Deals with function returning a C++ string. -%typemap(python, in) (gdcmMethod *method,void *arg) { +%typemap(python, in) (gdcmMethod *,void * =NULL,gdcmMethod * =NULL) { Py_INCREF($input); $1=vtkPythonVoidFunc; $2=$input; + $3=vtkPythonVoidFuncArgDelete; } diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 82b35472..ac19e312 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -31,6 +31,9 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir, startMethod=NULL; progressMethod=NULL; endMethod=NULL; + startMethodArgDelete=NULL; + progressMethodArgDelete=NULL; + endMethodArgDelete=NULL; startArg=NULL; progressArg=NULL; endArg=NULL; @@ -60,6 +63,10 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir, */ gdcmDicomDir::~gdcmDicomDir() { + SetStartMethod(NULL); + SetProgressMethod(NULL); + SetEndMethod(NULL); + if(metaElems) delete metaElems; @@ -123,6 +130,93 @@ void gdcmDicomDir::ParseDirectory(void) CreateDicomDir(); } +/* + * \ingroup gdcmDicomDir + * \brief Set the start method to call when the parsing of the directory starts + * @param method Method to call + * @param arg Argument to pass to the method + * \warning In python : the arg parameter isn't considered + */ +void gdcmDicomDir::SetStartMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete) +{ + if((startArg)&&(startMethodArgDelete)) + startMethodArgDelete(startArg); + + startMethod=method; + startArg=arg; + startMethodArgDelete=argDelete; +} + +/* + * \ingroup gdcmDicomDir + * \brief Set the method to delete the argument + * The argument is destroyed when the method is changed or when the class + * is destroyed + * @param method Method to call to delete the argument + */ +void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method) +{ + startMethodArgDelete=method; +} + +/* + * \ingroup gdcmDicomDir + * \brief Set the progress method to call when the parsing of the directory progress + * @param method Method to call + * @param arg Argument to pass to the method + * \warning In python : the arg parameter isn't considered + */ +void gdcmDicomDir::SetProgressMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete) +{ + if((progressArg)&&(progressMethodArgDelete)) + progressMethodArgDelete(progressArg); + + progressMethod=method; + progressArg=arg; + progressMethodArgDelete=argDelete; +} + +/* + * \ingroup gdcmDicomDir + * \brief Set the method to delete the argument + * The argument is destroyed when the method is changed or when the class + * is destroyed + * @param method Method to call to delete the argument + */ +void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method) +{ + progressMethodArgDelete=method; +} + +/* + * \ingroup gdcmDicomDir + * \brief Set the end method to call when the parsing of the directory ends + * @param method Method to call + * @param arg Argument to pass to the method + * \warning In python : the arg parameter isn't considered + */ +void gdcmDicomDir::SetEndMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete) +{ + if((endArg)&&(endMethodArgDelete)) + endMethodArgDelete(endArg); + + endMethod=method; + endArg=arg; + endMethodArgDelete=argDelete; +} + +/* + * \ingroup gdcmDicomDir + * \brief Set the method to delete the argument + * The argument is destroyed when the method is changed or when the class + * is destroyed + * @param method Method to call to delete the argument + */ +void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method) +{ + endMethodArgDelete=method; +} + /** * \ingroup gdcmDicomDir * \brief writes on disc a DICOMDIR diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index ae675fb0..73cf77e5 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -44,14 +44,17 @@ public: // Parsing void ParseDirectory(void); - inline void SetStartMethod(gdcmMethod *method,void *arg=NULL) {startMethod=method;startArg=arg;}; - inline void SetProgressMethod(gdcmMethod *method,void *arg=NULL) {progressMethod=method;progressArg=arg;}; - inline void SetEndMethod(gdcmMethod *method,void *arg=NULL) {endMethod=method;endArg=arg;}; + void SetStartMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL); + void SetStartMethodArgDelete(gdcmMethod *); + void SetProgressMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL); + void SetProgressMethodArgDelete(gdcmMethod *); + void SetEndMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL); + void SetEndMethodArgDelete(gdcmMethod *); - inline float GetProgress(void) {return(progress);}; + inline float GetProgress(void) {return(progress);}; - inline void AbortProgress(void) {abort=true;}; - inline bool IsAborted(void) {return(abort);}; + inline void AbortProgress(void) {abort=true;}; + inline bool IsAborted(void) {return(abort);}; // Write bool Write(std::string fileName); @@ -96,6 +99,9 @@ private: gdcmMethod *startMethod; gdcmMethod *progressMethod; gdcmMethod *endMethod; + gdcmMethod *startMethodArgDelete; + gdcmMethod *progressMethodArgDelete; + gdcmMethod *endMethodArgDelete; void *startArg; void *progressArg; void *endArg;