ADTF
datamodel_xml_configurationtoxml_base.h
Go to the documentation of this file.
1 
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 
30 namespace ddl {
31 namespace mapping {
32 
42 template <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
OO DataDefinition Optional Implementation.
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!
Template class to create MappingConfiguration DOM nodes with the help of the type DomNodeType.
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.
static bool setOptionalAttribute(DomNodeType &dom_node, const char *attribute_name, const utility::Optional< T > &value)
Set the Optional Attribute.
static bool setOptionalAttribute(DomNodeType &dom_node, const char *attribute_name, const std::string &value)
Set the Optional Attribute.
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.