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 "../../StatechartViewerPlugin/model/State.h"
26 #include "../../StatechartViewerPlugin/model/StateParameter.h"
27 #include "../../StatechartViewerPlugin/model/stateinstance/Visitor.h"
28 #include "../model/StateTreeNode.h"
30 
31 #include <QList>
32 #include <QString>
33 
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 }
54 
55 namespace armarx::statechartio
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  */
70  void serialize(armarx::statechartmodel::StateCPtr state, const QMap<QString, StateTreeNodePtr>& uuidToNodeMap = QMap<QString, StateTreeNodePtr>());
71 
72  /**
73  * Builds the XML document for the state object that has been handled by serialize() before.
74  * @param indent Whether to indent the resulting XML document (for output in a file) or to output unindented XML (for snapshots).
75  * @return XML document as a string.
76  */
77  QString getXmlString(bool indent = true) const;
78 
79  protected:
84 
85  private:
86  rapidxml::xml_node<>* buildDescription(const QString& description);
87  rapidxml::xml_node<>* buildEventList(const armarx::statechartmodel::EventList& eventList);
88  rapidxml::xml_node<>* buildParameterList(const QString& tagName, const armarx::statechartmodel::StateParameterMap& parameterMap);
89  rapidxml::xml_node<>* buildParameterMappingList(const armarx::statechartmodel::ParameterMappingList& parameterMappingList, const QString& mappingName);
90  rapidxml::xml_node<>* buildStartState(armarx::statechartmodel::TransitionCPtr startStateTransition);
91  rapidxml::xml_node<>* buildSubstateList(const armarx::statechartmodel::StateInstanceMap& substateMap);
92  rapidxml::xml_node<>* buildTransitionList(const armarx::statechartmodel::CTransitionList& transitionList, const QMap<QString, StateTreeNodePtr>& uuidToNodeMap);
93  rapidxml::xml_node<>* buildXmlDeclaration();
94 
95  char* cloneQString(const QString& string);
96 
97  rapidxml::xml_document<> document;
98  rapidxml::xml_node<>* substateNode; /* Needed for visit*() methods */
99  std::string escapeString(std::string str);
100 
101  VariantInfoPtr variantInfo;
102  };
103 }
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
armarx::statechartmodel::RemoteStateCPtr
std::shared_ptr< const RemoteState > RemoteStateCPtr
Definition: XmlWriter.h:51
armarx::statechartio
Definition: StateInstanceFactory.h:31
armarx::statechartmodel::RemoteState
Definition: RemoteState.h:28
armarx::statechartmodel::EventList
QList< EventPtr > EventList
Definition: XmlWriter.h:47
armarx::statechartio::XmlWriter::visitEndState
void visitEndState(armarx::statechartmodel::EndStateCPtr endState) override
Definition: XmlWriter.cpp:121
armarx::statechartio::XmlWriter::visitRemoteState
void visitRemoteState(armarx::statechartmodel::RemoteStateCPtr remoteState) override
Definition: XmlWriter.cpp:101
armarx::statechartmodel::StateInstanceMap
QMap< QString, StateInstancePtr > StateInstanceMap
Definition: State.h:50
armarx::statechartio::XmlWriter::visitDynamicRemoteState
void visitDynamicRemoteState(armarx::statechartmodel::DynamicRemoteStateCPtr dynamicRemoteState) override
Definition: XmlWriter.cpp:111
armarx::statechartio::XmlWriter::serialize
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:45
armarx::statechartmodel::DynamicRemoteStateCPtr
std::shared_ptr< const DynamicRemoteState > DynamicRemoteStateCPtr
Definition: DynamicRemoteState.h:41
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::statechartmodel
Definition: XmlWriter.h:36
armarx::statechartmodel::State
Definition: State.h:52
armarx::statechartmodel::ParameterMapping
Definition: ParameterMapping.h:34
armarx::statechartio::XmlWriter::visitLocalState
void visitLocalState(armarx::statechartmodel::LocalStateCPtr localState) override
Definition: XmlWriter.cpp:92
armarx::statechartmodel::Visitor
Definition: Visitor.h:39
armarx::control::hardware_config::tagName
std::string tagName(ConfigTag tag)
Definition: Config.cpp:302
armarx::statechartio::XmlWriter::XmlWriter
XmlWriter(const VariantInfoPtr &variantInfo)
Definition: XmlWriter.cpp:41
rapidxml::xml_document
This class represents root of the DOM hierarchy.
Definition: rapidxml.hpp:140
armarx::statechartmodel::CTransitionList
QList< TransitionCPtr > CTransitionList
Definition: State.h:49
armarx::statechartmodel::EndState
Definition: EndState.h:28
armarx::statechartio::XmlWriter::getXmlString
QString getXmlString(bool indent=true) const
Builds the XML document for the state object that has been handled by serialize() before.
Definition: XmlWriter.cpp:84
rapidxml::xml_node
Class representing a node of XML document.
Definition: rapidxml.hpp:138
armarx::statechartmodel::LocalStateCPtr
std::shared_ptr< const LocalState > LocalStateCPtr
Definition: XmlWriter.h:50
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::statechartmodel::TransitionCPtr
std::shared_ptr< const Transition > TransitionCPtr
Definition: Transition.h:94
armarx::statechartmodel::ParameterMappingList
QList< ParameterMappingPtr > ParameterMappingList
Definition: XmlWriter.h:49
armarx::statechartmodel::ParameterMappingPtr
std::shared_ptr< ParameterMapping > ParameterMappingPtr
Definition: XmlWriter.h:48
armarx::statechartmodel::EventPtr
std::shared_ptr< Event > EventPtr
Definition: XmlWriter.h:46
armarx::statechartio::XmlWriter
XML writer class used to build XML representations of State objects.
Definition: XmlWriter.h:61
armarx::statechartmodel::LocalState
Definition: LocalState.h:31
armarx::statechartmodel::Event
Definition: Event.h:30
rapidxml.hpp
armarx::statechartmodel::StateCPtr
std::shared_ptr< const State > StateCPtr
Definition: XmlWriter.h:45
armarx::statechartmodel::EndStateCPtr
std::shared_ptr< const EndState > EndStateCPtr
Definition: XmlWriter.h:52
VariantInfo.h