Node

High-level node management utilities.

Overview

Typical use cases:

  • Managing hierarchical node structures.

Header

<RaeptorCogs/Node.hpp>

Metadata

Author

Estorc

Version

v1.0

Copyright

Copyright (c) 2025 Estorc MIT License.

Structs

Structures

Struct

Description

RaeptorCogs::RegisterNode

RegisterNode struct.

template<typename Derived, typename Base>
struct RegisterNode : public Base

RegisterNode struct.

Template struct to register a derived node type and update its class IDs.

class MyNode : public RaeptorCogs::RegisterNode<MyNode, RaeptorCogs::Node> {};

Template Parameters:
  • Derived – The derived node type.

  • Base – The base node type.

Public Functions

inline BitArray getClassIds() const override

Get the class IDs BitArray for this node.

Returns:

BitArray representing the class IDs of this node.

Classes

Classes

Class

Description

RaeptorCogs::Node

Node class.

class Node

Node class.

Represents a node in a hierarchical structure and provides utilities for managing parent-child relationships and type identification.

class MyNode : public RaeptorCogs::RegisterNode<MyNode, RaeptorCogs::Node> {};
RaeptorCogs::Node* root = new RaeptorCogs::Node();
RaeptorCogs::Node* child = new MyNode();
root->addChild(child);
bool isMyNode = child->isInstanceOf<MyNode>(); // true

Subclassed by RaeptorCogs::RegisterNode< Component, Node >, RaeptorCogs::RegisterNode< Graphic2D, Node >

Public Functions

Node() = default

Default constructor for Node.

virtual ~Node()

Destructor for Node.

inline virtual BitArray getClassIds() const

Get the class IDs BitArray for this node.

Returns:

BitArray representing the class IDs of this node.

template<typename T>
inline bool isInstanceOf() const

Check if this node is an instance of the specified type.

bool isMyNode = node->isInstanceOf<MyNode>(); // true if node is of type MyNode

Template Parameters:

T – The type to check against.

Returns:

true if this node is an instance of type T, false otherwise.

void addChild(Node *child)

Add a child node.

Note

Sets the parent of the child node to this node.

Parameters:

child – Pointer to the child node to add.

void removeChild(Node *child)

Remove a child node.

Note

Sets the parent of the child node to nullptr.

Parameters:

child – Pointer to the child node to remove.

const std::vector<Node*> &getChildren() const

Get the child nodes.

Note

The returned vector is const to prevent modification of the child nodes.

Returns:

Vector of pointers to the child nodes.

Node *getParent() const

Get the parent node.

Returns:

Pointer to the parent node, or nullptr if this node has no parent.

Public Static Functions

template<typename T>
static inline size_t getClassId()

Get the unique class ID for a specific type.

Note

Each type T will have a unique class ID assigned the first time this method is called.

Template Parameters:

T – The type to get the class ID for.

Returns:

The unique class ID for type

Protected Functions

virtual void setParent(Node *parent)

Set the parent node.

Note

Called internally when adding/removing child nodes.

Parameters:

parent – Pointer to the parent node.

Private Members

Node *parent = nullptr

Parent node pointer.

Points to the parent of this node in the hierarchy.

std::vector<Node*> children

Child nodes vector.

Stores pointers to the child nodes of this node.

Private Static Functions

static inline size_t getNextClassId()

Get the next unique class ID.

Returns:

The next unique class ID.