QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
QGlib::RefPointer< T > Class Template Reference

#include <QGlib/RefPointer>

Public Member Functions

 RefPointer (T *cppClass)
 
template<class X >
 RefPointer (const RefPointer< X > &other)
 
 RefPointer (const RefPointer< T > &other)
 
template<class X >
RefPointer< T > & operator= (const RefPointer< X > &other)
 
RefPointer< T > & operator= (const RefPointer< T > &other)
 
template<class X >
bool operator== (const X &other) const
 
template<class X >
bool operator!= (const X &other) const
 
void clear ()
 
bool isNull () const
 
bool operator! () const
 
T * operator-> () const
 
 operator typename T::CType * () const
 
template<class X >
RefPointer< X > staticCast () const
 
template<class X >
RefPointer< X > dynamicCast () const
 

Static Public Member Functions

static RefPointer< T > wrap (typename T::CType *nativePtr, bool increaseRef=true)
 

Related Functions

(Note that these are not member functions.)

template<class T , class X >
boost::enable_if_c
< boost::is_pointer< X >
::value &&!boost::is_same< X,
typename boost::add_pointer
< typename T::CType >::type >
::value, bool >::type 
operator== (const X &other, const RefPointer< T > &self)
 
template<class T , class X >
boost::enable_if_c
< boost::is_pointer< X >
::value &&!boost::is_same< X,
typename boost::add_pointer
< typename T::CType >::type >
::value, bool >::type 
operator!= (const X &other, const RefPointer< T > &self)
 
template<typename T >
uint qHash (const RefPointer< T > &ptr)
 

Detailed Description

template<class T>
class QGlib::RefPointer< T >

Smart pointer class for working with wrapper classes that support reference counting.

Nearly all GObject and GStreamer classes are designed to work with reference counting. This class provides a smart pointer for instances of those classes which takes care of increasing and decreasing the reference count automatically when a new pointer is constructed and destructed, respectively.

All wrapper classes that wrap reference-counted objects must be used with RefPointer. For convenience, this library provides typedefs for all the reference-counted wrappers, which are in the form:

typedef RefPointer<Foo> FooPtr;

So, for example, if you want to use an instance of a QGst::Element, you should declare a pointer to it like that:

Examples:
examples/appsink-src/main.cpp, examples/player/main.cpp, examples/qmlplayer/main.cpp, examples/recorder/main.cpp, and examples/voip/main.cpp.

Definition at line 56 of file global.h.

Constructor & Destructor Documentation

template<class T>
QGlib::RefPointer< T >::RefPointer ( T *  cppClass)
inlineexplicit

Definition at line 217 of file refpointer.h.

Member Function Documentation

template<class T >
template<class X >
bool QGlib::RefPointer< T >::operator== ( const X &  other) const

This operator allows you to compare a RefPointer to either another RefPointer or to a pointer of a C object. For example:

GObject *object = g_object_new(...);
if (objectPtr == object) {
//this code will be executed, the comparison returns true
}
Note
Although this is a template, you cannot compare to anything else other than a RefPointer or a C instance pointer.

Definition at line 271 of file refpointer.h.

template<class T >
template<class X >
bool QGlib::RefPointer< T >::operator!= ( const X &  other) const
See also
operator==()

Definition at line 278 of file refpointer.h.

template<class T >
void QGlib::RefPointer< T >::clear ( )

Sets this RefPointer to NULL and drops the reference to the object that it was previously pointing at.

Definition at line 316 of file refpointer.h.

template<class T >
QGlib::RefPointer< T >::operator typename T::CType * ( ) const
inline

Cast operator that implicitly casts the smart pointer to the pointer type of the underlying C instance. For example, RefPointer<QGst::Element> will cast to GstElement*. This is provided as a helper tool for working with native C methods if needed.

Note
the returned pointer does not have an increased reference count

Definition at line 359 of file refpointer.h.

template<class T>
RefPointer< T > QGlib::RefPointer< T >::wrap ( typename T::CType *  nativePtr,
bool  increaseRef = true 
)
static

Makes a RefPointer out of a pointer to a native C instance. If increaseRef is specified as false, the reference count is not increased on construction (but it is decreased on destruction!).

Definition at line 326 of file refpointer.h.

template<class T >
template<class X >
RefPointer< X > QGlib::RefPointer< T >::staticCast ( ) const
template<class T >
template<class X >
RefPointer< X > QGlib::RefPointer< T >::dynamicCast ( ) const

Dynamically casts this RefPointer to a RefPointer of another class. This is equivalent to the built-in dynamic_cast, but it additionally allows you to cast objects to interfaces that they implement and vice-versa by using the Glib type system to determine if the cast is allowed or not. If the cast fails, it returns a null RefPointer.

For example, you can do:

QGst::ElementPtr filesrc = QGst::ElementFactory::make("filesrc");

because a "filesrc" element implements the GstUriHandler interface.

Examples:
examples/player/main.cpp.

Definition at line 462 of file refpointer.h.

Friends And Related Function Documentation

template<class T , class X >
boost::enable_if_c< boost::is_pointer< X >::value &&!boost::is_same< X, typename boost::add_pointer< typename T::CType >::type >::value, bool >::type operator== ( const X &  other,
const RefPointer< T > &  self 
)
related
See also
RefPointer::operator==()

Definition at line 294 of file refpointer.h.

template<class T , class X >
boost::enable_if_c< boost::is_pointer< X >::value &&!boost::is_same< X, typename boost::add_pointer< typename T::CType >::type >::value, bool >::type operator!= ( const X &  other,
const RefPointer< T > &  self 
)
related
See also
RefPointer::operator==()

Definition at line 310 of file refpointer.h.

template<typename T >
uint qHash ( const RefPointer< T > &  ptr)
related

Definition at line 492 of file refpointer.h.


The documentation for this class was generated from the following files: