MAGE  v0.171.0
Matthias Advanced Game Engine
mage::Node Class Reference

#include <node.hpp>

Public Types

using NodePtr = ProxyPtr< Node >
 
using ComponentPtr = ProxyPtr< Component >
 

Public Member Functions

 Node (std::string name="")
 
 Node (const Node &node)
 
 Node (Node &&node) noexcept
 
virtual ~Node ()
 
Nodeoperator= (const Node &node)=delete
 
Nodeoperator= (Node &&node) noexcept
 
TransformGetTransform () noexcept
 
const TransformGetTransform () const noexcept
 
bool HasParent () const noexcept
 
NodePtr GetParent () const noexcept
 
std::size_t GetNumberOfChilds () const noexcept
 
bool ContainsChilds () const
 
bool ContainsChild (ProxyPtr< const Node > node) const
 
void AddChild (NodePtr node)
 
void RemoveChild (NodePtr node)
 
void RemoveAllChilds () noexcept
 
template<typename ActionT >
void ForEachChild (ActionT &&action) const
 
template<typename ActionT >
void ForEachDescendant (ActionT &&action) const
 
template<typename ComponentT >
bool Contains () const noexcept
 
bool ContainsComponents () const noexcept
 
std::size_t GetNumberOfComponents () const noexcept
 
template<typename ComponentT >
std::size_t GetNumberOf () const noexcept
 
template<typename ComponentT >
ProxyPtr< ComponentT > Get () noexcept
 
template<typename ComponentT >
ProxyPtr< const ComponentT > Get () const noexcept
 
template<typename ComponentT >
const std::vector< ProxyPtr< ComponentT > > GetAll ()
 
template<typename ComponentT >
const std::vector< ProxyPtr< const ComponentT > > GetAll () const
 
template<typename ComponentT >
void Add (ProxyPtr< ComponentT > component)
 
template<typename ComponentT , typename ActionT >
void ForEach (ActionT &&action)
 
template<typename ComponentT , typename ActionT >
void ForEach (ActionT &&action) const
 
template<typename ActionT >
void ForEachComponent (ActionT &&action)
 
template<typename ActionT >
void ForEachComponent (ActionT &&action) const
 
State GetState () const noexcept
 
void SetState (State state) noexcept
 
U64 GetGuid () const noexcept
 
NodePtr Get () const noexcept
 
const std::string_view GetName () const noexcept
 
void SetName (std::string name) noexcept
 
void Set (NodePtr ptr) noexcept
 

Private Attributes

Transform m_transform
 
NodePtr m_parent
 
std::vector< NodePtrm_childs
 
std::unordered_multimap< std::type_index, ComponentPtrm_components
 
State m_state
 
U64 m_guid
 
NodePtr m_this
 
std::string m_name
 

Detailed Description

A class of nodes.

Member Typedef Documentation

◆ ComponentPtr

A pointer to a component.

◆ NodePtr

A pointer to a node.

Constructor & Destructor Documentation

◆ Node() [1/3]

mage::Node::Node ( std::string  name = "")
explicit

Constructs a node.

Parameters
[in]nameThe name of the node.

◆ Node() [2/3]

mage::Node::Node ( const Node node)

Constructs a node from the given node.

Parameters
[in]nodeA reference to the node.

◆ Node() [3/3]

mage::Node::Node ( Node &&  node)
noexcept

Constructs a node by moving the given node.

Parameters
[in]nodeA reference to the node to move.

◆ ~Node()

mage::Node::~Node ( )
virtualdefault

Destructs this node.

Member Function Documentation

◆ Add()

template<typename ComponentT >
void mage::Node::Add ( ProxyPtr< ComponentT >  component)

Adds the given component to this node.

Template Parameters
ComponentTThe component type.
Parameters
[in]componentA pointer to the component.

◆ AddChild()

void mage::Node::AddChild ( NodePtr  node)

Adds the given node to the childs of this node.

Parameters
[in]nodeA pointer to the node.

◆ Contains()

template<typename ComponentT >
bool mage::Node::Contains ( ) const
noexcept

Checks whether this node contains a component of the given type.

Template Parameters
ComponentTThe component type.
Returns
true if this node contains at least one component of the given type. false otherwise.

◆ ContainsChild()

bool mage::Node::ContainsChild ( ProxyPtr< const Node node) const

Checks whether this node contains the given node as a child.

Parameters
[in]nodeA pointer to the node.
Returns
true if this node contains the given node as a child. false otherwise.

◆ ContainsChilds()

bool mage::Node::ContainsChilds ( ) const

Checks whether this node contains childs.

Returns
true if this node contains at least one child. false otherwise.

◆ ContainsComponents()

bool mage::Node::ContainsComponents ( ) const
noexcept

Checks whether this node contains components.

Returns
true if this node contains at least one component. false otherwise.

◆ ForEach() [1/2]

template<typename ComponentT , typename ActionT >
void mage::Node::ForEach ( ActionT &&  action)

Traverses all components of the given type of this node.

Template Parameters
ComponentTThe component type.
ActionTAn action to perform on all components of the given type of this node. The action must accept ComponentT& values.
Parameters
[in]actionThe action.

◆ ForEach() [2/2]

template<typename ComponentT , typename ActionT >
void mage::Node::ForEach ( ActionT &&  action) const

Traverses all components of the given type of this node.

Template Parameters
ComponentTThe component type.
ActionTAn action to perform on all components of the given type of this node. The action must accept const ComponentT& values.
Parameters
[in]actionThe action.

◆ ForEachChild()

template<typename ActionT >
void mage::Node::ForEachChild ( ActionT &&  action) const

Traverses all childs of this node.

Template Parameters
ActionTAn action to perform on all childs of this node. The action must accept Node& values.
Parameters
[in]actionThe action.

◆ ForEachComponent() [1/2]

template<typename ActionT >
void mage::Node::ForEachComponent ( ActionT &&  action)

Traverses all components of this node.

Template Parameters
ActionTAn action to perform on all components of this node. The action must accept Component& values.
Parameters
[in]actionThe action.

◆ ForEachComponent() [2/2]

template<typename ActionT >
void mage::Node::ForEachComponent ( ActionT &&  action) const

Traverses all components of this node.

Template Parameters
ActionTAn action to perform on all components of this node. The action must accept const Component& values.
Parameters
[in]actionThe action.

◆ ForEachDescendant()

template<typename ActionT >
void mage::Node::ForEachDescendant ( ActionT &&  action) const

Traverses all descendants (childs included) of this node.

Template Parameters
ActionTAn action to perform on all descendants of this node. The action must accept Node& values.
Parameters
[in]actionThe action.

◆ Get() [1/3]

template<typename ComponentT >
ProxyPtr< ComponentT > mage::Node::Get ( )
noexcept

Returns the first component of the given type of this node.

Template Parameters
ComponentTThe component type.
Returns
nullptr if this node has no component of the given type.
A pointer to the first component of the given type of this node.

◆ Get() [2/3]

template<typename ComponentT >
ProxyPtr< const ComponentT > mage::Node::Get ( ) const
noexcept

Returns the first component of the given type of this node.

Template Parameters
ComponentTThe component type.
Returns
nullptr if this node has no component of the given type.
A pointer to the first component of the given type of this node.

◆ Get() [3/3]

NodePtr mage::Node::Get ( ) const
noexcept

Returns a pointer to this node.

Returns
A pointer to this node.

◆ GetAll() [1/2]

template<typename ComponentT >
const std::vector< ProxyPtr< ComponentT > > mage::Node::GetAll ( )

Returns all components of the given type of this node.

Template Parameters
ComponentTThe component type.
Returns
A vector containing all components of the given type of this node.

◆ GetAll() [2/2]

template<typename ComponentT >
const std::vector< ProxyPtr< const ComponentT > > mage::Node::GetAll ( ) const

