21#ifndef MAPPING_CONFIGURATION_FROM_XML_BASE_INCLUDED
22#define MAPPING_CONFIGURATION_FROM_XML_BASE_INCLUDED
47template <
typename DomNodeType>
68 const std::string& attribute_name,
70 bool is_mandatory =
false,
71 const std::string& parse_error_message = {},
72 const std::string& mapping_reading_version = {})
74 auto value = dom_node.getAttribute(attribute_name);
77 throw utility::Error(std::string(mapping_reading_version) +
"::getAttribute",
78 {
"...", attribute_name},
104 template <
typename T>
107 bool is_mandatory =
false,
108 const std::string& parse_error_message =
"",
109 const std::string& mapping_reading_version = {})
111 const std::string value = dom_node.getData();
114 throw utility::Error(std::string(mapping_reading_version) +
"::getData ",
115 {dom_node.getName(),
"..."},
116 parse_error_message);
118 return default_value;
142 template <
typename T>
144 const std::string& sub_node_name,
146 bool is_mandatory =
false,
147 const std::string& parse_error_message = {},
148 const std::string& mapping_reading_version = {})
150 DomNodeType sub_node;
151 std::string value = {};
152 if (dom_node.findNode(sub_node_name, sub_node)) {
153 return getData<T>(sub_node, default_value, is_mandatory, parse_error_message);
157 throw Error(std::string(mapping_reading_version) +
"getDataSubNode",
158 {dom_node.getName(), sub_node_name},
159 parse_error_message);
161 return default_value;
171 std::stringstream& property_stream)
173 if (!attributes.empty()) {
174 for (
const auto& current: attributes) {
175 property_stream <<
" " << current.first <<
"=\"" << current.second <<
"\"";
187 std::stringstream& property_stream,
190 const std::string tab(level,
' ');
191 const auto data = dom_node.getData();
192 if (!data.empty() && level != 0) {
193 property_stream << tab <<
"<" << dom_node.getName();
195 property_stream <<
">";
196 property_stream << data;
197 property_stream << tab <<
"</" << dom_node.getName() <<
">" << std::endl;
200 const auto nodes = dom_node.getChildren();
201 if (nodes.empty() && level != 0) {
202 property_stream << tab <<
"<" << dom_node.getName();
204 property_stream <<
"/>" << std::endl;
208 property_stream << tab <<
"<" << dom_node.getName();
210 property_stream <<
">" << std::endl;
212 for (
const auto& current: nodes) {
216 property_stream << tab <<
"</" << dom_node.getName() <<
">" << std::endl;
229 template <
typename PropertiesType>
231 const std::string& property_name,
232 PropertiesType& properties_target)
234 auto data = dom_node.getData();
238 properties_target.emplace({property_name, data});
241 std::stringstream prop_stream;
243 properties_target.emplace({property_name, prop_stream.str()});
definition of the mapping namespace
Definition ddl.h:50
ddl::utility::Error Error
mapping error definition
Definition mapping_configuration_types.h:35
void replaceInString(std::string &string_data, const std::string &to_replace, const std::string &replace_with)
In place replacement helper function.
::ddl::dd::Error Error
Exception helper class to collect information while parsing, adding DD Objects or other failed operat...
Definition ddl_error.h:110
Optional< int > toType(const std::string &from_string, const Optional< int > &default_value={})
specialized conversion to the Optional<int>
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
Factory helper to create a MappingConfiguration out of a XML based description. This factory uses a t...
Definition datamodel_xml_configurationfromxml_base.h:48
static utility::Optional< T > getDataSubNode(const DomNodeType &dom_node, const std::string &sub_node_name, const utility::Optional< T > &default_value={}, bool is_mandatory=false, const std::string &parse_error_message={}, const std::string &mapping_reading_version={})
Get the data content of a subnode of dom_node. Return a valid Optional<T> if set, otherwise return de...
Definition datamodel_xml_configurationfromxml_base.h:143
static void nodeToString(const DomNodeType &dom_node, std::stringstream &property_stream, size_t level=0)
Helper function to serialize a xml node to a string.
Definition datamodel_xml_configurationfromxml_base.h:186
static void attributesToString(const std::map< std::string, std::string > &attributes, std::stringstream &property_stream)
Helper function to serialize xml attributes to a string.
Definition datamodel_xml_configurationfromxml_base.h:170
static utility::Optional< T > getAttribute(const DomNodeType &dom_node, const std::string &attribute_name, const utility::Optional< T > &default_value={}, bool is_mandatory=false, const std::string &parse_error_message={}, const std::string &mapping_reading_version={})
Get the Attribute from the dom_node. Return a valid Optional<T> if set, otherwise return default_valu...
Definition datamodel_xml_configurationfromxml_base.h:67
static utility::Optional< T > getData(const DomNodeType &dom_node, const utility::Optional< T > &default_value={}, bool is_mandatory=false, const std::string &parse_error_message="", const std::string &mapping_reading_version={})
Get the data content of a subnode of dom_node. Return a valid Optional<T> if set, otherwise return de...
Definition datamodel_xml_configurationfromxml_base.h:105
static void setDataOrSubNodesAsProperty(const DomNodeType &dom_node, const std::string &property_name, PropertiesType &properties_target)
Set the Data Or Sub Nodes As Property.
Definition datamodel_xml_configurationfromxml_base.h:230