[gstreamermm] Use std::auto_ptr<> in classes that keep member slots.



commit 573bf92e1a166336c2af3819294deaf0f84e4e6e
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Wed Dec 16 15:49:49 2009 -0500

    	Use std::auto_ptr<> in classes that keep member slots.
    
    	* gstreamer/src/audioclock.ccg:
    	* gstreamer/src/audioclock.hg:
    	* gstreamer/src/task.ccg:
    	* gstreamer/src/task.hg: Use std::auto_ptr<> for classes that are
    	constructed with slots and keep a copy of the slots so that they are
    	automatically freed with the auto_ptr.  If the C API had new functions
    	with destroy notification this would not be necessary, but it doesn't
    	seem complicated to compensate in C++.

 ChangeLog                    |   13 +++++++++++++
 gstreamer/src/audioclock.ccg |   35 ++++++++---------------------------
 gstreamer/src/audioclock.hg  |    6 ++----
 gstreamer/src/task.ccg       |   33 ++++++---------------------------
 gstreamer/src/task.hg        |    6 ++----
 5 files changed, 31 insertions(+), 62 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2afc0fb..880f63a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-12-16  José Alburquerque  <jaalburqu svn gnome org>
+
+	Use std::auto_ptr<> in classes that keep member slots.
+
+	* gstreamer/src/audioclock.ccg:
+	* gstreamer/src/audioclock.hg:
+	* gstreamer/src/task.ccg:
+	* gstreamer/src/task.hg: Use std::auto_ptr<> for classes that are
+	constructed with slots and keep a copy of the slots so that they are
+	automatically freed with the auto_ptr.  If the C API had new functions
+	with destroy notification this would not be necessary, but it doesn't
+	seem complicated to compensate in C++.
+
 2009-12-10  José Alburquerque  <jaalburqu svn gnome org>
 
 	Gst::RingBufferSpec: Avoid copying between it and its C counterpart.
diff --git a/gstreamer/src/audioclock.ccg b/gstreamer/src/audioclock.ccg
index 5f9a3a9..d199290 100644
--- a/gstreamer/src/audioclock.ccg
+++ b/gstreamer/src/audioclock.ccg
@@ -54,37 +54,18 @@ static GstClockTime AudioClock_GetTime_gstreamermm_callback(GstClock* clock, voi
 namespace Gst
 {
 
-AudioClock::AudioClock(const Glib::ConstructParams& construct_params)
-:
-  Gst::SystemClock(construct_params),
-  _slot_set(false)
-{}
-
-AudioClock::AudioClock(GstAudioClock* castitem)
-:
-  Gst::SystemClock(reinterpret_cast<GstSystemClock*>(castitem)),
-  _slot_set(false)
-{}
-
-
 AudioClock::AudioClock(const Glib::ustring& name, const SlotGetTime& time_slot)
-  : _CONSTRUCT("name", name.c_str()),
-    _slot_set(true)
+  : _CONSTRUCT("name", name.c_str())
 {
-  slot = new SlotGetTime(time_slot);
+  // The slot is dynamically allocated because it is called each time the time
+  // is gotten.
+  m_slot.reset(new SlotGetTime(time_slot));
 
-  //The following lines are taken verbatim from gst_audio_clock_new() after the
-  //call to g_object_new() because it seems that bug #545782 will not be
-  //accepted:
+  // The following lines are taken verbatim from gst_audio_clock_new() after
+  // the call to g_object_new() because it seems that bug #545782 will not be
+  // accepted.
   gobj()->func = &AudioClock_GetTime_gstreamermm_callback;
-  gobj()->user_data = &slot;
-}
-
-
-AudioClock::~AudioClock()
-{
-  if(_slot_set)
-    delete slot;
+  gobj()->user_data = m_slot.get();
 }
 
 } //namespace Gst
diff --git a/gstreamer/src/audioclock.hg b/gstreamer/src/audioclock.hg
index c85aaed..af37abd 100644
--- a/gstreamer/src/audioclock.hg
+++ b/gstreamer/src/audioclock.hg
@@ -18,6 +18,7 @@
  */
 
 #include <gstreamermm/systemclock.h>
+#include <memory>
 
 _DEFS(gstreamermm,gst)
 
@@ -36,8 +37,6 @@ namespace Gst
 class AudioClock : public Gst::SystemClock
 {
   _CLASS_GOBJECT(AudioClock, GstAudioClock, GST_AUDIO_CLOCK, Gst::SystemClock, GstSystemClock)
-  _CUSTOM_DTOR()
-  _CUSTOM_CTOR_CAST()
 
 public:
   /** For example,
@@ -67,8 +66,7 @@ public:
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 private:
-  SlotGetTime* slot;
-  bool _slot_set;
+  std::auto_ptr<SlotGetTime> m_slot;
 #endif
 };
 
diff --git a/gstreamer/src/task.ccg b/gstreamer/src/task.ccg
index 9139d3f..dce9068 100644
--- a/gstreamer/src/task.ccg
+++ b/gstreamer/src/task.ccg
@@ -106,33 +106,19 @@ static void Task_Callbacks_gstreamermm_callback_destroy(void* data)
 namespace Gst
 {
 
-Task::Task(const Glib::ConstructParams& construct_params)
-:
-  Object(construct_params),
-  _slot_set(false)
-{}
-
-Task::Task(GstTask* castitem)
-:
-  Object(reinterpret_cast<GstObject*>(castitem)),
-  _slot_set(false)
-{}
-
-
 Task::Task(const SlotTask& task_slot)
 :
-  _CONSTRUCT(),
-  _slot_set(true)
+  _CONSTRUCT()
 {
-  //Create a copy of the slot.  A pointer to this copy will be passed through
-  //the call back's data parameter.  It will be destroyed in the Task's
-  //destructor
-  slot = new SlotTask(task_slot);
+  // Create a copy of the slot.  A pointer to this copy will be passed through
+  // the call back's data parameter.  It will be destroyed with the
+  // std::auto_ptr<>.
+  m_slot.reset(new SlotTask(task_slot));
 
   // These lines are taken verbatim from gst_task_create() after calling
   // g_object_new().
   gobj()->func = &Task_Task_gstreamermm_callback;
-  gobj()->data = &slot;
+  gobj()->data = m_slot.get();
 }
 
 void Task::set_thread_slots(const SlotEnter& enter_slot,
@@ -154,11 +140,4 @@ void Task::set_thread_slots(const SlotEnter& enter_slot,
     &Task_Callbacks_gstreamermm_callback_destroy);
 }
 
-Task::~Task()
-{
-  // Delete task's slot upon destruction
-  if(_slot_set)
-    delete slot;
-}
-
 } //namespace Gst
diff --git a/gstreamer/src/task.hg b/gstreamer/src/task.hg
index c654a5d..eb49f7e 100644
--- a/gstreamer/src/task.hg
+++ b/gstreamer/src/task.hg
@@ -19,6 +19,7 @@
 
 #include <gst/gsttask.h>
 #include <gstreamermm/object.h>
+#include <memory>
 
 _DEFS(gstreamermm,gst)
 
@@ -62,8 +63,6 @@ class TaskPool;
 class Task : public Object
 {
   _CLASS_GOBJECT(Task, GstTask, GST_TASK, Object, GstObject)
-  _CUSTOM_CTOR_CAST()
-  _CUSTOM_DTOR()
 
 public:
   /** For example,
@@ -136,8 +135,7 @@ public:
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 private:
-  SlotTask* slot;
-  bool _slot_set;
+  std::auto_ptr<SlotTask> m_slot;
 #endif
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]