Fabric 0.2.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
fabric::XMLParser Class Reference

Syntax validation plugin for XML plans. More...

#include <xml_parser_plugin.hpp>

Inheritance diagram for fabric::XMLParser:
Inheritance graph
[legend]
Collaboration diagram for fabric::XMLParser:
Collaboration graph
[legend]

Public Member Functions

 XMLParser ()=default
 
virtual ~XMLParser ()=default
 
void initialize (const rclcpp::Node::SharedPtr &node) override
 Initialize the XML parser plugin.
 
bool load_file (const std::string &file_path, fabric::Plan &plan) override
 load a file into an XML document
 
bool check_compatibility (const fabric::Plan &plan) override
 Check the compatibility of the given plan with the given parser.
 
void parse (fabric::Plan &plan) override
 Parse the given XML plan.
 
- Public Member Functions inherited from fabric::ParserBase
virtual ~ParserBase ()=default
 

Protected Member Functions

void convert_to_string (tinyxml2::XMLDocument &document_xml, std::string &document_string)
 convert XMLDocument to std::string
 
bool search (std::vector< std::string > list, std::string value)
 search a string in a vector of strings
 
tinyxml2::XMLElement * extract_plan (tinyxml2::XMLDocument &document)
 Extract the <Plan> element from the XML document.
 
bool convert_to_string (tinyxml2::XMLElement *element, std::string &parameters)
 convert XMLElement to std::string
 
bool check_syntax (tinyxml2::XMLElement *element, std::vector< std::string > &control_list, std::vector< std::string > &rejected, std::string &error)
 check the plan to make sure all control and runner XML elements are valid with minimal required attributes. The function uses recursive approach to go through the xml plan
 
void add_completion_runner (tinyxml2::XMLDocument &document, const std::string &plan_id)
 add a completion runner to the plan This function adds a new <Control> element with type "sequential" and a <Runner> element for the completion runner to the existing <Plan> element in the XML document.
 
int add_parallel_all (fabric::Plan &plan, int connection_id=0, std::string description="")
 Adds a system connection for parallel input multiplexing with waiting for all inputs.
 
int add_parallel_any (fabric::Plan &plan, int connection_id=0, std::string description="")
 Adds a system connection for parallel input multiplexing with waiting for any inputs.
 
capabilities2_events::EventParameters convert_xml_to_event_parameters (tinyxml2::XMLElement *element)
 Check and update the system runner id for the successor based on the predecessor's id.
 
int extract_connections (tinyxml2::XMLElement *element, fabric::Plan &plan, int connection_id=0, fabric::event connection_type=fabric::event::ON_SUCCESS, std::string conn_description="")
 parse through the plan and extract the connections
 
- Protected Member Functions inherited from fabric::ParserBase
void initialize_base (const rclcpp::Node::SharedPtr &node, const std::string &plugin_name)
 Base initialization method for derived classes.
 

Protected Attributes

std::vector< std::string > control_list
 List of valid control tags.
 
tinyxml2::XMLDocument system_doc
 XML Document for system runners.
 
int runner_index = 0
 Index for assigning unique IDs to system runners.
 
tinyxml2::XMLElement * plan_ = nullptr
 Pointer to the plan element in the XML document.
 
tinyxml2::XMLDocument default_document
 Default XML document for loading from file.
 
tinyxml2::XMLDocument current_document_
 XML Document to hold the current plan.
 
- Protected Attributes inherited from fabric::ParserBase
rclcpp::Node::SharedPtr node_
 Shared pointer to the ROS2 node.
 
std::string plugin_name_
 Name of the validation plugin.
 

Detailed Description

Syntax validation plugin for XML plans.

This plugin checks the XML plan for basic syntax errors (well-formedness, root tag, etc).

Constructor & Destructor Documentation

◆ XMLParser()

fabric::XMLParser::XMLParser ( )
default

◆ ~XMLParser()

virtual fabric::XMLParser::~XMLParser ( )
virtualdefault

Member Function Documentation

◆ add_completion_runner()

void fabric::XMLParser::add_completion_runner ( tinyxml2::XMLDocument &  document,
const std::string &  plan_id 
)
inlineprotected

add a completion runner to the plan This function adds a new <Control> element with type "sequential" and a <Runner> element for the completion runner to the existing <Plan> element in the XML document.

Parameters
documentXML document to which the completion runner will be added
plan_idID of the plan to be associated with the completion runner

◆ add_parallel_all()

int fabric::XMLParser::add_parallel_all ( fabric::Plan plan,
int  connection_id = 0,
std::string  description = "" 
)
inlineprotected

Adds a system connection for parallel input multiplexing with waiting for all inputs.

Parameters
connectionsfabric::Plan containing connections
connection_idconnection id to be used for the new connection
descriptiondescription of the connection
Returns
int next connection id

◆ add_parallel_any()

int fabric::XMLParser::add_parallel_any ( fabric::Plan plan,
int  connection_id = 0,
std::string  description = "" 
)
inlineprotected

Adds a system connection for parallel input multiplexing with waiting for any inputs.

Parameters
planfabric::Plan containing connections
connection_idconnection id to be used for the new connection
descriptiondescription of the connection
Returns
int next connection id

◆ check_compatibility()

bool fabric::XMLParser::check_compatibility ( const fabric::Plan plan)
inlineoverridevirtual

Check the compatibility of the given plan with the given parser.

Parameters
planThe plan to check for compatibility.
Returns
true if the plan is compatible, false otherwise.

Implements fabric::ParserBase.

◆ check_syntax()

bool fabric::XMLParser::check_syntax ( tinyxml2::XMLElement *  element,
std::vector< std::string > &  control_list,
std::vector< std::string > &  rejected,
std::string &  error 
)
inlineprotected

check the plan to make sure all control and runner XML elements are valid with minimal required attributes. The function uses recursive approach to go through the xml plan

Parameters
elementXML Element to be evaluated
control_listlist of valid control tags
rejectedlist containing invalid tags
erroroutput string for error messages
Returns
true if element valid and supported and false otherwise

◆ convert_to_string() [1/2]

void fabric::XMLParser::convert_to_string ( tinyxml2::XMLDocument &  document_xml,
std::string &  document_string 
)
inlineprotected

convert XMLDocument to std::string

Parameters
documentelement to be converted
Returns
std::string converted document

◆ convert_to_string() [2/2]

bool fabric::XMLParser::convert_to_string ( tinyxml2::XMLElement *  element,
std::string &  parameters 
)
inlineprotected

convert XMLElement to std::string

Parameters
elementXMLElement element to be converted
paramtersparameter to hold std::string
Returns
true if element is not nullptr and conversion successful, false if element is nullptr

◆ convert_xml_to_event_parameters()

capabilities2_events::EventParameters fabric::XMLParser::convert_xml_to_event_parameters ( tinyxml2::XMLElement *  element)
inlineprotected

Check and update the system runner id for the successor based on the predecessor's id.

This function checks if the predecessor is a system runner and has parameters. If so, it updates the successor's parameters with the predecessor's id.

Parameters
predecessorThe predecessor node_t containing the source runner
successorThe successor node_t to be updated

convert tinyxml2::XMLElement attributes to EventParameters. Treats the original attributes as string and let the runners that they are related to handle the conversion from string to correct data type

Parameters
elementtinyxml2::XMLElement element to be converted.
Returns
capabilities2_events::EventParameters converted parameters

◆ extract_connections()

int fabric::XMLParser::extract_connections ( tinyxml2::XMLElement *  element,
fabric::Plan plan,
int  connection_id = 0,
fabric::event  connection_type = fabric::event::ON_SUCCESS,
std::string  conn_description = "" 
)
inlineprotected

parse through the plan and extract the connections

Parameters
elementXML Element to be evaluated
connectionsstd::map containing extracted connections

◆ extract_plan()

tinyxml2::XMLElement * fabric::XMLParser::extract_plan ( tinyxml2::XMLDocument &  document)
inlineprotected

Extract the <Plan> element from the XML document.

This function checks if the root element of the provided XML document is <Plan>. If so, it returns the first child element of <Plan>. Otherwise, it indicates failure.

Parameters
documentThe XMLDocument to extract the plan from
Returns
tinyxml2::XMLElement* Pointer to the first child of <Plan> if successful, nullptr otherwise

◆ initialize()

void fabric::XMLParser::initialize ( const rclcpp::Node::SharedPtr &  node)
inlineoverridevirtual

Initialize the XML parser plugin.

Parameters
nodeShared pointer to the ROS2 node.

Reimplemented from fabric::ParserBase.

◆ load_file()

bool fabric::XMLParser::load_file ( const std::string &  file_path,
fabric::Plan plan 
)
inlineoverridevirtual

load a file into an XML document

Parameters
documentThe path to the XML file to be loaded
Returns
true if the file was loaded successfully, false otherwise

Implements fabric::ParserBase.

◆ parse()

void fabric::XMLParser::parse ( fabric::Plan plan)
inlineoverridevirtual

Parse the given XML plan.

Parameters
documentThe XMLDocument representing the plan.
planThe parsed plan.

Implements fabric::ParserBase.

◆ search()

bool fabric::XMLParser::search ( std::vector< std::string >  list,
std::string  value 
)
inlineprotected

search a string in a vector of strings

Parameters
listvector of strings to be searched
valuestring to be searched in the vector
Returns
true if value is found in list and false otherwise

Member Data Documentation

◆ control_list

std::vector<std::string> fabric::XMLParser::control_list
protected

List of valid control tags.

◆ current_document_

tinyxml2::XMLDocument fabric::XMLParser::current_document_
protected

XML Document to hold the current plan.

◆ default_document

tinyxml2::XMLDocument fabric::XMLParser::default_document
protected

Default XML document for loading from file.

◆ plan_

tinyxml2::XMLElement* fabric::XMLParser::plan_ = nullptr
protected

Pointer to the plan element in the XML document.

◆ runner_index

int fabric::XMLParser::runner_index = 0
protected

Index for assigning unique IDs to system runners.

◆ system_doc

tinyxml2::XMLDocument fabric::XMLParser::system_doc
protected

XML Document for system runners.


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