XmlReader.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
29
31
33{
34 /**
35 * @class XmlReader
36 * @brief XML reader class used to build State objects from XML representations.
37 */
39 {
40 public:
41 /**
42 * Creates a new XmlReader. The ICE communicator is required for deserialization of parameter default values from JSON.
43 * @param iceCommunicator Ice communicator.
44 */
45 XmlReader(Ice::CommunicatorPtr iceCommunicator, VariantInfoPtr info);
46
47 /**
48 * Parses the given XML document and builds a State object (that can be retrieved using getRootState()).
49 * The State object will not contain references to other states until addReferences() has been called.
50 * @param xmlString XML document to parse.
51 */
52 void parseXml(const QString& xmlString);
53
54 /**
55 * Returns the State object created by this XML reader.
56 * @return State object.
57 */
60 {
61 return loadedState;
62 }
63
64 private:
65 QString readDescription(rapidxml::xml_node<>* rootNode) const;
66 armarx::statechartmodel::EventList readEventList(rapidxml::xml_node<>* eventListNode) const;
68 readParameterList(rapidxml::xml_node<>* parameterListNode) const;
70 readParameterMappingList(rapidxml::xml_node<>* parameterMappingListNode) const;
71 void readStartState(rapidxml::xml_node<>* startStateNode) const;
73 readSubstateList(rapidxml::xml_node<>* substateListNode) const;
75 readTransitionList(rapidxml::xml_node<>* transitionListNode) const;
76
78 getSubstateByInstanceName(const QString& name) const;
79
81 const QString& attributeName,
82 bool required = true) const;
83
84 Ice::CommunicatorPtr iceCommunicator;
85 VariantInfoPtr info;
87 bool hasSubstateByInstanceName(const QString& name) const;
88 };
89
90 /**
91 * @class XmlNodeIterator
92 * @brief Iterate over all child nodes with a certain name of a given XML node.
93 */
95 {
96 public:
97 XmlNodeIterator(rapidxml::xml_node<>* parentNode, const QString& nodeName, bool required);
98
100
101 private:
102 rapidxml::xml_node<>*parentNode, *currentChildNode;
103 const QString& nodeName;
104 const QByteArray nodeNameUtf8;
105 bool required;
106 };
107} // namespace armarx::statechartio
108
110{
111 class XmlReaderException : public LocalException
112 {
113 public:
114 XmlReaderException(const std::string& errorText) :
115 LocalException("Parsing the XML file failed: " + errorText)
116 {
117 }
118
119 std::string
120 name() const override
121 {
122 return "armarx::exceptions::local::XmlReaderException";
123 }
124 };
125} // namespace armarx::exceptions::local
QString readAttribute(rapidxml::xml_node<> *node, const QString &attributeName, bool required=true)
std::string name() const override
Definition XmlReader.h:120
XmlReaderException(const std::string &errorText)
Definition XmlReader.h:114
XmlNodeIterator(rapidxml::xml_node<> *parentNode, const QString &nodeName, bool required)
armarx::statechartmodel::StatePtr getLoadedState() const
Returns the State object created by this XML reader.
Definition XmlReader.h:59
void parseXml(const QString &xmlString)
Parses the given XML document and builds a State object (that can be retrieved using getRootState()).
Definition XmlReader.cpp:45
XmlReader(Ice::CommunicatorPtr iceCommunicator, VariantInfoPtr info)
Creates a new XmlReader.
Definition XmlReader.cpp:39
Class representing a node of XML document.
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
std::shared_ptr< State > StatePtr
Definition State.h:48
QMap< QString, StateParameterPtr > StateParameterMap
std::shared_ptr< StateInstance > StateInstancePtr
QList< ParameterMappingPtr > ParameterMappingList
Definition XmlWriter.h:49
QList< TransitionPtr > TransitionList
Definition State.h:50
QList< EventPtr > EventList
Definition XmlWriter.h:47
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.