Ember
Loading...
Searching...
No Matches
EmberCore::Node Class Reference

Represents a node in a behavior tree structure. More...

#include <Node.h>

Public Types

enum class  Type {
  None , Action , Control , Condition ,
  Decorator , BehaviorTree
}
 Node types for behavior tree classification. More...
enum class  Status { Idle , Running , Success , Failure }
 Node status for runtime execution tracking. More...
enum class  VisualState { Normal , Selected , Hovered , Highlighted }
 Visual state for UI rendering. More...

Public Member Functions

 Node (const String &name, Type type=Type::None)
virtual ~Node ()
 Node (const Node &other)=delete
Nodeoperator= (const Node &other)=delete
 Node (Node &&other) noexcept
Nodeoperator= (Node &&other) noexcept
void AddChild (std::unique_ptr< Node > child)
void RemoveChild (size_t index)
void RemoveChild (Node *child)
std::unique_ptr< NodeDetachChild (size_t index)
std::unique_ptr< NodeDetachChild (Node *child)
std::unique_ptr< NodeDeepCopy () const
NodeFindChild (const String &name) const
NodeFindChildById (size_t id) const
NodeGetParent () const
size_t GetChildCount () const
NodeGetChild (size_t index) const
size_t GetId () const
const StringGetName () const
void SetName (const String &name)
Type GetType () const
void SetType (Type type)
Status GetStatus () const
void SetStatus (Status status)
const PointGetPosition () const
void SetPosition (const Point &position)
VisualState GetVisualState () const
void SetVisualState (VisualState state)
bool AreChildrenVisible () const
void SetChildrenVisible (bool visible)
void ToggleChildrenVisibility ()
int GetChildrenWidth () const
void SetChildrenWidth (int width)
int CalculateSubtreeWidth (int node_width, int horizontal_spacing) const
bool IsValid () const
bool HasCycles () const
size_t GetDepth () const
size_t GetSubtreeNodeCount () const
void Accept (std::function< void(Node *)> visitor)
void Accept (std::function< void(const Node *)> visitor) const
String GetTypeString () const
String GetStatusString () const
std::vector< Node * > GetAllChildren ()
std::vector< const Node * > GetAllChildren () const
void SetAttribute (const String &name, const String &value)
String GetAttribute (const String &name, const String &default_value="") const
bool HasAttribute (const String &name) const
void RemoveAttribute (const String &name)
const std::map< String, String > & GetAllAttributes () const
size_t GetAttributeCount () const
String ToString () const
void PrintTree (int indent=0) const

Protected Member Functions

virtual std::unique_ptr< NodeCreateCopy () const
virtual void OnChildAdded (Node *child)
virtual void OnChildRemoved (Node *child)

Private Member Functions

void SetParent (Node *parent)
bool HasCyclesHelper (std::vector< const Node * > &visited) const
size_t FindChildIndex (Node *child) const

Private Attributes

String name_
Type type_
Status status_
size_t id_
std::vector< std::unique_ptr< Node > > children_
Nodeparent_
Point position_
VisualState visual_state_
bool children_visible_
int children_width_
std::map< String, Stringcustom_attributes_

Static Private Attributes

static size_t next_id_ = 1

Friends

class NodeFactory

Detailed Description

Represents a node in a behavior tree structure.

This class encapsulates the core functionality of behavior tree nodes, providing a modern C++ interface with proper memory management and extensible design patterns.

Definition at line 20 of file Node.h.

Member Enumeration Documentation

◆ Status

enum class EmberCore::Node::Status
strong

Node status for runtime execution tracking.

Enumerator
Idle 
Running 
Success 
Failure 

Definition at line 37 of file Node.h.

◆ Type

enum class EmberCore::Node::Type
strong

Node types for behavior tree classification.

Enumerator
None 
Action 
Control 
Condition 
Decorator 
BehaviorTree 

Definition at line 25 of file Node.h.

◆ VisualState

enum class EmberCore::Node::VisualState
strong

Visual state for UI rendering.

Enumerator
Normal 
Selected 
Hovered 
Highlighted 

Definition at line 47 of file Node.h.

Constructor & Destructor Documentation

◆ Node() [1/3]

EmberCore::Node::Node ( const String & name,
Type type = Type::None )
explicit

Definition at line 12 of file Node.cpp.

◆ ~Node()

EmberCore::Node::~Node ( )
virtual

Definition at line 17 of file Node.cpp.

◆ Node() [2/3]

EmberCore::Node::Node ( const Node & other)
delete

◆ Node() [3/3]

EmberCore::Node::Node ( Node && other)
noexcept

Definition at line 27 of file Node.cpp.

Member Function Documentation

