preCICE v3.1.2
Loading...
Searching...
No Matches
XMLTag.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <map>
5#include <memory>
6#include <optional>
7#include <set>
8#include <string>
9#include <vector>
10#include "logging/Logger.hpp"
11#include "xml/ConfigParser.hpp"
12#include "xml/XMLAttribute.hpp"
13
14namespace precice {
15namespace xml {
16class ConfigParser;
17}
18} // namespace precice
19
20namespace precice {
21namespace xml {
22
29
31class XMLTag {
33
34public:
36
38
39 template <typename T>
41
43 struct Listener {
44
46
47 virtual ~Listener(){};
55
64 };
65
74
76
85 XMLTag(
86 Listener & listener,
90
97
99 {
100 return _doc;
101 };
102
110
112 XMLTag &addSubtag(const XMLTag &tag);
113
114 const Subtags &getSubtags() const
115 {
116 return _subtags;
117 };
118
120 //XMLTag& removeSubtag ( const std::string& tagName );
121
124
125 // Adds a XML attribute by making a copy of the given attribute.
127
130
133
136
139
141
142 template <typename Container>
144 {
145 std::for_each(subtags.begin(), subtags.end(), [this](auto &s) { this->addSubtag(s); });
146 }
147
153 const std::string &getName() const
154 {
155 return _name;
156 }
157
160 {
161 return _namespace;
162 }
163
165 {
166 return _namespaces;
167 };
168
171 {
172 return _fullName;
173 }
174
176
177 int getIntAttributeValue(const std::string &name, std::optional<int> default_value = std::nullopt) const;
178
180
182
184 {
185 return _doubleAttributes;
186 };
187
189 {
190 return _intAttributes;
191 };
192
194 {
195 return _stringAttributes;
196 };
197
199 {
200 return _booleanAttributes;
201 };
202
207
217 Eigen::VectorXd getEigenVectorXdAttributeValue(
218 const std::string &name,
219 int dimensions) const;
220
221 bool isConfigured() const
222 {
223 return _configured;
224 }
225
227 {
228 return _occurrence;
229 }
230
232 void clear();
233
236
237private:
238 mutable logging::Logger _log{"xml::XMLTag"};
239
241
244
247
250
252
253 bool _configured = false;
254
256
258
260
262
264
266
268
270
272
274
276
277 void areAllSubtagsConfigured() const;
278
279 void resetAttributes();
280};
281
282// ------------------------------------------------------ HEADER IMPLEMENTATION
283
289
295//NoPListener& getNoPListener();
296
302XMLTag getRootTag();
303
305void configure(
306 XMLTag & tag,
308 std::string_view configurationFilename);
309
310} // namespace xml
311} // namespace precice
312
316//std::ostream& operator<< (
317// std::ostream& os,
318// const precice::xml::XMLTag& tag );
std::string name
This class provides a lightweight logger.
Definition Logger.hpp:16
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
const std::string & getNamespace() const
Returns xml namespace.
Definition XMLTag.hpp:159
bool isConfigured() const
Definition XMLTag.hpp:221
void addSubtags(const Container &subtags)
Definition XMLTag.hpp:143
Eigen::VectorXd getEigenVectorXdAttributeValue(const std::string &name, int dimensions) const
Returns Eigen vector attribute value with given dimensions.
Definition XMLTag.cpp:168
std::string getDocumentation() const
Definition XMLTag.hpp:98
std::string _fullName
Combination of name and namespace: _namespace + ":" + _name.
Definition XMLTag.hpp:249
const AttributeMap< Eigen::VectorXd > & getEigenVectorXdAttributes() const
Definition XMLTag.hpp:203
AttributeMap< double > _doubleAttributes
Definition XMLTag.hpp:265
std::map< std::string, bool > _configuredNamespaces
Definition XMLTag.hpp:261
bool hasAttribute(const std::string &attributeName)
Definition XMLTag.cpp:111
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
Definition XMLTag.cpp:142
Occurrence _occurrence
Definition XMLTag.hpp:255
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
Definition XMLTag.cpp:155
AttributeMap< std::string > _stringAttributes
Definition XMLTag.hpp:269
Occurrence getOccurrence() const
Definition XMLTag.hpp:226
void readAttributes(const std::map< std::string, std::string > &aAttributes)
reads all attributes of this tag
Definition XMLTag.cpp:190
XMLTag & setDocumentation(const std::string &documentation)
Adds a description of the purpose of this XML tag.
Definition XMLTag.cpp:29
typename std::vector< std::string > Namespaces
Definition XMLTag.hpp:35
Namespaces _namespaces
Definition XMLTag.hpp:257
std::string _namespace
XML namespace of the tag.
Definition XMLTag.hpp:246
void clear()
Removes all attributes and subtags.
Definition XMLTag.cpp:374
typename std::map< std::string, XMLAttribute< T > > AttributeMap
Definition XMLTag.hpp:40
const Namespaces & getNamespaces() const
Definition XMLTag.hpp:164
std::set< std::string > _attributes
Definition XMLTag.hpp:263
const AttributeMap< std::string > & getStringAttributes() const
Definition XMLTag.hpp:193
const AttributeMap< int > & getIntAttributes() const
Definition XMLTag.hpp:188
Listener & _listener
Definition XMLTag.hpp:240
const std::string & getName() const
Returns name (without namespace).
Definition XMLTag.hpp:153
static std::string getOccurrenceString(Occurrence occurrence)
Definition XMLTag.cpp:411
const std::string & getFullName() const
Returns full name consisting of xml namespace + ":" + name.
Definition XMLTag.hpp:170
Occurrence
Types of occurrences of an XML tag.
Definition XMLTag.hpp:67
AttributeMap< int > _intAttributes
Definition XMLTag.hpp:267
void addAttributeHint(std::string name, std::string message)
Adds a hint for missing attributes, which will be displayed along the error message.
Definition XMLTag.cpp:104
XMLTag(Listener &listener, std::string name, Occurrence occurrence, std::string xmlNamespace="")
Standard constructor.
Definition XMLTag.cpp:12
std::map< std::string, std::string > _attributeHints
Definition XMLTag.hpp:275
std::string _name
Name of the tag.
Definition XMLTag.hpp:243
typename std::vector< std::shared_ptr< XMLTag > > Subtags
Definition XMLTag.hpp:37
int getIntAttributeValue(const std::string &name, std::optional< int > default_value=std::nullopt) const
Definition XMLTag.cpp:129
std::string _doc
Definition XMLTag.hpp:251
XMLTag & addNamespace(const std::string &namespaceName)
Adds a namespace to the tag.
Definition XMLTag.cpp:35
const Subtags & getSubtags() const
Definition XMLTag.hpp:114
const AttributeMap< double > & getDoubleAttributes() const
Definition XMLTag.hpp:183
logging::Logger _log
Definition XMLTag.hpp:238
AttributeMap< bool > _booleanAttributes
Definition XMLTag.hpp:271
double getDoubleAttributeValue(const std::string &name, std::optional< double > default_value=std::nullopt) const
Definition XMLTag.cpp:116
const AttributeMap< bool > & getBooleanAttributes() const
Definition XMLTag.hpp:198
XMLTag & addAttribute(const XMLAttribute< double > &attribute)
Removes the XML subtag with given name.
Definition XMLTag.cpp:53
XMLTag & addSubtag(const XMLTag &tag)
Adds an XML tag as subtag by making a copy of the given tag.
Definition XMLTag.cpp:41
void areAllSubtagsConfigured() const
Definition XMLTag.cpp:314
AttributeMap< Eigen::VectorXd > _eigenVectorXdAttributes
Definition XMLTag.hpp:273
T for_each(T... args)
XMLTag getRootTag()
Returns an XMLTag::Listener that does nothing on callbacks.
Definition XMLTag.cpp:389
void configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition XMLTag.cpp:395
Main namespace of the precice library.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24
No operation listener for tests.
Definition XMLTag.hpp:285
void xmlTagCallback(ConfigurationContext const &context, XMLTag &callingTag) override
Callback at begin of XML tag.
Definition XMLTag.hpp:286
void xmlEndTagCallback(ConfigurationContext const &context, XMLTag &callingTag) override
Callback at end of XML tag and at end of subtag.
Definition XMLTag.hpp:287
Callback interface for configuration classes using XMLTag.
Definition XMLTag.hpp:43
virtual void xmlTagCallback(ConfigurationContext const &context, XMLTag &callingTag)=0
Callback at begin of XML tag.
Listener & operator=(Listener &&)=delete
virtual void xmlEndTagCallback(ConfigurationContext const &context, XMLTag &callingTag)=0
Callback at end of XML tag and at end of subtag.