GameObjectHandle< T > Class Template Reference

Description

template<typename T>
class bs::GameObjectHandle< T >

A handle that can point to various types of game objects.

It primarily keeps track if the object is still alive, so anything still referencing it doesn't accidentally use it.

Note
This class exists because references between game objects should be quite loose. For example one game object should be able to reference another one without the other one knowing. But if that is the case I also need to handle the case when the other object we're referencing has been deleted, and that is the main purpose of this class.
It is important this class contains no data since we often value cast it to its base.

Inherits GameObjectHandleBase.

Methods

 GameObjectHandle ()
 Constructs a new empty handle. More...
 
template<typename T1 >
 GameObjectHandle (const GameObjectHandle< T1 > &ptr)
 Copy constructor from another handle of the same type. More...
 
 GameObjectHandle (const GameObjectHandleBase &ptr)
 Copy constructor from another handle of the base type. More...
 
GameObjectHandle< T > & operator= (std::nullptr_t ptr)
 Invalidates the handle. More...
 
T * get () const
 Returns a pointer to the referenced GameObject. More...
 
SPtr< T > getInternalPtr () const
 Returns a smart pointer to the referenced GameObject. More...
 
T * operator-> () const
 Returns pointer to the referenced GameObject. More...
 
T & operator* () const
 Returns reference to the referenced GameObject. More...
 
Internal
 operator int Bool_struct< T >::* () const
 Allows direct conversion of handle to bool. More...
 
- Methods inherited from GameObjectHandleBase
bool isDestroyed (bool checkQueued=false) const
 Returns true if the object the handle is pointing to has been destroyed. More...
 
UINT64 getInstanceId () const
 Returns the instance ID of the object the handle is referencing. More...
 
GameObjectget () const
 Returns pointer to the referenced GameObject. More...
 
SPtr< GameObjectgetInternalPtr () const
 Returns a smart pointer to the referenced GameObject. More...
 
GameObjectoperator-> () const
 Returns pointer to the referenced GameObject. More...
 
GameObjectoperator* () const
 Returns reference to the referenced GameObject. More...
 
virtual RTTITypeBasegetRTTI () const override
 Returns an interface you can use to access class' Run Time Type Information. More...
 
SPtr< GameObjectHandleData_getHandleData () const
 Returns internal handle data. More...
 
void _resolve (const GameObjectHandleBase &object)
 Resolves a handle to a proper GameObject in case it was created uninitialized. More...
 
void _setHandleData (const SPtr< GameObject > &object)
 Changes the GameObject instance the handle is pointing to. More...
 
- Methods inherited from IReflectable
bool isDerivedFrom (RTTITypeBase *base)
 Returns true if current RTTI class is derived from base (Or if it is the same type as base). More...
 
UINT32 getTypeId () const
 Returns an unique type identifier of the class. More...
 
const StringgetTypeName () const
 Returns the type name of the class. More...
 

Additional Inherited Members

- Static methods inherited from GameObjectHandleBase
static RTTITypeBasegetRTTIStatic ()
 
- Static methods inherited from IReflectable
static Vector< RTTITypeBase * > & getDerivedClasses ()
 Returns all classes deriving directly from IReflectable. More...
 
static SPtr< IReflectablecreateInstanceFromTypeId (UINT32 rttiTypeId)
 Creates an empty instance of a class from a type identifier. More...
 
static void _registerDerivedClass (RTTITypeBase *derivedClass)
 Called by each type deriving from IReflectable, on program load. More...
 
static RTTITypeBase_getRTTIfromTypeId (UINT32 rttiTypeId)
 Returns class' RTTI type from type id. More...
 
static bool _isTypeIdDuplicate (UINT32 typeId)
 Checks if the provided type id is unique. More...
 
static void _checkForCircularReferences ()
 Iterates over all RTTI types and reports any circular references (for example one type having a field referencing another type, and that type having a field referencing the first type). More...
 
static RTTITypeBasegetRTTIStatic ()
 Returns an interface you can use to access class' Run Time Type Information. More...
 

Method documentation

T* get ( ) const

Returns a pointer to the referenced GameObject.

Note
Throws exception if the GameObject was destroyed.
SPtr<T> getInternalPtr ( ) const

Returns a smart pointer to the referenced GameObject.

Note
Throws exception if the GameObject was destroyed.
operator int Bool_struct< T >::* ( ) const

Allows direct conversion of handle to bool.

Note
This is needed because we can't directly convert to bool since then we can assign pointer to bool and that's weird.
T& operator* ( ) const

Returns reference to the referenced GameObject.

Note
Throws exception if the GameObject was destroyed.
T* operator-> ( ) const

Returns pointer to the referenced GameObject.

Note
Throws exception if the GameObject was destroyed.
GameObjectHandle<T>& operator= ( std::nullptr_t  ptr)

Invalidates the handle.

Constructor & Destructor Documentation

Constructs a new empty handle.

GameObjectHandle ( const GameObjectHandle< T1 > &  ptr)

Copy constructor from another handle of the same type.

Copy constructor from another handle of the base type.