◆ Accept() [1/2]

void EmberCore::Node::Accept ( std::function< void(const Node *)> visitor) const

Definition at line 263 of file Node.cpp.

◆ Accept() [2/2]

void EmberCore::Node::Accept ( std::function< void(Node *)> visitor)

Definition at line 254 of file Node.cpp.

◆ AddChild()

void EmberCore::Node::AddChild ( std::unique_ptr< Node > child)

Definition at line 77 of file Node.cpp.

◆ AreChildrenVisible()

bool EmberCore::Node::AreChildrenVisible ( ) const
inline

Definition at line 97 of file Node.h.

◆ CalculateSubtreeWidth()

int EmberCore::Node::CalculateSubtreeWidth ( int node_width,
int horizontal_spacing ) const

Definition at line 183 of file Node.cpp.

◆ CreateCopy()

std::unique_ptr< Node > EmberCore::Node::CreateCopy ( ) const
protectedvirtual

Definition at line 344 of file Node.cpp.

◆ DeepCopy()

std::unique_ptr< Node > EmberCore::Node::DeepCopy ( ) const

Definition at line 149 of file Node.cpp.

◆ DetachChild() [1/2]

std::unique_ptr< Node > EmberCore::Node::DetachChild ( Node * child)

Definition at line 140 of file Node.cpp.

◆ DetachChild() [2/2]

std::unique_ptr< Node > EmberCore::Node::DetachChild ( size_t index)

Definition at line 123 of file Node.cpp.

◆ FindChild()

Node * EmberCore::Node::FindChild ( const String & name) const

Definition at line 163 of file Node.cpp.

◆ FindChildById()

Node * EmberCore::Node::FindChildById ( size_t id) const

Definition at line 169 of file Node.cpp.

◆ FindChildIndex()

size_t EmberCore::Node::FindChildIndex ( Node * child) const
private

Definition at line 390 of file Node.cpp.

◆ GetAllAttributes()

const std::map< EmberCore::String, EmberCore::String > & EmberCore::Node::GetAllAttributes ( ) const

Definition at line 462 of file Node.cpp.

◆ GetAllChildren() [1/2]

std::vector< Node * > EmberCore::Node::GetAllChildren ( )

Definition at line 304 of file Node.cpp.

◆ GetAllChildren() [2/2]

std::vector< const Node * > EmberCore::Node::GetAllChildren ( ) const

Definition at line 315 of file Node.cpp.

◆ GetAttribute()

EmberCore::String EmberCore::Node::GetAttribute ( const String & name,
const String & default_value = "" ) const

Definition at line 451 of file Node.cpp.

◆ GetAttributeCount()

size_t EmberCore::Node::GetAttributeCount ( ) const

Definition at line 464 of file Node.cpp.

◆ GetChild()

Node * EmberCore::Node::GetChild ( size_t index) const

Definition at line 175 of file Node.cpp.

◆ GetChildCount()

size_t EmberCore::Node::GetChildCount ( ) const
inline

Definition at line 76 of file Node.h.

◆ GetChildrenWidth()

int EmberCore::Node::GetChildrenWidth ( ) const
inline

Definition at line 102 of file Node.h.

◆ GetDepth()

size_t EmberCore::Node::GetDepth ( ) const

Definition at line 236 of file Node.cpp.

◆ GetId()

size_t EmberCore::Node::GetId ( ) const
inline

Definition at line 80 of file Node.h.

◆ GetName()

const String & EmberCore::Node::GetName ( ) const
inline

Definition at line 81 of file Node.h.

◆ GetParent()

Node * EmberCore::Node::GetParent ( ) const
inline

Definition at line 75 of file Node.h.

◆ GetPosition()

const Point & EmberCore::Node::GetPosition ( ) const
inline

Definition at line 91 of file Node.h.

◆ GetStatus()

Status EmberCore::Node::GetStatus ( ) const
inline

Definition at line 87 of file Node.h.

◆ GetStatusString()

EmberCore::String EmberCore::Node::GetStatusString ( ) const

Definition at line 290 of file Node.cpp.

◆ GetSubtreeNodeCount()

size_t EmberCore::Node::GetSubtreeNodeCount ( ) const

Definition at line 246 of file Node.cpp.

◆ GetType()

Type EmberCore::Node::GetType ( ) const
inline

Definition at line 84 of file Node.h.

◆ GetTypeString()

EmberCore::String EmberCore::Node::GetTypeString ( ) const

Definition at line 274 of file Node.cpp.

◆ GetVisualState()

VisualState EmberCore::Node::GetVisualState ( ) const
inline

Definition at line 94 of file Node.h.

◆ HasAttribute()