Returns all components of the given type of this node.

Template Parameters
ComponentTThe component type.
Returns
A vector containing all components of the given type of this node.

◆ GetGuid()

U64 mage::Node::GetGuid ( ) const
noexcept

Returns the guid of this node.

Returns
The guid of this node.

◆ GetName()

const std::string_view mage::Node::GetName ( ) const
noexcept

Returns the name of this node.

Returns
The name of this node.

◆ GetNumberOf()

template<typename ComponentT >
std::size_t mage::Node::GetNumberOf ( ) const
noexcept

Returns the number of components of the given type of this node.

Template Parameters
ComponentTThe component type.
Returns
The number of components of the given type of this node.

◆ GetNumberOfChilds()

std::size_t mage::Node::GetNumberOfChilds ( ) const
noexcept

Returns the number of childs of this node.

Returns
The number of childs of this node.

◆ GetNumberOfComponents()

std::size_t mage::Node::GetNumberOfComponents ( ) const
noexcept

Returns the number of components of this node.

Returns
The number of components of this node.

◆ GetParent()

NodePtr mage::Node::GetParent ( ) const
noexcept

Returns the parent of this node.

Returns
A pointer to the parent of this node.

◆ GetState()

State mage::Node::GetState ( ) const
noexcept

Returns the state of this node.

Returns
The state of this node.

◆ GetTransform() [1/2]

Transform& mage::Node::GetTransform ( )
noexcept

Returns the transform of this node.

Returns
A reference to the transform of this node.

◆ GetTransform() [2/2]

const Transform& mage::Node::GetTransform ( ) const
noexcept

Returns the transform of this node.

Returns
A reference to the transform of this node.

◆ HasParent()

bool mage::Node::HasParent ( ) const
noexcept

Checks whether this node has a parent.

Returns
true if this node has a parent. false otherwise.

◆ operator=() [1/2]

Node& mage::Node::operator= ( const Node node)
delete

Copies the given node to this node.

Parameters
[in]nodeA reference to the node to copy.
Returns
A reference to the copy of the given node (i.e. this node).

◆ operator=() [2/2]

Node & mage::Node::operator= ( Node &&  node)
defaultnoexcept

Moves the given node to this node.

Parameters
[in]nodeA reference to the node to move.
Returns
A reference to the moved node (i.e. this node).

◆ RemoveAllChilds()

void mage::Node::RemoveAllChilds ( )
noexcept

Removes all childs from this node.

◆ RemoveChild()

void mage::Node::RemoveChild ( NodePtr  node)

Removes the given node from the childs of this node.

Parameters
[in]nodeA pointer to the node.

◆ Set()

void mage::Node::Set ( NodePtr  ptr)
noexcept

Sets the pointer of this node to the given pointer.

Parameters
[in]ptrThe pointer.

◆ SetName()

void mage::Node::SetName ( std::string  name)
noexcept

Sets the name of this node to the given string.

Parameters
[in]nameThe name.

◆ SetState()

void mage::Node::SetState ( State  state)
noexcept

Sets the state of this node to the given state.

Parameters
[in]stateThe state.

Member Data Documentation

◆ m_childs

std::vector< NodePtr > mage::Node::m_childs
private

A vector containing pointers to the the childs of this node.

◆ m_components

std::unordered_multimap< std::type_index, ComponentPtr > mage::Node::m_components
private

A multimap containing pointers to the components of this node as values with their associated type as key.

◆ m_guid

U64 mage::Node::m_guid
private

The guid of this node.

◆ m_name

std::string mage::Node::m_name
private

The name of this node.

◆ m_parent

NodePtr mage::Node::m_parent
private

A pointer to the parent of this node.

◆ m_state

State mage::Node::m_state
private

The state of this node.

◆ m_this

NodePtr mage::Node::m_this
private

A pointer to this node.

◆ m_transform

Transform mage::Node::m_transform
private

The transform of this node.