Class Ref<T>

#include <Geode/utils/cocos.hpp>
template<class T>classRef{ ... }

A smart pointer to a managed CCObject-deriving class. Retains shared ownership over the managed instance. Releases the object when the Ref is destroyed, or assigned another object or nullptr.

Use-cases include, for example, non-CCNode class members, or nodes that are not always in the scene tree.

Template parameters

T

A type that inherits from CCObject.
Examples2
class MyNode : public CCNode {
protected:
     // no need to manually call retain or
     // release on this array; Ref manages it
     // for you :3
     Ref<CCArray> m_list = CCArray::create();

     bool init() {
         if (!CCNode::init())
             return false;

         // No need to do m_list = CCArray::create()
         // or m_list->retain() :3

         return true;
     }
};
// Save a child from the current layer into a menu
Ref<CCMenu> menu = static_cast<CCMenu*>(this->getChildByID("main-menu"));

// Remove the menu from its parent
menu->removeFromParent();

// Menu will still point to a valid CCMenu as long as the menu variable exist
Public static methods1
staticgeode::Ref<T>adopt(
T*obj
)

Construct a Ref of an object, without retaining it. The object will still be released when Ref goes out of scope.

Parameters

obj

Object to construct the Ref from
Public member functions16
voidswap(
T*other
)

Swap the managed object with another object. The managed object will be released, and the new object retained

Parameters

other

The new object to swap to
T*take()

Takes out the object from the Ref, without calling release on it. This is like a symmetric counterpart to Ref::adopt, it essentially “leaks” the object, making the Ref empty and making you responsible for releasing it manually.

Return value
The managed object
T*data()const

Return the managed object

Return value
The managed object
T*operator*()const
No description provided
T*operator->()const
No description provided
T*operator=(
T*obj
)
No description provided
geode::Ref<T>&operator=(
geode::Ref<T>const&other
)
No description provided
geode::Ref<T>&operator=(
geode::Ref<T>&&other
)
No description provided
booloperator==(
T*other
)
const
No description provided
booloperator==(
geode::Ref<T>const&other
)
const
No description provided
booloperator!=(
T*other
)
const
No description provided
booloperator!=(
geode::Ref<T>const&other
)
const
No description provided
booloperator<(
geode::Ref<T>const&other
)
const
No description provided
booloperator<=(
geode::Ref<T>const&other
)
const
No description provided
booloperator>(
geode::Ref<T>const&other
)
const
No description provided
booloperator>=(
geode::Ref<T>const&other
)
const
No description provided
Fields0
Protected member functions0
Protected fields0