XmlWriter.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Christian Mandery (christian.mandery at kit dot edu)
18* @date 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <QList>
26#include <QString>
27
30
35
37{
38 class State;
39 class Event;
40 class ParameterMapping;
41 class LocalState;
42 class RemoteState;
43 class EndState;
44
45 using StateCPtr = std::shared_ptr<const State>;
46 using EventPtr = std::shared_ptr<Event>;
47 using EventList = QList<EventPtr>;
48 using ParameterMappingPtr = std::shared_ptr<ParameterMapping>;
49 using ParameterMappingList = QList<ParameterMappingPtr>;
50 using LocalStateCPtr = std::shared_ptr<const LocalState>;
51 using RemoteStateCPtr = std::shared_ptr<const RemoteState>;
52 using EndStateCPtr = std::shared_ptr<const EndState>;
53} // namespace armarx::statechartmodel
54
56{
57 /**
58 * @class XmlWriter
59 * @brief XML writer class used to build XML representations of State objects.
60 */
62 {
63 public:
64 XmlWriter(const VariantInfoPtr& variantInfo);
65
66 /**
67 * Builds XML data structures for serialization of the given state object. Afterwards, the resulting XML document can be generated using the getXmlString() method.
68 * @param state State object that should be serialized to XML.
69 */
71 const QMap<QString, StateTreeNodePtr>& uuidToNodeMap =
72 QMap<QString, StateTreeNodePtr>());
73
74 /**
75 * Builds the XML document for the state object that has been handled by serialize() before.
76 * @param indent Whether to indent the resulting XML document (for output in a file) or to output unindented XML (for snapshots).
77 * @return XML document as a string.
78 */
79 QString getXmlString(bool indent = true) const;
80
81 protected:
85 armarx::statechartmodel::DynamicRemoteStateCPtr dynamicRemoteState) override;
87
88 private:
89 rapidxml::xml_node<>* buildDescription(const QString& description);
90 rapidxml::xml_node<>* buildEventList(const armarx::statechartmodel::EventList& eventList);
92 buildParameterList(const QString& tagName,
94 rapidxml::xml_node<>* buildParameterMappingList(
95 const armarx::statechartmodel::ParameterMappingList& parameterMappingList,
96 const QString& mappingName);
98 buildStartState(armarx::statechartmodel::TransitionCPtr startStateTransition);
100 buildSubstateList(const armarx::statechartmodel::StateInstanceMap& substateMap);
102 buildTransitionList(const armarx::statechartmodel::CTransitionList& transitionList,
103 const QMap<QString, StateTreeNodePtr>& uuidToNodeMap);
104 rapidxml::xml_node<>* buildXmlDeclaration();
105
106 char* cloneQString(const QString& string);
107
109 rapidxml::xml_node<>* substateNode; /* Needed for visit*() methods */
110 std::string escapeString(std::string str);
111
112 VariantInfoPtr variantInfo;
113 };
114} // namespace armarx::statechartio
std::string str(const T &t)
void visitDynamicRemoteState(armarx::statechartmodel::DynamicRemoteStateCPtr dynamicRemoteState) override
void visitLocalState(armarx::statechartmodel::LocalStateCPtr localState) override
Definition XmlWriter.cpp:99
QString getXmlString(bool indent=true) const
Builds the XML document for the state object that has been handled by serialize() before.
Definition XmlWriter.cpp:90
void visitEndState(armarx::statechartmodel::EndStateCPtr endState) override
XmlWriter(const VariantInfoPtr &variantInfo)
Definition XmlWriter.cpp:41
void visitRemoteState(armarx::statechartmodel::RemoteStateCPtr remoteState) override
void serialize(armarx::statechartmodel::StateCPtr state, const QMap< QString, StateTreeNodePtr > &uuidToNodeMap=QMap< QString, StateTreeNodePtr >())
Builds XML data structures for serialization of the given state object.
Definition XmlWriter.cpp:46
This class represents root of the DOM hierarchy.
Class representing a node of XML document.
QMap< QString, StateParameterPtr > StateParameterMap
std::shared_ptr< const LocalState > LocalStateCPtr
Definition XmlWriter.h:50
QList< ParameterMappingPtr > ParameterMappingList
Definition XmlWriter.h:49
std::shared_ptr< const State > StateCPtr
Definition XmlWriter.h:45
std::shared_ptr< Event > EventPtr
Definition XmlWriter.h:46
std::shared_ptr< const Transition > TransitionCPtr
Definition Transition.h:91
std::shared_ptr< const EndState > EndStateCPtr
Definition XmlWriter.h:52
QList< EventPtr > EventList
Definition XmlWriter.h:47
QList< TransitionCPtr > CTransitionList
Definition State.h:51
std::shared_ptr< const DynamicRemoteState > DynamicRemoteStateCPtr
std::shared_ptr< const RemoteState > RemoteStateCPtr
Definition XmlWriter.h:51
std::shared_ptr< ParameterMapping > ParameterMappingPtr
Definition XmlWriter.h:48
QMap< QString, StateInstancePtr > StateInstanceMap
Definition State.h:52
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition VariantInfo.h:39
This file contains rapidxml parser and DOM implementation.