Ember
Loading...
Searching...
No Matches
LibXMLBehaviorTreeSerializer.h
Go to the documentation of this file.
1#pragma once
2
4#include "Types/Types.h"
5#include <libxml/parser.h>
6#include <libxml/tree.h>
7#include <memory>
8#include <string>
9
10// Forward declarations
11namespace EmberCore {
12class BehaviorTree;
13class Node;
14class Blackboard;
15} // namespace EmberCore
16
17namespace EmberCore {
18
33 public:
45
46 public:
51 explicit LibXMLBehaviorTreeSerializer(const ParserConfig &config);
52
57
64 bool SerializeToFile(std::shared_ptr<BehaviorTree> tree, const EmberCore::String &filepath);
65
71 EmberCore::String SerializeToString(std::shared_ptr<BehaviorTree> tree);
72
76 bool HasErrors() const { return !errors_.empty(); }
77 const std::vector<SerializeError> &GetErrors() const { return errors_; }
78 void ClearErrors() { errors_.clear(); }
79
83 const ParserConfig &GetConfig() const { return config_; }
84 void SetConfig(const ParserConfig &config) { config_ = config; }
85
86 private:
92 xmlDocPtr CreateXMLDocument(std::shared_ptr<BehaviorTree> tree);
93
100 xmlNodePtr SerializeBehaviorTree(std::shared_ptr<BehaviorTree> tree, xmlNodePtr parent);
101
108 xmlNodePtr SerializeNode(Node *node, xmlNodePtr parent);
109
115 void SerializeAttributes(Node *node, xmlNodePtr xml_node);
116
123 xmlNodePtr SerializeBlackboard(Blackboard *blackboard, xmlNodePtr parent);
124
128 void AddError(SerializeError::Type type, const EmberCore::String &message);
129
134
135 private:
137 std::vector<SerializeError> errors_;
138};
139
140} // namespace EmberCore
Represents a complete behavior tree data structure.
Represents a blackboard containing multiple entries.
void SerializeAttributes(Node *node, xmlNodePtr xml_node)
Serialize node attributes.
LibXMLBehaviorTreeSerializer(const ParserConfig &config)
Constructor with parser configuration.
EmberCore::String SerializeToString(std::shared_ptr< BehaviorTree > tree)
Serialize behavior tree to string.
EmberCore::String GetElementNameForNode(Node *node) const
Get node element name based on node type and config.
xmlDocPtr CreateXMLDocument(std::shared_ptr< BehaviorTree > tree)
Create XML document from behavior tree.
xmlNodePtr SerializeBehaviorTree(std::shared_ptr< BehaviorTree > tree, xmlNodePtr parent)
Serialize a single behavior tree to XML node.
const std::vector< SerializeError > & GetErrors() const
xmlNodePtr SerializeNode(Node *node, xmlNodePtr parent)
Recursively serialize a node and its children.
bool SerializeToFile(std::shared_ptr< BehaviorTree > tree, const EmberCore::String &filepath)
Serialize behavior tree to file.
void AddError(SerializeError::Type type, const EmberCore::String &message)
Error handling.
xmlNodePtr SerializeBlackboard(Blackboard *blackboard, xmlNodePtr parent)
Serialize blackboard.
const ParserConfig & GetConfig() const
Configuration management.
Represents a node in a behavior tree structure.
Definition Node.h:20
Configuration for XML parser behavior and element/attribute mappings.
Main types header for EmberCore.
std::string String
Framework-agnostic string type.
Definition String.h:14