]> Creatis software - gdcm.git/commitdiff
* FIX : memory leaks and the set of ArgDelete methods in gdcmDicomDir
authorregrain <regrain>
Wed, 11 Feb 2004 10:52:37 +0000 (10:52 +0000)
committerregrain <regrain>
Wed, 11 Feb 2004 10:52:37 +0000 (10:52 +0000)
       when using from python
     -- BeNours

ChangeLog
gdcmPython/gdcm.i
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h

index 05fe4f15903baf6c1f421eb39c810c246b9d7f5a..39fd0fa12fa927c8d65be15aae7cba02a5aa2bbe 100644 (file)
--- 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
index 71b026def4a7056ae9a1a963fc3a89a3bf4fe704..b731ceddb63b0b610915d2dde5ce17d0049913f4 100644 (file)
@@ -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;
 }
 
 
index 82b35472a2993e4f4178e77a329d9b7eb6903d43..ac19e312329ae57b164a51df277ea3e471b7b21e 100644 (file)
@@ -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
index ae675fb00ab6931b23f6955bc9a33c004f749435..73cf77e57d0da0ad0b03c710435765226c0cc0fe 100644 (file)
@@ -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;