15 #ifndef DD_DD_TO_XML_FACTORY_H_INCLUDED
16 #define DD_DD_TO_XML_FACTORY_H_INCLUDED
37 template <
typename DOM_NODE_TYPE>
51 const char* attribute_name,
72 const char* attribute_name,
73 const std::string& value)
76 dom_node.setAttribute(attribute_name, value);
89 static void setData(DOM_NODE_TYPE& dom_node,
90 const std::string& sub_node_name,
91 const std::string& value)
93 DOM_NODE_TYPE sub_node = dom_node.createChild(sub_node_name);
94 sub_node.setData(value);
105 DOM_NODE_TYPE sub_node = parent_node.createChild(
"header");
113 for (
auto ext = declarations.cbegin(); ext != declarations.cend(); ++ext) {
114 DOM_NODE_TYPE sub_ext_node = sub_node.createChild(
"ext_declaration");
115 sub_ext_node.setAttribute(
"key", ext->second->getKey());
116 sub_ext_node.setAttribute(
"value", ext->second->getValue());
128 DOM_NODE_TYPE sub_node = parent_node.createChild(
"baseunit");
129 sub_node.setAttribute(
"name",
base_unit.getName());
130 sub_node.setAttribute(
"symbol",
base_unit.getSymbol());
131 sub_node.setAttribute(
"description",
base_unit.getDescription());
142 DOM_NODE_TYPE sub_node = parent_node.createChild(
"prefixes");
143 sub_node.setAttribute(
"name", unit_prefix.
getName());
145 sub_node.setAttribute(
"power", power);
146 sub_node.setAttribute(
"symbol", unit_prefix.
getSymbol());
157 DOM_NODE_TYPE sub_node = parent_node.createChild(
"unit");
158 sub_node.setAttribute(
"name",
unit.getName());
159 setData(sub_node,
"numerator",
unit.getNumerator());
160 setData(sub_node,
"denominator",
unit.getDenominator());
162 const auto& ref_units =
unit.getRefUnits();
163 for (
auto ref_unit = ref_units.cbegin(); ref_unit != ref_units.cend(); ++ref_unit) {
164 DOM_NODE_TYPE sub_node_elem = sub_node.createChild(
"refUnit");
165 sub_node_elem.setAttribute(
"name", (*ref_unit).getUnitName());
166 sub_node_elem.setAttribute(
"power",
std::to_string((*ref_unit).getPower()));
167 sub_node_elem.setAttribute(
"prefix", (*ref_unit).getPrefixName());
180 const Version& file_ddl_version)
182 DOM_NODE_TYPE sub_node = parent_node.createChild(
"datatype");
186 if (file_ddl_version >=
Version(3, 0)) {
187 sub_node.setAttribute(
"name",
data_type.getName());
190 sub_node.setAttribute(
"type",
data_type.getName());
195 setOptionalAttribute<size_t>(sub_node,
"arraysize",
data_type.getArraySize());
198 if (file_ddl_version >=
Version(3, 0)) {
212 DOM_NODE_TYPE sub_node = parent_node.createChild(
"enum");
213 sub_node.setAttribute(
"name",
enum_type.getName());
214 sub_node.setAttribute(
"type",
enum_type.getDataTypeName());
215 const auto& elems =
enum_type.getElements();
216 for (
auto elem = elems.cbegin(); elem != elems.cend(); ++elem) {
217 DOM_NODE_TYPE sub_node_elem = sub_node.createChild(
"element");
218 sub_node_elem.setAttribute(
"name", elem->second->getName());
219 sub_node_elem.setAttribute(
"value", elem->second->getValue());
232 const Version& file_ddl_version)
234 DOM_NODE_TYPE sub_node = parent_node.createChild(
"element");
235 sub_node.setAttribute(
"name", element.
getName());
236 sub_node.setAttribute(
"type", element.
getTypeName());
239 DOM_NODE_TYPE* serialized_node = &sub_node;
240 DOM_NODE_TYPE serialized_node_version_40;
241 if (file_ddl_version >=
Version(4, 0)) {
242 serialized_node_version_40 = sub_node.createChild(
"serialized");
243 serialized_node = &serialized_node_version_40;
246 serialized_node->setAttribute(
"byteorder",
248 setOptionalAttribute<size_t>(*serialized_node,
"bitpos", element.
getBitPos());
249 setOptionalAttribute<size_t>(*serialized_node,
"numbits", element.
getNumBits());
251 DOM_NODE_TYPE* deserialized_node = &sub_node;
252 DOM_NODE_TYPE deserialized_node_version_40;
253 if (file_ddl_version >=
Version(4, 0)) {
254 deserialized_node_version_40 = sub_node.createChild(
"deserialized");
255 deserialized_node = &deserialized_node_version_40;
270 if (array_size == 0) {
276 if (file_ddl_version >=
Version(2, 0)) {
280 if (file_ddl_version >=
Version(3, 0)) {
287 if (file_ddl_version >=
Version(4, 2)) {
300 const Version& file_ddl_version)
302 DOM_NODE_TYPE sub_node = parent_node.createChild(
"struct");
303 sub_node.setAttribute(
"name",
struct_type.getName());
304 sub_node.setAttribute(
"version",
struct_type.getVersion());
306 setOptionalAttribute<size_t>(sub_node,
"alignment",
struct_type.getAlignment());
309 sub_node.setAttribute(
"ddlversion",
313 for (
auto elem = elements.cbegin(); elem != elements.cend(); ++elem) {
314 auto current_elem = *elem;
315 createNode(sub_node, *current_elem, file_ddl_version);
327 DOM_NODE_TYPE sub_node = parent_node.createChild(
"streammetatype");
333 for (
auto prop = props.cbegin(); prop != props.cend(); ++prop) {
334 DOM_NODE_TYPE sub_prop_node = sub_node.createChild(
"property");
335 sub_prop_node.setAttribute(
"name", prop->second->getName());
336 sub_prop_node.setAttribute(
"type", prop->second->getType());
348 DOM_NODE_TYPE sub_node = parent_node.createChild(
"stream");
349 sub_node.setAttribute(
"name", stream.
getName());
353 const auto& stream_structs = stream.
getStructs();
354 for (
auto stream_struct = stream_structs.cbegin(); stream_struct != stream_structs.cend();
356 DOM_NODE_TYPE sub_struct_node = sub_node.createChild(
"struct");
358 sub_struct_node.setAttribute(
"type", (*stream_struct)->getTypeName());
359 auto byte_pos = (*stream_struct)->getBytePos();
363 sub_struct_node.setAttribute(
"bytepos",
std::to_string(*byte_pos));
377 DOM_NODE_TYPE units_node = parent_node.createChild(
"units");
385 for (
auto unit_prefix = unit_prefixes.cbegin(); unit_prefix != unit_prefixes.cend();
387 createNode(units_node, *(unit_prefix->second));
391 for (
auto unit = units.cbegin();
unit != units.cend(); ++
unit) {
396 DOM_NODE_TYPE data_types_node = parent_node.createChild(
"datatypes");
402 DOM_NODE_TYPE enum_types_node = parent_node.createChild(
"enums");
408 DOM_NODE_TYPE struct_types_node = parent_node.createChild(
"structs");
417 DOM_NODE_TYPE stream_meta_types_node = parent_node.createChild(
"streammetatypes");
426 DOM_NODE_TYPE streams_node = parent_node.createChild(
"streams");
428 for (
auto stream = streams.cbegin(); stream != streams.cend(); ++stream) {
OO DataDefinition Optional Implementation.
bool isDynamicArraySize() const
indicates if this is a dynamic erray size.
size_t getArraySizeValue() const
get the array size
const std::string & getArraySizeElementName() const
gets the dynamic array size
static std::string toString(ByteOrder byte_order)
convert byte_order to a string.
static std::string toString(const Version &version)
Version to string conversion.
DataDefinition Datamodel This datamodel is observable for any change of:
const EnumTypes & getEnumTypes() const
Get the Enum Types object.
const BaseUnits & getBaseUnits() const
Get the Base Units object.
const StructTypes & getStructTypes() const
Get the Struct Types object.
std::shared_ptr< const Header > getHeader() const
Get the Header object.
const StreamMetaTypes & getStreamMetaTypes() const
Get the Stream Meta Types object.
const DataTypes & getDataTypes() const
Get the Data Types object.
const Streams & getStreams() const
Get the Streams object.
const Units & getUnits() const
Get the Units object.
Version getVersion() const
Get the DDL Version.
const UnitPrefixes & getUnitPrefixes() const
Get the Unit Prefixes object.
observable DataDefinition object class to describe (POD) DataType.
observable DataDefinition object class to describe EnumType.
observable Stream DataDefinition object.
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.
const std::string & getTypeName() const
Get the Type Name.
const std::string & getDescription() const
Get the Description.
const std::string & getScale() const
Get the Scale (for information only)
const ArraySize & getArraySize() const
Get the Array Size.
const std::string & getComment() const
Get the Comment.
const std::string & getValue() const
Get the value.
const std::string & getMax() const
Get the Max (for information only).
const std::string & getValidElementCount() const
Get the Valid Element Count element name.
const std::string & getName() const
Get the Name.
const std::string & getMin() const
Get the Min (for information only).
const std::string & getUnitName() const
Get the Unit Name.
const std::string & getDefault() const
Get the Default object.
const std::string & getOffset() const
Get the Offset (for information only)
ByteOrder getByteOrder() const
Get the Byte Order.
OptionalSize getBytePos() const
Get the Byte Pos.
OptionalSize getBitPos() const
Get the Bit Pos (if set)
OptionalSize getNumBits() const
Get the Num Bits (if set)
observable DataDefinition object class to describe StructType.
Unit Prefix - datamodel pefixes.
const std::string & getSymbol() const
Get the Symbol.
const std::string & getName() const
Get the Name.
int32_t getPower() const
Get the Power.
OO DataDefinition Redesign.
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.
@ enum_type
the type is a enum type (EnumType)
@ data_type
the type is a data type (DataType)
@ struct_type
the type is a struct type (StructType)
@ stream_meta_type
the type is an stream meta type (StreamMetaType)
@ unit
the unit is a unit (Unit)
@ base_unit
the unit is a base unit (BaseUnit)
definition of the ddl namespace
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!
Template class to create DD DOM nodes with the help of the type DOM_NODE_TYPE.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::BaseUnit &base_unit)
Create a Node for the base_unit.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::DataDefinition &dd)
Create a Node for the DD.
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.
static bool setOptionalAttribute(DOM_NODE_TYPE &dom_node, const char *attribute_name, const std::string &value)
Set the Optional Attribute.
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.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::EnumType &enum_type)
Create a Node for the enum_type.
static bool setOptionalAttribute(DOM_NODE_TYPE &dom_node, const char *attribute_name, const utility::Optional< T > &value)
Set the Optional Attribute.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::Header &header)
Create a Node for the header.
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.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::Unit &unit)
Create a Node for the unit.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::UnitPrefix &unit_prefix)
Create a Node for the unit_prefix.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::Stream &stream)
Create a Node for the stream.
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.
static void createNode(DOM_NODE_TYPE &parent_node, const datamodel::StreamMetaType &stream_meta_type)
Create a Node for the stream_meta_type.
An optional template as long as the std::optional is not available here.
OO DataDefinition Redesign.