ADTF
ddstructure.h
Go to the documentation of this file.
1 
15 #ifndef DDSTRUCTURE_H_INCLUDED
16 #define DDSTRUCTURE_H_INCLUDED
17 
18 #include <ddl/dd/dd.h>
19 #include <ddl/dd/ddelement.h>
20 #include <ddl/dd/ddelement_ref.h>
22 
23 #include <type_traits>
24 
25 namespace ddl {
26 
28 class DDElement;
29 class DDElementRef;
31 
57 class DDStructure {
58 public:
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 {
404  addElement(
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);
690  DDStructure& addElement(const DDElement& element);
691 
706 
725  DDStructure& addElements(const std::vector<DDElement>& elements);
726 
731 
738  {
739  return _struct_type->getElements().cbegin();
740  };
747  {
748  return _struct_type->getElements().cend();
749  }
756  {
757  return _struct_type->getElements().begin();
758  };
765  {
766  return _struct_type->getElements().end();
767  }
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 
889 private:
890  template <typename T, bool align_with_padding>
891  friend class DDStructureGenerator;
892 
893  void popLastElement();
894 
895  dd::DataDefinition _dd;
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.
Definition: dddatatype.h:30
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 StructType::Element and its dependencies.
Definition: ddelement_ref.h:35
Utility class for a complete valid data definition of one EnumType and its dependencies.
Definition: ddenum.h:29
Creating a valid Structure Data Definition by a existing type and its member types.
Utility class for a complete valid data definition of one StructType and its dependencies.
Definition: ddstructure.h:57
std::string getStructName() const
Gets the Struct Name.
DDStructure(const DDStructure &other)
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.
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 DDElement &element)
Creates one element to the struct using the convenience class DDElement.
std::string getStructDescription() const
Gets the Struct Data Description as XML String.
const_iterator begin() const
returns the first elenents iterator for range based iterations.
Definition: ddstructure.h:755
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()=default
Destroy the DDStructure object.
bool isCompatible(const DDStructure &other) const
binary compares the structs
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.
const_iterator cbegin() const
returns the first elements iterator.
Definition: ddstructure.h:737
const dd::DataDefinition & getDD() const
returns a valid DDL.
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 DDElement &element)
Adds one element to the struct using the convenience class DDElement.
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.
dd::datamodel::StructType::Elements::const_iterator const_iterator
iterator to iterate the elements of the struct
Definition: ddstructure.h:730
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.
void setElementUnit(const std::string &element_name, const dd::BaseUnit &base_unit)
Sets additional element base unit information to the given element_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.
const dd::StructType & getStructType() const
Get the Struct Type object.
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.
DDStructure()=delete
Construct a new DDStructure object.
size_t getAlignment() const
Retrieves the current evaluated alignment of the structure.
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
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
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
const_iterator cend() const
returns the end elements iterator.
Definition: ddstructure.h:746
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 & 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.
DDStructure & addElements(const std::vector< DDElement > &elements)
Adds a list of element to the struct using the convenience class DDElement.
void setStructInfo(const std::string &comment)
Set additional struct information like comment.
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.
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 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.
void setElementUnit(const std::string &element_name, const DDUnit &unit)
Sets additional element unit information to the given element_name.
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 & operator=(const DDStructure &other)
copy assignment operator
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.
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.
const_iterator end() const
returns the end elements iterator.
Definition: ddstructure.h:764
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 & operator=(DDStructure &&other)
move assignment operator
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.
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.
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.
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.
bool isEqual(const DDStructure &other) const
equal in names and descriptions
DDStructure(DDStructure &&other)
Construct a new DDStructure object.
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.
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.
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition: dd.h:92
observable DataDefinition object class to describe (POD) DataType.
observable DataDefinition object class to describe StructType.
container_type::const_iterator const_iterator
local definition of the container const_iterator
Definition: access_list.h:133
OO DataDefinition - Data Definition.
OO DataDefinition Element Header.
OO DataDefinition Element Header.
@ 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)
@ unit
the unit is a unit (Unit)
@ base_unit
the unit is a base unit (BaseUnit)
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!