Ember
Loading...
Searching...
No Matches
NodeAdapter.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/Node.h"
5#include <memory>
6
7namespace EmberCore {
8
16class NodeAdapter : public ITreeNode {
17 public:
22 explicit NodeAdapter(Node *node);
23 virtual ~NodeAdapter() = default;
24
25 // Core node properties
26 const EmberCore::String &GetName() const override;
27 NodeType GetType() const override;
28 NodeStatus GetStatus() const override;
29 size_t GetId() const override;
30
31 // Tree structure
32 size_t GetChildCount() const override;
33 ITreeNode *GetChild(size_t index) const override;
34 ITreeNode *GetParent() const override;
35
36 // Visual properties
37 const EmberCore::Point &GetPosition() const override;
38 void SetPosition(const EmberCore::Point &position) override;
39 VisualState GetVisualState() const override;
40 void SetVisualState(VisualState state) override;
41
42 // Children visibility
43 bool AreChildrenVisible() const override;
44 void SetChildrenVisible(bool visible) override;
45
46 // Layout support
47 int GetChildrenWidth() const override;
48 void SetChildrenWidth(int width) override;
49 int CalculateSubtreeWidth(int node_width, int horizontal_spacing) const override;
50
51 // Tree statistics
52 size_t GetDepth() const override;
53 size_t GetSubtreeNodeCount() const override;
54
55 // SubTree/reference status
56 bool IsSubTreeReference() const override;
57 bool IsUnimplementedReference() const override;
58 String GetSubTreeReference() const override;
59
60 // Visitor pattern support
61 void Accept(std::function<void(ITreeNode *)> visitor) override;
62 void Accept(std::function<void(const ITreeNode *)> visitor) const override;
63
64 // Access to the wrapped node (for legacy code compatibility)
65 Node *GetWrappedNode() const { return wrapped_node_; }
66
67 private:
69
70 // Cache for child adapters to maintain consistent pointer identity
71 mutable std::vector<std::unique_ptr<NodeAdapter>> child_adapters_;
72 mutable std::unique_ptr<NodeAdapter> parent_adapter_;
73
74 // Helper methods
79
80 // Ensure child adapters are created and cached
81 void EnsureChildAdapters() const;
82 void EnsureParentAdapter() const;
83};
84
85} // namespace EmberCore
Abstract interface for tree nodes that can be visualized.
Definition ITreeNode.h:31
VisualState
Visual state for UI rendering.
Definition ITreeNode.h:58
NodeType
Node types for visualization categorization.
Definition ITreeNode.h:36
NodeStatus
Node status for runtime visualization.
Definition ITreeNode.h:48
size_t GetDepth() const override
virtual ~NodeAdapter()=default
void EnsureChildAdapters() const
NodeAdapter(Node *node)
Constructor that wraps an existing Node.
size_t GetSubtreeNodeCount() const override
ITreeNode * GetParent() const override
bool IsUnimplementedReference() const override
Check if this node references an unimplemented tree.
String GetSubTreeReference() const override
Get the ID of the referenced SubTree (if this is a SubTree node)
int GetChildrenWidth() const override
void SetChildrenWidth(int width) override
int CalculateSubtreeWidth(int node_width, int horizontal_spacing) const override
void EnsureParentAdapter() const
const EmberCore::Point & GetPosition() const override
bool AreChildrenVisible() const override
void Accept(std::function< void(ITreeNode *)> visitor) override
void SetPosition(const EmberCore::Point &position) override
size_t GetChildCount() const override
NodeType GetType() const override
Node * GetWrappedNode() const
Definition NodeAdapter.h:65
VisualState GetVisualState() const override
NodeStatus GetStatus() const override
NodeStatus ConvertNodeStatus(Node::Status status) const
std::vector< std::unique_ptr< NodeAdapter > > child_adapters_
Definition NodeAdapter.h:71
NodeType ConvertNodeType(Node::Type type) const
std::unique_ptr< NodeAdapter > parent_adapter_
Definition NodeAdapter.h:72
bool IsSubTreeReference() const override
Check if this node is a SubTree reference.
VisualState ConvertVisualState(Node::VisualState state) const
void SetChildrenVisible(bool visible) override
const EmberCore::String & GetName() const override
void SetVisualState(VisualState state) override
size_t GetId() const override
ITreeNode * GetChild(size_t index) const override
Represents a node in a behavior tree structure.
Definition Node.h:20
Status
Node status for runtime execution tracking.
Definition Node.h:37
VisualState
Visual state for UI rendering.
Definition Node.h:47
Type
Node types for behavior tree classification.
Definition Node.h:25
Main types header for EmberCore.
std::string String
Framework-agnostic string type.
Definition String.h:14
2D point with integer coordinates
Definition Geometry.h:8