cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RefPtr< T > Class Template Reference

Wrapper class which maintains a strong reference to a cocos2dx cocos2d::Ref* type object. More...

#include <CCRefPtr.h>

Public Member Functions

 RefPtr ()
 
 RefPtr (RefPtr< T > &&other)
 
 RefPtr (T *ptr)
 
 RefPtr (std::nullptr_t ptr)
 
 RefPtr (const RefPtr< T > &other)
 
 ~RefPtr ()
 
RefPtr< T > & operator= (const RefPtr< T > &other)
 
RefPtr< T > & operator= (RefPtr< T > &&other)
 
RefPtr< T > & operator= (T *other)
 
RefPtr< T > & operator= (std::nullptr_t other)
 
 operator T * () const
 
T & operator* () const
 
T * operator-> () const
 
T * get () const
 
bool operator== (const RefPtr< T > &other) const
 
bool operator== (const T *other) const
 
bool operator== (typename std::remove_const< T >::type *other) const
 
bool operator== (const std::nullptr_t other) const
 
bool operator!= (const RefPtr< T > &other) const
 
bool operator!= (const T *other) const
 
bool operator!= (typename std::remove_const< T >::type *other) const
 
bool operator!= (const std::nullptr_t other) const
 
bool operator> (const RefPtr< T > &other) const
 
bool operator> (const T *other) const
 
bool operator> (typename std::remove_const< T >::type *other) const
 
bool operator> (const std::nullptr_t other) const
 
bool operator< (const RefPtr< T > &other) const
 
bool operator< (const T *other) const
 
bool operator< (typename std::remove_const< T >::type *other) const
 
bool operator< (const std::nullptr_t other) const
 
bool operator>= (const RefPtr< T > &other) const
 
bool operator>= (const T *other) const
 
bool operator>= (typename std::remove_const< T >::type *other) const
 
bool operator>= (const std::nullptr_t other) const
 
bool operator<= (const RefPtr< T > &other) const
 
bool operator<= (const T *other) const
 
bool operator<= (typename std::remove_const< T >::type *other) const
 
bool operator<= (const std::nullptr_t other) const
 
 operator bool () const
 
void reset ()
 
void swap (RefPtr< T > &other)
 
void weakAssign (const RefPtr< T > &other)
 This function assigns to this RefPtr<T> but does not increase the reference count of the object pointed to. More...
 

Detailed Description

template<typename T>
class cocos2d::RefPtr< T >

Wrapper class which maintains a strong reference to a cocos2dx cocos2d::Ref* type object.

Similar in concept to a boost smart pointer.

Enables the use of the RAII idiom with Cocos2dx objects and helps automate some of the more mundane tasks of pointer initialization and cleanup.

The class itself is modelled on C++ 11 std::shared_ptr, and trys to keep some of the methods and functionality consistent with std::shared_ptr.

Constructor & Destructor Documentation

RefPtr ( )
inline
RefPtr ( RefPtr< T > &&  other)
inline
RefPtr ( T *  ptr)
inline
RefPtr ( std::nullptr_t  ptr)
inline
RefPtr ( const RefPtr< T > &  other)
inline
~RefPtr ( )
inline

Member Function Documentation

T* get ( ) const
inline
operator bool ( ) const
inline
operator T * ( ) const
inline
bool operator!= ( const RefPtr< T > &  other) const
inline
bool operator!= ( const T *  other) const
inline
bool operator!= ( typename std::remove_const< T >::type *  other) const
inline
bool operator!= ( const std::nullptr_t  other) const
inline
T& operator* ( ) const
inline
T* operator-> ( ) const
inline
bool operator< ( const RefPtr< T > &  other) const
inline
bool operator< ( const T *  other) const
inline
bool operator< ( typename std::remove_const< T >::type *  other) const
inline
bool operator< ( const std::nullptr_t  other) const
inline
bool operator<= ( const RefPtr< T > &  other) const
inline
bool operator<= ( const T *  other) const
inline
bool operator<= ( typename std::remove_const< T >::type *  other) const
inline
bool operator<= ( const std::nullptr_t  other) const
inline
RefPtr<T>& operator= ( const RefPtr< T > &  other)
inline
RefPtr<T>& operator= ( RefPtr< T > &&  other)
inline
RefPtr<T>& operator= ( T *  other)
inline
RefPtr<T>& operator= ( std::nullptr_t  other)
inline
bool operator== ( const RefPtr< T > &  other) const
inline
bool operator== ( const T *  other) const
inline
bool operator== ( typename std::remove_const< T >::type *  other) const
inline
bool operator== ( const std::nullptr_t  other) const
inline
bool operator> ( const RefPtr< T > &  other) const
inline
bool operator> ( const T *  other) const
inline
bool operator> ( typename std::remove_const< T >::type *  other) const
inline
bool operator> ( const std::nullptr_t  other) const
inline
bool operator>= ( const RefPtr< T > &  other) const
inline
bool operator>= ( const T *  other) const
inline
bool operator>= ( typename std::remove_const< T >::type *  other) const
inline
bool operator>= ( const std::nullptr_t  other) const
inline
void reset ( )
inline
void swap ( RefPtr< T > &  other)
inline
void weakAssign ( const RefPtr< T > &  other)
inline

This function assigns to this RefPtr<T> but does not increase the reference count of the object pointed to.

Useful for assigning an object created through the 'new' operator to a RefPtr<T>. Basically used in scenarios where the RefPtr<T> has the initial ownership of the object.

E.G: RefPtr<cocos2d::Image> image; image.weakAssign(new cocos2d::Image());

Instead of: RefPtr<cocos2d::Image> image; image = new cocos2d::Image(); image->release(); // Required because new'd object already has a reference count of '1'.


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