bool EmberCore::Node::HasAttribute ( const String & name) const

Definition at line 456 of file Node.cpp.

◆ HasCycles()

bool EmberCore::Node::HasCycles ( ) const

Definition at line 231 of file Node.cpp.

◆ HasCyclesHelper()

bool EmberCore::Node::HasCyclesHelper ( std::vector< const Node * > & visited) const
private

Definition at line 373 of file Node.cpp.

◆ IsValid()

bool EmberCore::Node::IsValid ( ) const

Definition at line 205 of file Node.cpp.

◆ OnChildAdded()

void EmberCore::Node::OnChildAdded ( Node * child)
protectedvirtual

Definition at line 362 of file Node.cpp.

◆ OnChildRemoved()

void EmberCore::Node::OnChildRemoved ( Node * child)
protectedvirtual

Definition at line 367 of file Node.cpp.

◆ operator=() [1/2]

Node & EmberCore::Node::operator= ( const Node & other)
delete

◆ operator=() [2/2]

Node & EmberCore::Node::operator= ( Node && other)
noexcept

Definition at line 42 of file Node.cpp.

◆ PrintTree()

void EmberCore::Node::PrintTree ( int indent = 0) const

Definition at line 332 of file Node.cpp.

◆ RemoveAttribute()

void EmberCore::Node::RemoveAttribute ( const String & name)

Definition at line 460 of file Node.cpp.

◆ RemoveChild() [1/2]

void EmberCore::Node::RemoveChild ( Node * child)

Definition at line 116 of file Node.cpp.

◆ RemoveChild() [2/2]

void EmberCore::Node::RemoveChild ( size_t index)

Definition at line 103 of file Node.cpp.

◆ SetAttribute()

void EmberCore::Node::SetAttribute ( const String & name,
const String & value )

Definition at line 444 of file Node.cpp.

◆ SetChildrenVisible()

void EmberCore::Node::SetChildrenVisible ( bool visible)
inline

Definition at line 98 of file Node.h.

◆ SetChildrenWidth()

void EmberCore::Node::SetChildrenWidth ( int width)
inline

Definition at line 103 of file Node.h.

◆ SetName()

void EmberCore::Node::SetName ( const String & name)
inline

Definition at line 82 of file Node.h.

◆ SetParent()

void EmberCore::Node::SetParent ( Node * parent)
inlineprivate

Definition at line 164 of file Node.h.

◆ SetPosition()

void EmberCore::Node::SetPosition ( const Point & position)
inline

Definition at line 92 of file Node.h.

◆ SetStatus()

void EmberCore::Node::SetStatus ( Status status)
inline

Definition at line 88 of file Node.h.

◆ SetType()

void EmberCore::Node::SetType ( Type type)
inline

Definition at line 85 of file Node.h.

◆ SetVisualState()

void EmberCore::Node::SetVisualState ( VisualState state)
inline

Definition at line 95 of file Node.h.

◆ ToggleChildrenVisibility()

void EmberCore::Node::ToggleChildrenVisibility ( )
inline

Definition at line 99 of file Node.h.

◆ ToString()

EmberCore::String EmberCore::Node::ToString ( ) const

Definition at line 327 of file Node.cpp.

◆ NodeFactory

friend class NodeFactory
friend

Definition at line 168 of file Node.h.

Member Data Documentation

◆ children_

std::vector<std::unique_ptr<Node> > EmberCore::Node::children_
private

Definition at line 148 of file Node.h.

◆ children_visible_

bool EmberCore::Node::children_visible_
private

Definition at line 154 of file Node.h.

◆ children_width_

int EmberCore::Node::children_width_
private

Definition at line 155 of file Node.h.

◆ custom_attributes_

std::map<String, String> EmberCore::Node::custom_attributes_
private

Definition at line 158 of file Node.h.

◆ id_

size_t EmberCore::Node::id_
private

Definition at line 145 of file Node.h.

◆ name_

String EmberCore::Node::name_
private

Definition at line 142 of file Node.h.

◆ next_id_

size_t EmberCore::Node::next_id_ = 1
staticprivate

Definition at line 161 of file Node.h.

◆ parent_

Node* EmberCore::Node::parent_
private

Definition at line 149 of file Node.h.

◆ position_

Point EmberCore::Node::position_
private

Definition at line 152 of file Node.h.

◆ status_

Status EmberCore::Node::status_
private

Definition at line 144 of file Node.h.

◆ type_

Type EmberCore::Node::type_
private

Definition at line 143 of file Node.h.

◆ visual_state_

VisualState EmberCore::Node::visual_state_
private

Definition at line 153 of file Node.h.


The documentation for this class was generated from the following files: