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

XML serializer using libxml2 for behavior tree files. More...

#include <LibXMLBehaviorTreeSerializer.h>

Classes

struct  SerializeError
 Error information for serialization failures. More...

Public Member Functions

 LibXMLBehaviorTreeSerializer (const ParserConfig &config)
 Constructor with parser configuration.
 ~LibXMLBehaviorTreeSerializer ()
 Destructor.
bool SerializeToFile (std::shared_ptr< BehaviorTree > tree, const EmberCore::String &filepath)
 Serialize behavior tree to file.
EmberCore::String SerializeToString (std::shared_ptr< BehaviorTree > tree)
 Serialize behavior tree to string.
bool HasErrors () const
 Error handling.
const std::vector< SerializeError > & GetErrors () const
void ClearErrors ()
const ParserConfigGetConfig () const
 Configuration management.
void SetConfig (const ParserConfig &config)

Private Member Functions

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.
xmlNodePtr SerializeNode (Node *node, xmlNodePtr parent)
 Recursively serialize a node and its children.
void SerializeAttributes (Node *node, xmlNodePtr xml_node)
 Serialize node attributes.
xmlNodePtr SerializeBlackboard (Blackboard *blackboard, xmlNodePtr parent)
 Serialize blackboard.
void AddError (SerializeError::Type type, const EmberCore::String &message)
 Error handling.
EmberCore::String GetElementNameForNode (Node *node) const
 Get node element name based on node type and config.

Private Attributes

ParserConfig config_
std::vector< SerializeErrorerrors_

Detailed Description

XML serializer using libxml2 for behavior tree files.

This serializer mirrors the LibXMLBehaviorTreeParser, converting behavior trees back to XML format while preserving comments, formatting, and respecting the active parser profile configuration.

Features:

  • libxml2-based serialization for consistency with parser
  • Preserves XML comments and formatting from original files
  • Respects parser profile settings for element/attribute names
  • Pretty-printed XML output with configurable indentation

Definition at line 32 of file LibXMLBehaviorTreeSerializer.h.

Constructor & Destructor Documentation

◆ LibXMLBehaviorTreeSerializer()

EmberCore::LibXMLBehaviorTreeSerializer::LibXMLBehaviorTreeSerializer ( const ParserConfig & config)
explicit

Constructor with parser configuration.

Parameters
configParser configuration to respect for element/attribute naming

Definition at line 10 of file LibXMLBehaviorTreeSerializer.cpp.

◆ ~LibXMLBehaviorTreeSerializer()

EmberCore::LibXMLBehaviorTreeSerializer::~LibXMLBehaviorTreeSerializer ( )

Destructor.

Definition at line 12 of file LibXMLBehaviorTreeSerializer.cpp.

Member Function Documentation

◆ AddError()

void EmberCore::LibXMLBehaviorTreeSerializer::AddError ( SerializeError::Type type,
const EmberCore::String & message )
private

Error handling.

Definition at line 283 of file LibXMLBehaviorTreeSerializer.cpp.

◆ ClearErrors()

void EmberCore::LibXMLBehaviorTreeSerializer::ClearErrors ( )
inline

Definition at line 78 of file LibXMLBehaviorTreeSerializer.h.

◆ CreateXMLDocument()

xmlDocPtr EmberCore::LibXMLBehaviorTreeSerializer::CreateXMLDocument ( std::shared_ptr< BehaviorTree > tree)
private

Create XML document from behavior tree.

Parameters
treeBehavior tree to serialize
Returns
xmlDocPtr or nullptr on error

Definition at line 92 of file LibXMLBehaviorTreeSerializer.cpp.

◆ GetConfig()

const ParserConfig & EmberCore::LibXMLBehaviorTreeSerializer::GetConfig ( ) const
inline

Configuration management.

Definition at line 83 of file LibXMLBehaviorTreeSerializer.h.

◆ GetElementNameForNode()

EmberCore::String EmberCore::LibXMLBehaviorTreeSerializer::GetElementNameForNode ( Node * node) const
private

Get node element name based on node type and config.

Definition at line 288 of file LibXMLBehaviorTreeSerializer.cpp.

◆ GetErrors()

const std::vector< SerializeError > & EmberCore::LibXMLBehaviorTreeSerializer::GetErrors ( ) const
inline

Definition at line 77 of file LibXMLBehaviorTreeSerializer.h.

◆ HasErrors()

bool EmberCore::LibXMLBehaviorTreeSerializer::HasErrors ( ) const
inline

Error handling.

Definition at line 76 of file LibXMLBehaviorTreeSerializer.h.

◆ SerializeAttributes()

void EmberCore::LibXMLBehaviorTreeSerializer::SerializeAttributes ( Node * node,
xmlNodePtr xml_node )
private

Serialize node attributes.

Parameters
nodeSource node
xml_nodeTarget XML node

Definition at line 226 of file LibXMLBehaviorTreeSerializer.cpp.

◆ SerializeBehaviorTree()

xmlNodePtr EmberCore::LibXMLBehaviorTreeSerializer::SerializeBehaviorTree ( std::shared_ptr< BehaviorTree > tree,
xmlNodePtr parent )
private

Serialize a single behavior tree to XML node.

Parameters
treeBehavior tree to serialize
parentParent XML node
Returns
XML node representing the tree

Definition at line 130 of file LibXMLBehaviorTreeSerializer.cpp.

◆ SerializeBlackboard()

xmlNodePtr EmberCore::LibXMLBehaviorTreeSerializer::SerializeBlackboard ( Blackboard * blackboard,
xmlNodePtr parent )
private

Serialize blackboard.

Parameters
blackboardBlackboard to serialize
parentParent XML node
Returns
XML node representing the blackboard

Definition at line 248 of file LibXMLBehaviorTreeSerializer.cpp.

◆ SerializeNode()

xmlNodePtr EmberCore::LibXMLBehaviorTreeSerializer::SerializeNode ( Node * node,
xmlNodePtr parent )
private

Recursively serialize a node and its children.

Parameters
nodeNode to serialize
parentParent XML node
Returns
XML node representing the node

Definition at line 172 of file LibXMLBehaviorTreeSerializer.cpp.

◆ SerializeToFile()

bool EmberCore::LibXMLBehaviorTreeSerializer::SerializeToFile ( std::shared_ptr< BehaviorTree > tree,
const EmberCore::String & filepath )

Serialize behavior tree to file.

Parameters
treeBehavior tree to serialize
filepathOutput file path
Returns
true if successful, false otherwise

Definition at line 16 of file LibXMLBehaviorTreeSerializer.cpp.

◆ SerializeToString()

EmberCore::String EmberCore::LibXMLBehaviorTreeSerializer::SerializeToString ( std::shared_ptr< BehaviorTree > tree)

Serialize behavior tree to string.

Parameters
treeBehavior tree to serialize
Returns
XML string, empty on error

Definition at line 55 of file LibXMLBehaviorTreeSerializer.cpp.

◆ SetConfig()

void EmberCore::LibXMLBehaviorTreeSerializer::SetConfig ( const ParserConfig & config)
inline

Definition at line 84 of file LibXMLBehaviorTreeSerializer.h.

Member Data Documentation

◆ config_

ParserConfig EmberCore::LibXMLBehaviorTreeSerializer::config_
private

Definition at line 136 of file LibXMLBehaviorTreeSerializer.h.

◆ errors_

std::vector<SerializeError> EmberCore::LibXMLBehaviorTreeSerializer::errors_
private

Definition at line 137 of file LibXMLBehaviorTreeSerializer.h.


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