15#ifndef DD_DD_TO_XML_FACTORY_H_INCLUDED
16#define DD_DD_TO_XML_FACTORY_H_INCLUDED
38template <
typename DOM_NODE_TYPE>
52 const std::string& attribute_name,
56 dom_node.setAttribute(attribute_name, std::to_string(*value));
73 const std::string& attribute_name,
74 const std::string& value)
77 dom_node.setAttribute(attribute_name, value);
90 static void setData(DOM_NODE_TYPE& dom_node,
91 const std::string& sub_node_name,
92 const std::string& value)
94 DOM_NODE_TYPE sub_node = dom_node.createChild(sub_node_name);
95 sub_node.setData(value);
106 const auto& literals = DDXmlLiterals::getInstance();
107 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.header);
109 literals.language_version,
116 for (
auto ext = declarations.cbegin(); ext != declarations.cend(); ++ext) {
117 DOM_NODE_TYPE sub_ext_node = sub_node.createChild(literals.ext_declaration);
118 sub_ext_node.setAttribute(literals.key, ext->second->getKey());
119 sub_ext_node.setAttribute(literals.value, ext->second->getValue());
131 const auto& literals = DDXmlLiterals::getInstance();
132 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.baseunit);
133 sub_node.setAttribute(literals.name,
base_unit.getName());
134 sub_node.setAttribute(literals.symbol,
base_unit.getSymbol());
135 sub_node.setAttribute(literals.description,
base_unit.getDescription());
146 const auto& literals = DDXmlLiterals::getInstance();
147 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.prefixes);
148 sub_node.setAttribute(literals.name,
unit_prefix.getName());
149 auto power = std::to_string(
unit_prefix.getPower());
150 sub_node.setAttribute(literals.power, power);
151 sub_node.setAttribute(literals.symbol,
unit_prefix.getSymbol());
162 const auto& literals = DDXmlLiterals::getInstance();
163 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.unit);
164 sub_node.setAttribute(literals.name,
unit.getName());
165 setData(sub_node, literals.numerator,
unit.getNumerator());
166 setData(sub_node, literals.denominator,
unit.getDenominator());
167 setData(sub_node, literals.offset,
unit.getOffset());
168 const auto& ref_units =
unit.getRefUnits();
169 for (
auto ref_unit = ref_units.cbegin(); ref_unit != ref_units.cend(); ++ref_unit) {
170 DOM_NODE_TYPE sub_node_elem = sub_node.createChild(literals.refUnit);
171 sub_node_elem.setAttribute(literals.name, (*ref_unit).getUnitName());
172 sub_node_elem.setAttribute(literals.power, std::to_string((*ref_unit).getPower()));
173 sub_node_elem.setAttribute(literals.prefix, (*ref_unit).getPrefixName());
186 const Version& file_ddl_version)
188 const auto& literals = DDXmlLiterals::getInstance();
189 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.datatype);
193 if (file_ddl_version >=
Version(3, 0)) {
194 sub_node.setAttribute(literals.name,
data_type.getName());
197 sub_node.setAttribute(literals.type__,
data_type.getName());
199 sub_node.setAttribute(literals.size, std::to_string(
data_type.getBitSize()));
205 if (file_ddl_version >=
Version(3, 0)) {
219 const auto& literals = DDXmlLiterals::getInstance();
220 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.enum__);
221 sub_node.setAttribute(literals.name,
enum_type.getName());
222 sub_node.setAttribute(literals.type__,
enum_type.getDataTypeName());
223 const auto& elems =
enum_type.getElements();
224 for (
auto elem = elems.cbegin(); elem != elems.cend(); ++elem) {
225 DOM_NODE_TYPE sub_node_elem = sub_node.createChild(literals.element);
226 sub_node_elem.setAttribute(literals.name, elem->second->getName());
227 sub_node_elem.setAttribute(literals.value, elem->second->getValue());
240 const Version& file_ddl_version)
242 const auto& literals = DDXmlLiterals::getInstance();
243 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.element);
244 sub_node.setAttribute(literals.name, element.
getName());
245 sub_node.setAttribute(literals.type__, element.
getTypeName());
248 DOM_NODE_TYPE* serialized_node = &sub_node;
249 DOM_NODE_TYPE serialized_node_version_40;
250 if (file_ddl_version >=
Version(4, 0)) {
251 serialized_node_version_40 = sub_node.createChild(literals.serialized);
252 serialized_node = &serialized_node_version_40;
254 serialized_node->setAttribute(literals.bytepos, std::to_string(*element.
getBytePos()));
255 serialized_node->setAttribute(literals.byteorder,
260 DOM_NODE_TYPE* deserialized_node = &sub_node;
261 DOM_NODE_TYPE deserialized_node_version_40;
262 if (file_ddl_version >=
Version(4, 0)) {
263 deserialized_node_version_40 = sub_node.createChild(literals.deserialized);
264 deserialized_node = &deserialized_node_version_40;
266 deserialized_node->setAttribute(literals.alignment, std::to_string(element.
getAlignment()));
279 if (array_size == 0) {
282 sub_node.setAttribute(literals.arraysize, std::to_string(array_size));
285 if (file_ddl_version >=
Version(2, 0)) {
289 if (file_ddl_version >=
Version(3, 0)) {
296 if (file_ddl_version >=
Version(4, 2)) {
310 const Version& file_ddl_version)
312 const auto& literals = DDXmlLiterals::getInstance();
313 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.struct__);
314 sub_node.setAttribute(literals.name,
struct_type.getName());
315 sub_node.setAttribute(literals.version,
struct_type.getVersion());
320 sub_node.setAttribute(literals.ddlversion,
324 for (
auto elem = elements.cbegin(); elem != elements.cend(); ++elem) {
325 auto current_elem = *elem;
326 createNode(sub_node, *current_elem, file_ddl_version);
338 const auto& literals = DDXmlLiterals::getInstance();
339 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.streammetatype);
345 for (
auto prop = props.cbegin(); prop != props.cend(); ++prop) {
346 DOM_NODE_TYPE sub_prop_node = sub_node.createChild(literals.property);
347 sub_prop_node.setAttribute(literals.name, prop->second->getName());
348 sub_prop_node.setAttribute(literals.type__, prop->second->getType());
360 const auto& literals = DDXmlLiterals::getInstance();
361 DOM_NODE_TYPE sub_node = parent_node.createChild(literals.stream);
362 sub_node.setAttribute(literals.name, stream.
getName());
366 const auto& stream_structs = stream.
getStructs();
367 for (
auto stream_struct = stream_structs.cbegin(); stream_struct != stream_structs.cend();
369 DOM_NODE_TYPE sub_struct_node = sub_node.createChild(literals.struct__);
371 sub_struct_node.setAttribute(literals.type__, (*stream_struct)->getTypeName());
372 auto byte_pos = (*stream_struct)->getBytePos();
376 sub_struct_node.setAttribute(literals.bytepos, std::to_string(*byte_pos));
388 const auto& literals = DDXmlLiterals::getInstance();
392 DOM_NODE_TYPE units_node = parent_node.createChild(literals.units);
394 const auto& base_units =
dd.getBaseUnits();
399 const auto& unit_prefixes =
dd.getUnitPrefixes();
405 const auto& units =
dd.getUnits();
406 for (
auto unit = units.cbegin();
unit != units.cend(); ++
unit) {
411 DOM_NODE_TYPE data_types_node = parent_node.createChild(literals.datatypes);
412 const auto& data_types =
dd.getDataTypes();
417 DOM_NODE_TYPE enum_types_node = parent_node.createChild(literals.enums);
418 const auto& enum_types =
dd.getEnumTypes();
423 DOM_NODE_TYPE struct_types_node = parent_node.createChild(literals.structs);
424 const auto& struct_types =
dd.getStructTypes();
432 DOM_NODE_TYPE stream_meta_types_node =
433 parent_node.createChild(literals.streammetatypes);
434 const auto& stream_meta_types_types =
dd.getStreamMetaTypes();
442 DOM_NODE_TYPE streams_node = parent_node.createChild(literals.streams);
443 const auto& streams =
dd.getStreams();
444 for (
auto stream = streams.cbegin(); stream != streams.cend(); ++stream) {
size_t getArraySizeValue() const
const std::string & getArraySizeElementName() const
bool isDynamicArraySize() const
static std::string toString(ByteOrder byte_order)
convert byte_order to a string.
static std::string toString(const Version &version)
Version to string conversion.
DDL Version.
Definition dd_common_types.h:203
BaseUnit.
Definition datamodel_units.h:108
DataDefinition Datamodel This datamodel is observable for any change of:
Definition datamodel_datadefinition.h:64
observable DataDefinition object class to describe (POD) DataType.
Definition datamodel_types.h:113
observable DataDefinition object class to describe EnumType.
Definition datamodel_types.h:320
observable Stream DataDefinition object.
Definition datamodel_streams.h:41
const std::string & getDescription() const
Get the Description.
const Structs & getStructs() const
Get the Structs object.
const std::string & getName() const
Get the Name.
const std::string & getStreamTypeName() const
Get the Stream Type Name.
virtual size_t getAlignment() const
Get the Alignment.
observable DataDefinition object class for a Element of a StructType.
Definition datamodel_types.h:736
const std::string & getDefault() const
Get the Default object.
const std::string & getScale() const
Get the Scale (for information only)
const std::string & getOffset() const
Get the Offset (for information only)
const std::string & getDescription() const
Get the Description.
const std::string & getComment() const
Get the Comment.
const std::string & getUnitName() const
Get the Unit Name.
const std::string & getName() const
Get the Name.
const std::string & getValue() const
Get the value.
const std::string & getMin() const
Get the Min (for information only). This was introduced in DDL 3.0.
const std::string & getTypeName() const
Get the Type Name.
const std::string & getMax() const
Get the Max (for information only). This was introduced in DDL 3.0.
const std::string & getValidElementCount() const
Get the Valid Element Count element name.
const ArraySize & getArraySize() const
Get the Array Size.
OptionalSize getNumBits() const
Get the Num Bits (if set)
OptionalSize getBitPos() const
Get the Bit Pos (if set)
OptionalSize getBytePos() const
Get the Byte Pos.
ByteOrder getByteOrder() const
Get the Byte Order.
observable DataDefinition object class to describe StructType.
Definition datamodel_types.h:453
Unit Prefix - datamodel pefixes.
Definition datamodel_units.h:221
BaseUnit.
Definition datamodel_units.h:338
definition of the dd namespace
Definition datamodel_base.h:26
@ base_unit
the unit is a base unit (BaseUnit)
Definition dd_common_types.h:91
@ unit
the unit is a unit (Unit)
Definition dd_common_types.h:86
@ struct_type
the type is a struct type (StructType)
Definition dd_common_types.h:64
@ data_type
the type is a data type (DataType)
Definition dd_common_types.h:54
@ stream_meta_type
the type is an stream meta type (StreamMetaType)
Definition dd_common_types.h:69
@ enum_type
the type is a enum type (EnumType)
Definition dd_common_types.h:59
definiton of the unit prefixes namespace
Definition dd_predefined_units.h:61
definition of the ddl namespace
Definition codec.h:21
Template class to create DD DOM nodes with the help of the type DOM_NODE_TYPE.
Definition xml_ddtoxml_factory.h:39
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::DataDefinition &dd)
Create a Node for the DD.
Definition xml_ddtoxml_factory.h:386
static void setData(DOM_NODE_TYPE &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 xml_ddtoxml_factory.h:90
static bool setOptionalAttribute(DOM_NODE_TYPE &dom_node, const std::string &attribute_name, const utility::Optional< T > &value)
Set the Optional Attribute. This will only set the attribute if the value is valid.
Definition xml_ddtoxml_factory.h:51
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::Header &header)
Create a Node for the header.
Definition xml_ddtoxml_factory.h:104
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::BaseUnit &base_unit)
Create a Node for the base_unit.
Definition xml_ddtoxml_factory.h:129
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::StreamMetaType &stream_meta_type)
Create a Node for the stream_meta_type.
Definition xml_ddtoxml_factory.h:335
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::StructType &struct_type, const Version &file_ddl_version)
Create a Node for the struct_type.
Definition xml_ddtoxml_factory.h:308
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::StructType::Element &element, const Version &file_ddl_version)
Create a Node for the struct_type element.
Definition xml_ddtoxml_factory.h:238
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::Unit &unit)
Create a Node for the unit.
Definition xml_ddtoxml_factory.h:160
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::EnumType &enum_type)
Create a Node for the enum_type.
Definition xml_ddtoxml_factory.h:217
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::Stream &stream)
Create a Node for the stream.
Definition xml_ddtoxml_factory.h:358
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::UnitPrefix &unit_prefix)
Create a Node for the unit_prefix.
Definition xml_ddtoxml_factory.h:144
static bool setOptionalAttribute(DOM_NODE_TYPE &dom_node, const std::string &attribute_name, const std::string &value)
Set the Optional Attribute. This will only set the attribute if the value is not empty.
Definition xml_ddtoxml_factory.h:72
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::DataType &data_type, const Version &file_ddl_version)
Create a Node for the data_type.
Definition xml_ddtoxml_factory.h:184
An optional template as long as the std::optional is not available here.
Definition access_optional.h:31