[gstreamermm] gstiterator returns a GValue*



commit 7f9a384605f23552094becbcb62cb7e5f35c2709
Author: Dirk Van Haerenborgh <vhdirk gmail com>
Date:   Tue Oct 15 09:00:52 2013 +0200

    gstiterator returns a GValue*
    
    Signed-off-by: Marcin Kolny <marcin kolny gmail com>

 gstreamer/src/iterator.hg |   50 +++++++++++++++++++++++---------------------
 1 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/gstreamer/src/iterator.hg b/gstreamer/src/iterator.hg
index 191fb6d..1797b97 100644
--- a/gstreamer/src/iterator.hg
+++ b/gstreamer/src/iterator.hg
@@ -241,11 +241,12 @@ public:
 
 template<class CppType>
 IteratorBase<CppType>::IteratorBase()
-: current(0),
+: current(new GValue()),
   current_result(Gst::ITERATOR_OK),
   cobject_(0),
   take_ownership(true)
-{}
+{
+}
 
 template<class CppType>
 IteratorBase<CppType>::IteratorBase(const IteratorBase<CppType>& other)
@@ -257,7 +258,7 @@ IteratorBase<CppType>::IteratorBase(const IteratorBase<CppType>& other)
 
 template<class CppType>
 IteratorBase<CppType>::IteratorBase(GstIterator* castitem, bool take_ownership)
-: current(0),
+: current(new GValue()),
   current_result(Gst::ITERATOR_OK),
   cobject_(castitem),
   take_ownership(take_ownership)
@@ -274,12 +275,16 @@ IteratorBase<CppType>& IteratorBase<CppType>::operator=(const IteratorBase<CppTy
 template<class CppType>
 IteratorResult IteratorBase<CppType>::next()
 {
+  // Unset current before calling gst_iterator_next()
+  if(G_IS_VALUE(this->current))
+    g_value_unset(this->current);  
+  
   current_result =
     static_cast<Gst::IteratorResult>(gst_iterator_next(cobj(), current));
 
-  // Set current to null if iterator is done:
+  // Reset current if iterator is done:
   if(current_result == Gst::ITERATOR_DONE)
-    current = 0;
+    g_value_reset (current);
 
   return current_result;
 }
@@ -288,14 +293,14 @@ template<class CppType>
 void IteratorBase<CppType>::resync()
 {
   gst_iterator_resync(cobj());
-  current = 0;
+  g_value_reset (current);
   current_result = Gst::ITERATOR_OK;
 }
 
 template<class CppType>
 bool IteratorBase<CppType>::is_start() const
 {
-  return (current == 0 && current_result == Gst::ITERATOR_OK);
+  return (G_VALUE_HOLDS_OBJECT(current) && current_result == Gst::ITERATOR_OK);
 }
 
 template<class CppType>
@@ -307,7 +312,7 @@ bool IteratorBase<CppType>::is_end() const
 template<class CppType>
 IteratorBase<CppType>::operator bool() const
 {
-  return (current != 0);
+  return (! G_VALUE_HOLDS_OBJECT(current));
 }
 
 template<class CppType>
@@ -321,9 +326,10 @@ void IteratorBase<CppType>::swap(IteratorBase<CppType>& other)
   take_ownership = other.take_ownership;
   other.take_ownership = temp_take_ownership;
 
-  void* const temp_current = current;
-  current = other.current;
-  other.current = temp_current;
+  GValue * const temp_current;
+  g_value_copy(current, temp_current);
+  g_value_copy(other.current, current);
+  g_value_copy(temp_current, other.current);
 
   const IteratorResult temp_result = current_result;
   current_result = other.current_result;
@@ -339,6 +345,8 @@ IteratorBase<CppType>::~IteratorBase()
     gst_iterator_free(cobject_);
     cobject_ = 0;
   }
+  if(G_IS_VALUE(this->current))
+    g_value_unset(this->current);
 }
 
 /***************** Gst::IteratorBasic<CppType> ***********************/
@@ -366,8 +374,8 @@ CppType IteratorBasic<CppType>::operator*() const
 {
   typedef typename CppType::BaseObjectType CType;
 
-  if(this->current)
-    return CppType(static_cast<CType*>(this->current));
+  if(G_IS_VALUE(this->current))
+    return CppType(static_cast<CType*>(g_value_get_object(this->current)));
   else
     return CppType();
 }
@@ -377,7 +385,7 @@ CppType* IteratorBasic<CppType>::operator->() const
 {
   static typename CppType::CppObjectType result;
 
-  if(this->current)
+  if(G_IS_VALUE(this->current))
   {
     result = this->operator*();
     return &result;
@@ -425,12 +433,6 @@ IteratorResult Iterator<CppType>::next()
 {
   const IteratorResult result = IteratorBasic<CppType>::next();
 
-  // Remove extra reference that gst_iterator_next() takes because references
-  // are taken when using Gst::Iterator<CppType> dereferencing operators (*
-  // and ->).
-  if(this->current)
-    g_object_unref(this->current);
-
   return result;
 }
 
@@ -439,11 +441,11 @@ Glib::RefPtr<CppType> Iterator<CppType>::operator*() const
 {
   typedef typename CppType::BaseObjectType CType;
 
-  if(this->current)
+  if(G_IS_VALUE(this->current))
   {
     //Take extra reference when dereferencing.  The reference will disappear
     //when Glib::RefPtr<> is destroyed.
-    return Glib::wrap(static_cast<CType*>(this->current), true);
+    return Glib::wrap(static_cast<CType*>(g_value_get_object (this->current)), true);
   }
   else
     return Glib::RefPtr<CppType>(0);
@@ -454,11 +456,11 @@ CppType* Iterator<CppType>::operator->() const
 {
   typedef typename CppType::BaseObjectType CType;
 
-  if(this->current)
+  if(G_IS_VALUE(this->current))
   {
     //Take extra reference when dereferencing.  The reference will disappear
     //when Glib::RefPtr<> is destroyed.
-    return Glib::wrap(static_cast<CType*>(this->current), true).operator->();
+    return Glib::wrap(static_cast<CType*>(g_value_get_object (this->current)), true).operator->();
   }
   else
     return static_cast<CppType*>(0);


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