15#ifndef DD_DD_FROM_XML_FACTORY_H_INCLUDED
16#define DD_DD_FROM_XML_FACTORY_H_INCLUDED
44T
toType(std::string from_string, T default_value)
noexcept;
56inline int toType<int>(std::string from_string,
int default_value)
noexcept
59 int i_converted = std::stoi(std::move(from_string));
62 catch (
const std::invalid_argument&) {
65 catch (
const std::exception&) {
73 int i_converted = std::stoi(std::move(from_string));
78inline size_t toType<size_t>(std::string from_string,
size_t default_value)
noexcept
81 int size_converted = std::stoi(std::move(from_string));
82 if (size_converted < 0) {
87 return size_converted;
90 catch (
const std::invalid_argument&) {
93 catch (
const std::exception&) {
100 int size_converted = std::stoi(std::move(from_string));
101 if (size_converted < 0) {
106 return size_converted;
110inline std::string
toType<std::string>(std::string from_string, std::string default_value)
noexcept
112 if (from_string.empty()) {
113 return std::move(default_value);
116 return std::move(from_string);
122 using namespace std::string_literals;
123 if (from_string.empty()) {
124 throw std::invalid_argument(
"Empty string"s);
127 return std::move(from_string);
144template <
typename DOM_NODE_TYPE>
151 static bool isInteger(
const std::string& string_to_check)
noexcept
170 template <
typename T>
172 const std::string& attribute_name,
175 using namespace std::string_literals;
176 auto value = dom_node.getAttribute(attribute_name);
184 catch (
const std::exception& e) {
185 throw Error(
"DDFromXMLFactory::getAttribute"s,
186 {
"..."s, attribute_name},
187 dom_node.getName() +
" has invalid data in "s + attribute_name +
188 " attribute: "s + e.what());
193 template <
typename T>
195 const std::string& attribute_name,
196 T default_value)
noexcept
198 using namespace std::string_literals;
199 auto value = dom_node.getAttribute(attribute_name);
201 return std::move(default_value);
204 return detail::toType<T>(std::move(value), std::move(default_value));
208 template <
typename T>
210 const std::string& attribute_name,
213 using namespace std::string_literals;
214 auto value = dom_node.getAttribute(attribute_name);
216 throw Error(
"DDFromXMLFactory::getAttribute"s,
217 {
"..."s, attribute_name},
218 dom_node.getName() +
" has no mandatory "s + attribute_name +
223 return detail::toRequiredType<T>(std::move(value));
225 catch (
const std::exception& e) {
226 throw Error(
"DDFromXMLFactory::getAttribute"s,
227 {
"..."s, attribute_name},
228 dom_node.getName() +
" has invalid data in "s + attribute_name +
229 " attribute: "s + e.what());
248 template <
typename T>
250 const std::string& sub_node_name,
253 using namespace std::string_literals;
254 DOM_NODE_TYPE sub_node;
255 std::string value = {};
256 if (dom_node.findNode(sub_node_name, sub_node)) {
257 value = sub_node.getData();
266 catch (
const std::exception& e) {
267 throw Error(
"DDFromXMLFactory::getData"s,
268 {
"..."s, sub_node_name},
269 dom_node.getName() +
" has invalid data in '"s + sub_node_name +
270 "' child:"s + e.what());
275 template <
typename T>
276 static T
getData(
const DOM_NODE_TYPE& dom_node,
277 const std::string& sub_node_name,
278 T default_value)
noexcept
280 using namespace std::string_literals;
281 DOM_NODE_TYPE sub_node;
282 std::string value = {};
283 if (dom_node.findNode(sub_node_name, sub_node)) {
284 value = sub_node.getData();
287 return std::move(default_value);
290 return detail::toType<T>(std::move(value), std::move(default_value));
293 template <
typename T>
294 static T
getData(
const DOM_NODE_TYPE& dom_node,
295 const std::string& sub_node_name,
298 using namespace std::string_literals;
299 DOM_NODE_TYPE sub_node;
300 std::string value = {};
301 if (dom_node.findNode(sub_node_name, sub_node)) {
302 value = sub_node.getData();
305 throw Error(
"DDFromXMLFactory::getData"s,
306 {
"..."s, sub_node_name},
307 dom_node.getName() +
" has no mandatory '"s + sub_node_name +
"' child."s);
311 return detail::toRequiredType<T>(std::move(value));
313 catch (
const std::exception& e) {
314 throw Error(
"DDFromXMLFactory::getData"s,
315 {
"..."s, sub_node_name},
316 dom_node.getName() +
" has invalid data in '"s + sub_node_name +
317 "' child: "s + e.what());
330 const DOM_NODE_TYPE& dom_node)
332 const auto& literals = DDXmlLiterals::getInstance();
333 using namespace std::string_literals;
347 const auto& literals = DDXmlLiterals::getInstance();
349 std::vector<datamodel::Header::ExtDeclaration> exts;
350 std::list<DOM_NODE_TYPE> header_ext_nodes;
351 if (dom_node.findNodes(literals.ext_declaration, header_ext_nodes)) {
352 for (
const auto& current_header_ext_node: header_ext_nodes) {
358 if (
auto file_ddl_version =
371 std::move(date_creation),
372 std::move(date_change),
373 std::move(description),
385 const auto& literals = DDXmlLiterals::getInstance();
400 const auto& literals = DDXmlLiterals::getInstance();
415 const auto& literals = DDXmlLiterals::getInstance();
430 const auto& literals = DDXmlLiterals::getInstance();
433 std::vector<datamodel::Unit::RefUnit> ref_units;
434 std::list<DOM_NODE_TYPE> ref_unit_nodes;
435 if (dom_node.findNodes(literals.refUnit, ref_unit_nodes)) {
436 for (
const auto& current_ref_unit_node: ref_unit_nodes) {
437 ref_units.emplace_back(
createRefUnit(current_ref_unit_node));
445 std::move(numerator),
446 std::move(denominator),
461 const Version& file_ddl_version,
464 const auto& literals = DDXmlLiterals::getInstance();
470 if (strict && (file_ddl_version >=
Version(3, 0))) {
487 if (
auto array_size_attrib =
489 array_size = *array_size_attrib;
495 std::string min_val, max_val;
496 if (file_ddl_version >=
Version(3, 0) || file_ddl_version ==
Version(0, 0)) {
501 auto default_type_alignment =
507 std::move(description),
508 std::move(array_size),
509 std::move(unit_name),
512 default_type_alignment);
523 const auto& literals = DDXmlLiterals::getInstance();
537 const auto& literals = DDXmlLiterals::getInstance();
542 std::list<DOM_NODE_TYPE> enum_element_nodes;
543 if (dom_node.findNodes(literals.element, enum_element_nodes)) {
544 for (
const auto& current_enum_element_node: enum_element_nodes) {
563 const Version& file_ddl_version,
566 const auto& literals = DDXmlLiterals::getInstance();
576 Version used_file_version = file_ddl_version;
577 if (file_ddl_version ==
Version(0, 0) || !strict) {
580 DOM_NODE_TYPE serialized_node;
581 if (dom_node.findNode(literals.serialized, serialized_node)) {
582 used_file_version =
Version(4, 0);
583 if (dom_node.hasAttribute(literals.valid_element_count)) {
584 used_file_version =
Version(4, 2);
589 used_file_version =
Version(3, 0);
595 if (used_file_version >=
Version(4, 0)) {
596 DOM_NODE_TYPE serialized_node;
597 if (dom_node.findNode(literals.serialized, serialized_node)) {
601 if (byte_pos_int == -1) {
605 byte_pos =
static_cast<size_t>(byte_pos_int);
607 auto byte_order_attrib =
615 throw Error(
"DDFromXMLFactory::getAttribute",
616 "struct/element/deserialized tag was not found");
619 DOM_NODE_TYPE deserialized_node;
620 if (dom_node.findNode(literals.deserialized, deserialized_node)) {
621 auto alignment_attrib =
627 throw Error(
"DDFromXMLFactory::getAttribute",
628 "struct/element/serialized tag was not found");
634 if (byte_pos_int == -1) {
638 byte_pos =
static_cast<size_t>(byte_pos_int);
640 auto byte_order_attrib =
648 auto alignment_attrib =
655 if (
auto arraysize_attrib =
666 if (file_ddl_version >=
Version(2, 0) || file_ddl_version ==
Version(0, 0) ||
668 array_size =
ArraySize(*std::move(arraysize_attrib));
678 std::string value, minimum_value, maximum_value, default_value, scale, offset,
681 if (used_file_version >=
Version(2, 0) || file_ddl_version ==
Version(0, 0) || !strict) {
685 if (used_file_version >=
Version(3, 0) || file_ddl_version ==
Version(0, 0) || !strict) {
693 if (used_file_version >=
Version(4, 2) || file_ddl_version ==
Version(0, 0) || !strict) {
694 valid_element_count =
699 std::move(name_attrib),
700 std::move(type_attrib),
703 std::move(array_size),
704 std::move(description),
706 std::move(unit_name),
708 std::move(minimum_value),
709 std::move(maximum_value),
710 std::move(default_value),
713 std::move(valid_element_count));
726 const Version& file_ddl_version,
729 using namespace std::string_literals;
730 const auto& literals = DDXmlLiterals::getInstance();
733 auto name_attrib = type_attrib ?
741 if (
auto alignment_attrib =
747 auto ddl_version_to_set =
Version(0, 0);
748 if (
auto ddl_version_attrib =
754 std::move(version_attrib),
755 std::move(alignment_to_set),
756 std::move(comment_attrib),
757 std::move(ddl_version_to_set));
759 std::list<DOM_NODE_TYPE> struct_element_nodes;
760 if (dom_node.findNodes(literals.element, struct_element_nodes)) {
761 for (
const auto& current_struct_element_node: struct_element_nodes) {
777 const DOM_NODE_TYPE& dom_node)
779 const auto& literals = DDXmlLiterals::getInstance();
793 const auto& literals = DDXmlLiterals::getInstance();
799 std::move(name_attrib), std::move(version_attrib), std::move(parent_attrib));
802 std::list<DOM_NODE_TYPE> smt_prop_nodes;
803 if (dom_node.findNodes(literals.property, smt_prop_nodes)) {
804 for (
const auto& current_smt_prop_node: smt_prop_nodes) {
820 const auto& literals = DDXmlLiterals::getInstance();
825 std::move(name_attrib), std::move(type_attrib), std::move(byte_pos));
836 const auto& literals = DDXmlLiterals::getInstance();
845 std::move(name_attrib), std::move(type_attrib), std::move(desc_attrib));
847 std::list<DOM_NODE_TYPE> ss_nodes;
848 if (dom_node.findNodes(literals.struct__, ss_nodes)) {
849 for (
const auto& current_stream_struct_node: ss_nodes) {
853 return created_stream;
870 using namespace std::string_literals;
871 const auto& literals = DDXmlLiterals::getInstance();
875 DOM_NODE_TYPE header_element;
876 if (dom_node.findNode(literals.header, header_element)) {
883 std::list<DOM_NODE_TYPE> baseunit_nodes;
884 if (dom_node.findNodes(
"//units/baseunit"s, baseunit_nodes)) {
885 for (
const auto& current_base_unit_node: baseunit_nodes) {
892 std::list<DOM_NODE_TYPE> prefix_nodes;
893 if (dom_node.findNodes(
"//units/prefixes"s, prefix_nodes)) {
894 for (
const auto& current_prefix_node: prefix_nodes) {
901 std::list<DOM_NODE_TYPE> unit_nodes;
902 if (dom_node.findNodes(
"//units/unit"s, unit_nodes)) {
903 for (
const auto& current_unit_node: unit_nodes) {
911 std::list<DOM_NODE_TYPE> datatype_nodes;
912 if (dom_node.findNodes(
"//datatypes/datatype"s, datatype_nodes)) {
913 for (
const auto& current_datatype_node: datatype_nodes) {
921 std::list<DOM_NODE_TYPE> enum_nodes;
922 if (dom_node.findNodes(
"//enums/enum"s, enum_nodes)) {
923 for (
const auto& current_enum_node: enum_nodes) {
931 std::list<DOM_NODE_TYPE> struct_nodes;
932 if (dom_node.findNodes(
"//structs/struct"s, struct_nodes)) {
933 for (
const auto& current_struct_node: struct_nodes) {
940 if (dom_node.getName() == literals.struct__) {
946 std::list<DOM_NODE_TYPE> stream_meta_type_nodes;
947 if (dom_node.findNodes(
"//streammetatypes/streammetatype"s, stream_meta_type_nodes)) {
948 for (
const auto& current_smt_node: stream_meta_type_nodes) {
955 std::list<DOM_NODE_TYPE> stream_nodes;
956 if (dom_node.findNodes(
"//streams/stream"s, stream_nodes)) {
957 for (
const auto& current_stream_node: stream_nodes) {
static const PredefinedDataTypes & getInstance()
Get the Instance object.
dd::OptionalSize getDefaultAlignment(const std::string &name) const
Get the default alignment of a Predefined Type by name.
static Alignment fromString(const std::string &alignment, const Alignment &default_val=Alignment::e_invalid)
convert a string to an alignment.
Definition dd_common_types.h:378
static ByteOrder fromString(const std::string &byte_order, const ByteOrder &default_val=ByteOrder::platform_not_supported)
convert a string to a byte_order.
Exception helper class to collect information while parsing, adding DD Objects or other failed operat...
Definition ddl_error.h:31
static Version fromString(const std::string &version, const Version &default_val=Version(0, 0))
Creates the Version from a string.
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
const EnumTypes & getEnumTypes() const
Get the Enum Types object.
const StreamMetaTypes & getStreamMetaTypes() const
Get the Stream Meta Types object.
const UnitPrefixes & getUnitPrefixes() const
Get the Unit Prefixes object.
Version getVersion() const
Get the DDL Version.
const BaseUnits & getBaseUnits() const
Get the Base Units object.
const Units & getUnits() const
Get the Units object.
const Streams & getStreams() const
Get the Streams object.
void setHeader(const Header &header)
Set the Header object.
const StructTypes & getStructTypes() const
Get the Struct Types object.
const DataTypes & getDataTypes() const
Get the Data Types object.
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
const Elements & getElements() const
Get the Elements object.
KeyValuePair Element
Enum type element defintion as Name Value pair.
Definition datamodel_types.h:326
DataDefinition object class of datamodel to hold a streamstruct.
Definition datamodel_streams.h:80
observable Stream DataDefinition object.
Definition datamodel_streams.h:41
const Structs & getStructs() const
Get the Structs object.
class to describe the deserialized information of a StructType::Element.
Definition datamodel_types.h:644
observable DataDefinition object class for a Element of a StructType.
Definition datamodel_types.h:736
class to describe the serialized information of a StructType::Element.
Definition datamodel_types.h:493
observable DataDefinition object class to describe StructType.
Definition datamodel_types.h:453
Unit Prefix - datamodel pefixes.
Definition datamodel_units.h:221
datamodel for the refUnit
Definition datamodel_units.h:377
BaseUnit.
Definition datamodel_units.h:338
void emplace(DDL_TYPE_TO_ACCESS &&type_to_add)
emplace the given item
Definition access_list.h:432
void emplace(DDL_TYPE_TO_ACCESS &&type_to_add)
emplaces the given item
Definition access_map.h:368
Error
Enumerates possible error values for filesystem interaction.
Definition filesystem.h:27
bool isInteger(const std::string &string_to_check) noexcept
Checks if the given string is an integer value.
definition of the dd namespace
Definition datamodel_base.h:26
ByteOrder
Definition dd_common_types.h:152
Alignment
Alignment defintion.
Definition dd_common_types.h:98
@ e0
Definition dd_common_types.h:99
utility::Optional< size_t > OptionalSize
Optional Size Type.
Definition dd_common_types.h:38
@ struct_type
the type is a struct type (StructType)
Definition dd_common_types.h:64
definition of the ddl namespace
Definition codec.h:21
Definition xml_ddfromxml_factory.h:157
Definition xml_ddfromxml_factory.h:156
Factory to create a DataDefinition out of a XML based description. This factory uses a template type ...
Definition xml_ddfromxml_factory.h:145
static utility::Optional< T > getAttribute(const DOM_NODE_TYPE &dom_node, const std::string &attribute_name, AsOptional)
Get the Attribute from the dom_node. Return a valid Optional<T> if set, otherwise return default_valu...
Definition xml_ddfromxml_factory.h:171
static datamodel::StructType createStructType(const DOM_NODE_TYPE &dom_node, const Version &file_ddl_version, bool strict)
Create a Struct Type object.
Definition xml_ddfromxml_factory.h:725
static datamodel::Unit createUnit(const DOM_NODE_TYPE &dom_node)
Create a Unit object.
Definition xml_ddfromxml_factory.h:428
static datamodel::Header::ExtDeclaration createHeaderExtDeclaration(const DOM_NODE_TYPE &dom_node)
Create a Header Ext Declaration object.
Definition xml_ddfromxml_factory.h:329
static datamodel::BaseUnit createBaseUnit(const DOM_NODE_TYPE &dom_node)
Create a Base Unit object.
Definition xml_ddfromxml_factory.h:383
static datamodel::StructType::Element createStructTypeElement(const DOM_NODE_TYPE &dom_node, const Version &file_ddl_version, bool strict)
Create a Struct Type Element object.
Definition xml_ddfromxml_factory.h:562
static utility::Optional< T > getData(const DOM_NODE_TYPE &dom_node, const std::string &sub_node_name, AsOptional)
Get the data content of a subnode of dom_node. Return a valid Optional<T> if set, otherwise return de...
Definition xml_ddfromxml_factory.h:249
static datamodel::DataType createDataType(const DOM_NODE_TYPE &dom_node, const Version &file_ddl_version, bool strict)
Create a Data Type object.
Definition xml_ddfromxml_factory.h:460
static datamodel::Unit::RefUnit createRefUnit(const DOM_NODE_TYPE &dom_node)
Create a Ref Unit object.
Definition xml_ddfromxml_factory.h:413
static datamodel::EnumType::Element createEnumTypeElement(const DOM_NODE_TYPE &dom_node)
Create a Enum Type Element object.
Definition xml_ddfromxml_factory.h:521
static datamodel::DataDefinition createDD(const DOM_NODE_TYPE &dom_node, const dd::Version &language_version, bool strict)
Creates a whole DataDefinition and read all sub node.
Definition xml_ddfromxml_factory.h:866
static datamodel::UnitPrefix createUnitPrefix(const DOM_NODE_TYPE &dom_node)
Create a Unit Prefix object.
Definition xml_ddfromxml_factory.h:398
static datamodel::EnumType createEnumType(const DOM_NODE_TYPE &dom_node)
Create a Enum Type object.
Definition xml_ddfromxml_factory.h:535
static datamodel::StreamMetaType::Property createStreamMetaTypeProperty(const DOM_NODE_TYPE &dom_node)
Create a Stream Meta Type Property object.
Definition xml_ddfromxml_factory.h:776
static datamodel::Stream::Struct createStreamStruct(const DOM_NODE_TYPE &dom_node)
Create a Stream Struct object.
Definition xml_ddfromxml_factory.h:818
static datamodel::StreamMetaType createStreamMetaType(const DOM_NODE_TYPE &dom_node)
Create a Stream Meta Type object.
Definition xml_ddfromxml_factory.h:791
static datamodel::Header createHeader(const DOM_NODE_TYPE &dom_node)
Create a Header object.
Definition xml_ddfromxml_factory.h:345
static bool isInteger(const std::string &string_to_check) noexcept
Checks if the given string is an integer value.
Definition xml_ddfromxml_factory.h:151
static datamodel::Stream createStream(const DOM_NODE_TYPE &dom_node)
Create a Stream object.
Definition xml_ddfromxml_factory.h:834
An optional template as long as the std::optional is not available here.
Definition access_optional.h:31
T toType(std::string from_string, T default_value) noexcept
Conversion to T.
T toRequiredType(std::string from_string)
Conversion to T without fallback.