NAP
Public Member Functions | List of all members
ComponentPtr< ComponentType > Class Template Reference

#include <component.h>

Public Member Functions

 ComponentPtr ()=default
 
 ComponentPtr (ComponentType *component)
 
const std::string & getInstancePath () const
 
virtual std::string toString () const override
 
virtual ComponenttoObject () const override
 
virtual void assign (const std::string &targetID, rtti::Object *targetObject) override
 
ComponentType * get () const
 
ComponentType * get ()
 
const ComponentType & operator* () const
 
ComponentType & operator* ()
 
const ComponentType * operator-> () const
 
ComponentType * operator-> ()
 
bool operator== (const ComponentPtr< ComponentType > &other) const
 
template<typename OTHER >
bool operator== (const ComponentPtr< OTHER > &other) const
 
template<typename OTHER >
bool operator== (const OTHER *ptr) const
 
bool operator== (std::nullptr_t) const
 
bool operator!= (const ComponentPtr< ComponentType > &other) const
 
template<typename OTHER >
bool operator!= (const ComponentPtr< OTHER > &other) const
 
template<typename OTHER >
bool operator!= (const OTHER *ptr) const
 
bool operator!= (std::nullptr_t) const
 
bool operator< (const ComponentPtr< ComponentType > &other) const
 
bool operator> (const ComponentPtr< ComponentType > &other) const
 
bool operator<= (const ComponentPtr< ComponentType > &other) const
 
bool operator>= (const ComponentPtr< ComponentType > &other) const
 

Description

template<class ComponentType>
class nap::ComponentPtr< ComponentType >

Typed version of ComponentPtrBase. ComponentPtr stores the path and the pointer to the target resource.

When pointing to other other components through ComponentPtrs, you can do so using a 'path' to the target component. This path can be of two forms:

Paths consisting out of multiple elements can be either relative or absolute and come in three forms:

When there are ChildEntityIDs on the path, it's possible for the ChildEntityID to be ambiguous (for example, when an entity has multiple children with the same ID). For example, consider the following entity hierarchy:

CarEntity -> WheelEntity -> TransformComponent -> WheelEntity -> TransformComponent -> WheelEntity -> TransformComponent -> WheelEntity -> TransformComponent

Pointing directly to one of these TransformComponents using a component path is not possible, because it would be ambiguous. To disambiguate which specific child entity is meant, the user can append a ':[child_index]' to the ChildEntityID on the path.

In this case, to point to the TransformComponent of the second wheel, the user would use the following path: './WheelEntity:1/TransformComponent'

Constructor & Destructor Documentation

◆ ComponentPtr() [1/2]

ComponentPtr ( )
default

◆ ComponentPtr() [2/2]

ComponentPtr ( ComponentType *  component)

Member Function Documentation

◆ assign()

void assign ( const std::string &  targetID,
rtti::Object targetObject 
)
overridevirtual

Assign the path to the component (including ID) and object to this pointer. Used for pointer resolving by the ResourceManager. Should not be called manually (is only public so that we can register it in RTTI)

Parameters
targetIDpath to the target component including ID, empty to clear
targetObjectThe component to assign, nullptr to clear

◆ get() [1/2]

ComponentType* get ( )
Returns
the raw pointer of the target component

◆ get() [2/2]

ComponentType* get ( ) const
Returns
the raw pointer of the target component

◆ getInstancePath()

const std::string& getInstancePath ( ) const

Returns the path to the target component including component ID

Returns
the path to the target component including component ID

◆ operator!=() [1/4]

bool operator!= ( const ComponentPtr< ComponentType > &  other) const

◆ operator!=() [2/4]

bool operator!= ( const ComponentPtr< OTHER > &  other) const

◆ operator!=() [3/4]

bool operator!= ( const OTHER *  ptr) const

◆ operator!=() [4/4]

bool operator!= ( std::nullptr_t  ) const

◆ operator*() [1/2]

ComponentType& operator* ( )

◆ operator*() [2/2]

const ComponentType& operator* ( ) const

◆ operator->() [1/2]

ComponentType* operator-> ( )

◆ operator->() [2/2]

const ComponentType* operator-> ( ) const

◆ operator<()

bool operator< ( const ComponentPtr< ComponentType > &  other) const

◆ operator<=()

bool operator<= ( const ComponentPtr< ComponentType > &  other) const

◆ operator==() [1/4]

bool operator== ( const ComponentPtr< ComponentType > &  other) const

◆ operator==() [2/4]

bool operator== ( const ComponentPtr< OTHER > &  other) const

◆ operator==() [3/4]

bool operator== ( const OTHER *  ptr) const

◆ operator==() [4/4]

bool operator== ( std::nullptr_t  ) const

◆ operator>()

bool operator> ( const ComponentPtr< ComponentType > &  other) const

◆ operator>=()

bool operator>= ( const ComponentPtr< ComponentType > &  other) const

◆ toObject()

virtual Component* toObject ( ) const
overridevirtual

Returns the assigned component

Returns
The rtti object, nullptr if it doesn't exist

◆ toString()

virtual std::string toString ( ) const
overridevirtual

Convert the path to a string for serialization

Returns
The string representation of this object