Dev Essential  1.6.3
Loading...
Searching...
No Matches
datamodel_xml_configurationtoxml_base.h
Go to the documentation of this file.
1
20
21#ifndef MAPPING_CONFIGURATION_TO_XML_BASE_H_INCLUDED
22#define MAPPING_CONFIGURATION_TO_XML_BASE_H_INCLUDED
23
26
27#include <stdexcept>
28#include <string>
29
30namespace ddl {
31namespace mapping {
32
42template <typename DomNodeType>
54 template <typename T>
55 static bool setOptionalAttribute(DomNodeType& dom_node,
56 const char* attribute_name,
57 const utility::Optional<T>& value)
58 {
59 if (value) {
60 dom_node.setAttribute(attribute_name, std::to_string(*value));
61 return true;
62 }
63 return false;
64 }
65
76 static bool setOptionalAttribute(DomNodeType& dom_node,
77 const char* attribute_name,
78 const std::string& value)
79 {
80 if (!value.empty()) {
81 dom_node.setAttribute(attribute_name, value);
82 return true;
83 }
84 return false;
85 }
86
93 static void setSubNodeData(DomNodeType& dom_node,
94 const std::string& sub_node_name,
95 const std::string& value)
96 {
97 DomNodeType sub_node = dom_node.createChild(sub_node_name);
98 sub_node.setData(value);
99 }
100
107 static void setOptionalSubNodeData(DomNodeType& dom_node,
108 const std::string& sub_node_name,
109 const std::string& value)
110 {
111 if (!value.empty()) {
112 setSubNodeData(dom_node, sub_node_name, value);
113 }
114 }
115};
116} // namespace mapping
117} // namespace ddl
118
119#endif // MAPPING_CONFIGURATION_TO_XML_BASE_H_INCLUDED
definition of the mapping namespace
Definition ddl.h:50
definition of the ddl namespace
Definition codec.h:21
An optional template as long as the std::optional is not available here.
Definition access_optional.h:31
Template class to create MappingConfiguration DOM nodes with the help of the type DomNodeType.
Definition datamodel_xml_configurationtoxml_base.h:43
static bool setOptionalAttribute(DomNodeType &dom_node, const char *attribute_name, const std::string &value)
Set the Optional Attribute. This will only set the attribute if the value is not empty.
Definition datamodel_xml_configurationtoxml_base.h:76
static bool setOptionalAttribute(DomNodeType &dom_node, const char *attribute_name, const utility::Optional< T > &value)
Set the Optional Attribute. This will only set the attribute if the value is valid.
Definition datamodel_xml_configurationtoxml_base.h:55
static void setOptionalSubNodeData(DomNodeType &dom_node, const std::string &sub_node_name, const std::string &value)
Set the data of the new created tag with the name sub_node_name.
Definition datamodel_xml_configurationtoxml_base.h:107
static void setSubNodeData(DomNodeType &dom_node, const std::string &sub_node_name, const std::string &value)
Set the data of the new created tag with the name sub_node_name.
Definition datamodel_xml_configurationtoxml_base.h:93