Ubuntu TV Media Scanner
A centralized index for removable media content.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
mediascanner::Wrapper< T, CopyHelper > Class Template Reference

A shared smart-pointer for GLib related types. More...

#include <mediascanner/glibutils.h>

Public Member Functions

 Wrapper ()
 Creates an emtpy pointer not holding any object. More...
 
 Wrapper (const Wrapper< T > &other)
 Copies another pointer instance. More...
 
 ~Wrapper ()
 Destroys the smart-pointer. More...
 
T * release ()
 Releases the wrapped object. More...
 
T * get () const
 This function gives access to the wrapped object. More...
 
T * dup () const
 Creates a new reference to, or a new copy of the wrapped object. More...
 
template<typename B >
B * get () const
 This function casts the wrapped object to a different type. More...
 
T * operator-> () const
 This operator gives access to the wrapped object's members. More...
 
void reset (T *p=0)
 This function requests to wrap a different object. More...
 
void take (T *p)
 This function requests to take ownership of a different object. More...
 
T ** out_param ()
 Resets the smart-pointer and returns a pointer to the internal object pointer. More...
 
Wrapper< T > & operator= (T *p)
 The assignment operator is an alias of the reset() method. More...
 
Wrapper< T > & operator= (const Wrapper< T > &other)
 The assignment operator is an alias of the reset() method. More...
 
 operator const T * () const
 This operator casts the wrapped object to another type. More...
 
bool operator! () const
 This operator checks if this pointer actually wraps an object. More...
 
bool operator== (const T *p) const
 This operator compares two pointers for equality. More...
 
bool operator!= (const T *p) const
 This operator compares two pointers for inequality. More...
 

Detailed Description

template<typename T, typename CopyHelper = internal::CopyHelper<T>>
class mediascanner::Wrapper< T, CopyHelper >

A shared smart-pointer for GLib related types.

Via its helper classes this smart-pointer supports a wide variety of GLib related types, such as GObjects, GstMiniObjects, boxed types, and even simple GLists.

See Also
internal::CopyHelper, internal::CastHelper

Constructor & Destructor Documentation

template<typename T, typename CopyHelper = internal::CopyHelper<T>>
mediascanner::Wrapper< T, CopyHelper >::Wrapper ( )
inline

Creates an emtpy pointer not holding any object.

template<typename T, typename CopyHelper = internal::CopyHelper<T>>
mediascanner::Wrapper< T, CopyHelper >::Wrapper ( const Wrapper< T > &  other)
inline

Copies another pointer instance.

For reference counted objects this new pointer will hold a new reference to the object. For boxed types and similiar a new copy of the original object is created.

Parameters
otherThe instance to initialize from.
See Also
take(), wrap(), wrap_static()
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
mediascanner::Wrapper< T, CopyHelper >::~Wrapper ( )
inline

Destroys the smart-pointer.

For reference counted objects this drops the reference hold, for other types this frees the object instance.

Member Function Documentation

template<typename T, typename CopyHelper = internal::CopyHelper<T>>
T* mediascanner::Wrapper< T, CopyHelper >::dup ( ) const
inline

Creates a new reference to, or a new copy of the wrapped object.

This function is useful to initialize C structures or arrays.

Returns
A pointer to the new reference, or the new object.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
T* mediascanner::Wrapper< T, CopyHelper >::get ( ) const
inline

This function gives access to the wrapped object.

Returns
A pointer to the wrapped object.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
template<typename B >
B* mediascanner::Wrapper< T, CopyHelper >::get ( ) const
inline

This function casts the wrapped object to a different type.

Returns
A pointer to the wrapped object.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
mediascanner::Wrapper< T, CopyHelper >::operator const T * ( ) const
inline

This operator casts the wrapped object to another type.

This cast operator also serves as safe bool cast. The more natural operator bool() is problematic because it leads to unwanted implicit casts. Also note that there is no non-const "operatpr T *()" to avoid ambiguity problems for the compiler.

template<typename T, typename CopyHelper = internal::CopyHelper<T>>
bool mediascanner::Wrapper< T, CopyHelper >::operator! ( ) const
inline

This operator checks if this pointer actually wraps an object.

Returns
true if this pointer wraps an object.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
bool mediascanner::Wrapper< T, CopyHelper >::operator!= ( const T *  p) const
inline

This operator compares two pointers for inequality.

Parameters
pThe other pointer to compare with.
Returns
true if both pointers are not equal.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
T* mediascanner::Wrapper< T, CopyHelper >::operator-> ( ) const
inline

This operator gives access to the wrapped object's members.

Returns
A pointer to the wrapped object.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
Wrapper<T>& mediascanner::Wrapper< T, CopyHelper >::operator= ( T *  p)
inline

The assignment operator is an alias of the reset() method.

Parameters
pThe new object to store, or null
Returns
A reference to this smart-pointer.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
Wrapper<T>& mediascanner::Wrapper< T, CopyHelper >::operator= ( const Wrapper< T > &  other)
inline

The assignment operator is an alias of the reset() method.

Parameters
pThe new object to store, or null
Returns
A reference to this smart-pointer.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
bool mediascanner::Wrapper< T, CopyHelper >::operator== ( const T *  p) const
inline

This operator compares two pointers for equality.

Parameters
pThe other pointer to compare with.
Returns
true if both pointers are equal.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
T** mediascanner::Wrapper< T, CopyHelper >::out_param ( )
inline

Resets the smart-pointer and returns a pointer to the internal object pointer.

This is useful to wrap objects retreived by output parameters.

Returns
A pointer to the internal object pointer.
See Also
reset(), take()
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
T* mediascanner::Wrapper< T, CopyHelper >::release ( )
inline

Releases the wrapped object.

This detaches the wrapped object from this smart-pointer without dropping the reference or freeing it. Use this function to transfer ownership of the wrapped object.

Returns
A pointer to the wrapped object, or null if no object was wrapped.
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
void mediascanner::Wrapper< T, CopyHelper >::reset ( T *  p = 0)
inline

This function requests to wrap a different object.

If the wrapped objects are reference-counted, the reference to the old object is dropped, and a reference to the new object is stored. For other types the old object is freed and a copy of the new object is stored.

Parameters
pThe new object to store, or null.
See Also
take(), out_param()
template<typename T, typename CopyHelper = internal::CopyHelper<T>>
void mediascanner::Wrapper< T, CopyHelper >::take ( T *  p)
inline

This function requests to take ownership of a different object.

If the wrapped objects are reference-counted, the reference to the old object is dropped, for other types the old object is freed. As this function takes ownership of the passed object, no new reference is created, and no copy is created.

Parameters
pThe new object to store, or null.
See Also
reset(), out_param()