Dev Essential  1.6.3
Loading...
Searching...
No Matches
ddstructure.h
Go to the documentation of this file.
1
14
15#ifndef DDSTRUCTURE_H_INCLUDED
16#define DDSTRUCTURE_H_INCLUDED
17
18#include <ddl/dd/dd.h>
19#include <ddl/dd/ddelement.h>
22
23#include <type_traits>
24
25namespace ddl {
26
28class DDElement;
29class DDElementRef;
31
58public:
63 DDStructure() = delete;
75 DDStructure(const DDStructure& other);
94 ~DDStructure() = default;
107 explicit DDStructure(const std::string& name,
108 const uint32_t struct_version = 1,
109 dd::OptionalSize alignment = {},
110 const std::string& comment = {},
111 const dd::Version& ddl_version = {});
124 explicit DDStructure(const std::string& name,
125 const std::string& xml_string,
126 const dd::Version& ddl_xml_file_version_to_parse = dd::Version(0, 0));
144 DDStructure& addElement(const std::string& element_name,
145 const dd::DataType& data_type,
146 size_t array_size = 1);
147
165 DDElementRef createElement(const std::string& element_name,
166 const dd::DataType& data_type,
167 size_t array_size = 1);
186 DDStructure& addElement(const std::string& element_name,
187 const dd::DataType& data_type,
188 size_t array_size,
189 size_t alignment);
190
209 DDElementRef createElement(const std::string& element_name,
210 const dd::DataType& data_type,
211 size_t array_size,
212 size_t alignment);
213
232 DDStructure& addElement(const std::string& element_name,
233 const DDDataType& data_type,
234 size_t array_size = 1);
235
254 DDElementRef createElement(const std::string& element_name,
255 const DDDataType& data_type,
256 size_t array_size = 1);
257
277 DDStructure& addElement(const std::string& element_name,
278 const DDDataType& data_type,
279 size_t array_size,
280 size_t alignment);
281
301 DDElementRef createElement(const std::string& element_name,
302 const DDDataType& data_type,
303 size_t array_size,
304 size_t alignment);
325 template <typename PREDEF_DATA_TYPE>
326 DDStructure& addElement(const std::string& element_name,
327 size_t array_size = 1,
328 const std::string& special_type_name = {})
329 {
330 if (special_type_name.empty()) {
331 addElement(element_name, DataType<PREDEF_DATA_TYPE>(), array_size);
332 }
333 else {
334 addElement(element_name, DataType<PREDEF_DATA_TYPE>(special_type_name), array_size);
335 }
336 return *this;
337 }
338
359 template <typename PREDEF_DATA_TYPE>
360 DDElementRef createElement(const std::string& element_name,
361 size_t array_size = 1,
362 const std::string& special_type_name = {})
363 {
364 if (special_type_name.empty()) {
365 return createElement(element_name, DataType<PREDEF_DATA_TYPE>(), array_size);
366 }
367 else {
368 return createElement(
369 element_name, DataType<PREDEF_DATA_TYPE>(special_type_name), array_size);
370 }
371 }
372
394 template <typename PREDEF_DATA_TYPE>
395 DDStructure& addElement(const std::string& element_name,
396 size_t array_size,
397 size_t alignment,
398 const std::string& special_type_name = {})
399 {
400 if (special_type_name.empty()) {
401 addElement(element_name, DataType<PREDEF_DATA_TYPE>(), array_size, alignment);
402 }
403 else {
405 element_name, DataType<PREDEF_DATA_TYPE>(special_type_name), array_size, alignment);
406 }
407 return *this;
408 }
409
431 template <typename PREDEF_DATA_TYPE>
432 DDElementRef createElement(const std::string& element_name,
433 size_t array_size,
434 size_t alignment,
435 const std::string& special_type_name = {})
436 {
437 if (special_type_name.empty()) {
438 return createElement(element_name, DataType<PREDEF_DATA_TYPE>(), array_size, alignment);
439 }
440 else {
441 return createElement(
442 element_name, DataType<PREDEF_DATA_TYPE>(special_type_name), array_size, alignment);
443 }
444 }
445
463 DDStructure& addElement(const std::string& element_name,
464 const DDEnum& enum_type,
465 size_t array_size,
466 const std::string& constant_value = {});
467
485 DDElementRef createElement(const std::string& element_name,
486 const DDEnum& enum_type,
487 size_t array_size,
488 const std::string& constant_value = {});
489
508 DDStructure& addElement(const std::string& element_name,
509 const DDEnum& enum_type,
510 size_t array_size,
511 size_t alignment,
512 const std::string& constant_value = {});
513
532 DDElementRef createElement(const std::string& element_name,
533 const DDEnum& enum_type,
534 size_t array_size,
535 size_t alignment,
536 const std::string& constant_value = {});
537
554 DDStructure& addElement(const std::string& element_name,
555 const DDEnum& enum_type,
556 const std::string& constant_value = {});
557
574 DDElementRef createElement(const std::string& element_name,
575 const DDEnum& enum_type,
576 const std::string& constant_value = {});
577
598 DDStructure& addElement(const std::string& element_name,
599 const DDStructure& struct_type,
600 size_t array_size = 1);
601
622 DDElementRef createElement(const std::string& element_name,
623 const DDStructure& struct_type,
624 size_t array_size = 1);
625
647 DDStructure& addElement(const std::string& element_name,
648 const DDStructure& struct_type,
649 size_t array_size,
650 size_t alignment);
651
673 DDElementRef createElement(const std::string& element_name,
674 const DDStructure& struct_type,
675 size_t array_size,
676 size_t alignment);
691
706
725 DDStructure& addElements(const std::vector<DDElement>& elements);
726
730 typedef dd::datamodel::StructType::Elements::const_iterator const_iterator;
731
738 {
739 return _struct_type->getElements().cbegin();
740 };
741
747 {
748 return _struct_type->getElements().cend();
749 }
750
756 {
757 return _struct_type->getElements().begin();
758 };
759
765 {
766 return _struct_type->getElements().end();
767 }
768
773 const dd::DataDefinition& getDD() const;
780
786 std::string getStructDescription() const;
792 std::string getStructName() const;
793
801 bool isCompatible(const DDStructure& other) const;
809 bool isEqual(const DDStructure& other) const;
810
815 size_t getSize() const;
816
821 size_t getAlignment() const;
822
830 void setStructInfo(const std::string& comment);
848 void setElementInfo(const std::string& element_name,
849 const std::string& description = {},
850 const std::string& comment = {},
851 const std::string& value = {},
852 const std::string& minimum_value = {},
853 const std::string& maximum_value = {},
854 const std::string& default_value = {},
855 const std::string& scale = {},
856 const std::string& offset = {});
867 void setElementUnit(const std::string& element_name, const DDUnit& unit);
878 void setElementUnit(const std::string& element_name, const dd::BaseUnit& base_unit);
879
887 DDElementRef getElement(const std::string& element_name);
888
889private:
890 template <typename T, bool align_with_padding>
891 friend class DDStructureGenerator;
892
893 void popLastElement();
894
896 std::shared_ptr<dd::StructType> _struct_type;
897 dd::OptionalSize _initial_alignment = {};
898};
899
900} // namespace ddl
901
902#endif // DDSTRUCTURE_H_INCLUDED
A DataType class holding the DD for a Datatype with dependencies. (i.e. Units!)
Definition dddatatype.h:30
Utility class for a complete valid data definition of one StructType::Element and its dependencies....
Definition ddelement_ref.h:35
Utility class for a complete valid data definition of one StructType::Element and its dependencies....
Definition ddelement.h:36
Utility class for a complete valid data definition of one EnumType and its dependencies....
Definition ddenum.h:29
DDStructure(const std::string &name, const uint32_t struct_version=1, dd::OptionalSize alignment={}, const std::string &comment={}, const dd::Version &ddl_version={})
Construct a new DDStructure object.
DDElementRef createElement(const DDElement &element)
Creates one element to the struct using the convenience class DDElement.
DDStructure & addElement(const std::string &element_name, size_t array_size, size_t alignment, const std::string &special_type_name={})
Adds one element to the struct using a (POD) DataType.
Definition ddstructure.h:395
DDElementRef createElement(const std::string &element_name, const DDEnum &enum_type, size_t array_size, const std::string &constant_value={})
Creates one element to the struct using the convenience class DDEnum.
DDStructure & addElement(const std::string &element_name, const DDStructure &struct_type, size_t array_size=1)
Adds one element to the struct using the convenience class DDStructure.
DDElementRef createElement(const std::string &element_name, size_t array_size, size_t alignment, const std::string &special_type_name={})
Creates one element to the struct using a (POD) DataType.
Definition ddstructure.h:432
DDElementRef createElement(const std::string &element_name, const dd::DataType &data_type, size_t array_size, size_t alignment)
Creates one element to the struct using a (POD) DataType.
void setStructInfo(const std::string &comment)
Set additional struct information like comment. This is important to create additional info in type r...
DDStructure & addElement(const std::string &element_name, const DDDataType &data_type, size_t array_size=1)
Adds one element to the struct using a (POD) DataType.
DDStructure & addElement(const std::string &element_name, const dd::DataType &data_type, size_t array_size, size_t alignment)
Adds one element to the struct using a (POD) DataType.
DDElementRef createElement(const std::string &element_name, const DDStructure &struct_type, size_t array_size, size_t alignment)
Creates one element to the struct using the convenience class DDStructure.
DDStructure & addElements(const std::vector< DDElement > &elements)
Adds a list of element to the struct using the convenience class DDElement.
void setElementInfo(const std::string &element_name, const std::string &description={}, const std::string &comment={}, const std::string &value={}, const std::string &minimum_value={}, const std::string &maximum_value={}, const std::string &default_value={}, const std::string &scale={}, const std::string &offset={})
Set additional element information to the given element_name.
bool isCompatible(const DDStructure &other) const
binary compares the structs
DDStructure & operator=(const DDStructure &other)
copy assignment operator
std::string getStructDescription() const
Gets the Struct Data Description as XML String.
dd::datamodel::StructType::Elements::const_iterator const_iterator
iterator to iterate the elements of the struct
Definition ddstructure.h:730
const_iterator cbegin() const
returns the first elements iterator.
Definition ddstructure.h:737
const_iterator begin() const
returns the first elenents iterator for range based iterations.
Definition ddstructure.h:755
size_t getAlignment() const
Retrieves the current evaluated alignment of the structure.
DDStructure(const DDStructure &other)
Construct a new DDStructure object.
bool isEqual(const DDStructure &other) const
equal in names and descriptions
DDStructure & addElement(const std::string &element_name, const DDEnum &enum_type, size_t array_size, const std::string &constant_value={})
Adds one element to the struct using the convenience class DDEnum.
DDStructure & addElement(const DDElement &element)
Adds one element to the struct using the convenience class DDElement.
DDElementRef createElement(const std::string &element_name, const DDEnum &enum_type, size_t array_size, size_t alignment, const std::string &constant_value={})
Creates one element to the struct using the convenience class DDEnum.
DDStructure()=delete
Construct a new DDStructure object.
DDElementRef createElement(const std::string &element_name, const DDStructure &struct_type, size_t array_size=1)
Creates one element to the struct using the convenience class DDStructure.
DDElementRef createElement(const std::string &element_name, const dd::DataType &data_type, size_t array_size=1)
Creates one element to the struct using a (POD) DataType.
std::string getStructName() const
Gets the Struct Name.
DDStructure & addElement(const std::string &element_name, const DDEnum &enum_type, const std::string &constant_value={})
Adds one element to the struct using the convenience class DDEnum.
DDElementRef createElement(const std::string &element_name, const DDEnum &enum_type, const std::string &constant_value={})
Creates one element to the struct using the convenience class DDEnum.
DDElementRef createElement(const std::string &element_name, size_t array_size=1, const std::string &special_type_name={})
Create one element to the struct using a (POD) DataType.
Definition ddstructure.h:360
DDElementRef getElement(const std::string &element_name)
Gets a element reference to the element with name element_name owned by the DDStructure.
DDStructure & addElement(const std::string &element_name, const DDEnum &enum_type, size_t array_size, size_t alignment, const std::string &constant_value={})
Adds one element to the struct using the convenience class DDEnum.
void setElementUnit(const std::string &element_name, const DDUnit &unit)
Sets additional element unit information to the given element_name.
DDStructure & operator=(DDStructure &&other)
move assignment operator
DDElementRef createElement(const std::string &element_name, const DDDataType &data_type, size_t array_size=1)
Creates one element to the struct using a (POD) DataType.
DDStructure & addElement(const std::string &element_name, const DDStructure &struct_type, size_t array_size, size_t alignment)
Adds one element to the struct using the convenience class DDStructure.
const_iterator cend() const
returns the end elements iterator.
Definition ddstructure.h:746
DDStructure & addElement(const std::string &element_name, size_t array_size=1, const std::string &special_type_name={})
Adds one element to the struct using a (POD) DataType.
Definition ddstructure.h:326
const dd::StructType & getStructType() const
Get the Struct Type object.
~DDStructure()=default
Destroy the DDStructure object.
DDStructure & addElement(const std::string &element_name, const dd::DataType &data_type, size_t array_size=1)
Adds one element to the struct using a (POD) DataType.
DDStructure(const std::string &name, const std::string &xml_string, const dd::Version &ddl_xml_file_version_to_parse=dd::Version(0, 0))
Construct a new DDStructure object.
DDElementRef createElement(const std::string &element_name, const DDDataType &data_type, size_t array_size, size_t alignment)
Creates one element to the struct using a (POD) DataType.
const dd::DataDefinition & getDD() const
returns a valid DDL.
const_iterator end() const
returns the end elements iterator.
Definition ddstructure.h:764
DDStructure & addElement(const std::string &element_name, const DDDataType &data_type, size_t array_size, size_t alignment)
Adds one element to the struct using a (POD) DataType.
size_t getSize() const
Retrieves the current evaluated deserialized size (in bytes) of the structure.
void setElementUnit(const std::string &element_name, const dd::BaseUnit &base_unit)
Sets additional element base unit information to the given element_name. Any other unit information w...
DDStructure(DDStructure &&other)
Construct a new DDStructure object.
The unit class holding a reference to its complete DD (references to baseunits and prefixes)
Definition ddunit.h:92
Generator template to create DataType for the plain c-types.
Definition dd_predefined_datatypes.h:38
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition dd.h:92
DDL Version.
Definition dd_common_types.h:203
datamodel::DataType DataType
Definition dd.h:51
datamodel::StructType StructType
Definition dd.h:59
utility::Optional< size_t > OptionalSize
Optional Size Type.
Definition dd_common_types.h:38
datamodel::BaseUnit BaseUnit
Definition dd.h:39
definiton of the unit namespace
Definition dd_predefined_units.h:55
definition of the ddl namespace
Definition codec.h:21