ADTF  3.18.2
DDStructureGenerator< T, align_with_padding >

Creating a valid Structure Data Definition by a existing type and its member types. More...

Public Member Functions

 DDStructureGenerator (const std::string &name, uint32_t struct_version=1)
 CTOR to create a structure type based on a type. More...
 
template<typename MemberType >
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset)
 Adds a new member of data type (POD) by member reference pointer. More...
 
template<typename MemberType >
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset, const DDEnum &enum_type)
 Adds a new member of an enumeration type by member reference pointer. More...
 
template<typename MemberType >
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset, const DDStructure &struct_type)
 Adds a new member of an structure type by member reference pointer. More...
 
std::string getStructDescription () const
 Gets the Struct Data Description as XML String. More...
 
std::string getStructName () const
 Gets the Struct Name. More...
 
const dd::DataDefinitiongetDD () const
 returns a valid DDL. More...
 
const dd::StructTypegetStructType () const
 Get the Struct Type object. More...
 
const DDStructuregetStructure () const
 Get the current valid DDStructure object. More...
 
size_t getSize () const
 Retrieves the current evaluated size of the structure. More...
 
size_t getAlignment () const
 Retrieves the current evaluated alignment of the structure. More...
 
 operator const DDStructure & () const
 Get the current valid DDStructure object. More...
 
void setStructInfo (const std::string &comment)
 Set additional struct information like comment. More...
 
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. More...
 
void setElementUnit (const std::string &element_name, const DDUnit &unit)
 Sets additional element unit information to the given element_name. More...
 
void setElementUnit (const std::string &element_name, const dd::BaseUnit &base_unit)
 Sets additional element base unit information to the given element_name. More...
 

Private Member Functions

void pushAlignment ()
 
void popAlignment ()
 
void validate () const
 
dd::OptionalSize evaluateAlignment (const std::string &element_name, size_t member_offset, size_t member_type_alignment)
 

Private Attributes

DDStructure _structure
 
bool _padded_final = false
 

Detailed Description

template<typename T, bool align_with_padding = true>
class ddl::DDStructureGenerator< T, align_with_padding >

Creating a valid Structure Data Definition by a existing type and its member types.

Template Parameters
TThe Struct type to use.
align_with_paddingSet to true to align the structure and structure members with padding bytes to reach expected size of T.
struct NestedStruct {
uint16_t value1;
uint32_t value2;
uint8_t value3;
};
//this creates a valid DDStructure to use
auto nested_definition = DDStructureGenerator<NestedStruct>("NestedStruct")
.addElement("value1", &NestedStruct::value1)
.addElement("value2", &NestedStruct::value2)
.addElement("value3", &NestedStruct::value3);
//this creates a valid enum type
enum MyEnum { a, b, c };
auto my_enum_type = DDEnumGenerator<MyEnum>("MyEnum", {{"a", a}, {"b", b}, {"c", c}});
//create a more complex structure
//static arrays are determined by type
struct MyStruct {
uint32_t value1;
NestedStruct nested;
MyEnum nested_enum[2];
};
auto my_struct = DDStructureGenerator<MyStruct>("MyStruct")
.addElement("value1", &MyStruct::value1)
.addElement("nested", &MyStruct::nested, nested_definition)
.addElement("nested_enum", &MyStruct::nested_enum, my_enum_type);

Definition at line 644 of file ddstructure.h.

Constructor & Destructor Documentation

◆ DDStructureGenerator()

DDStructureGenerator ( const std::string &  name,
uint32_t  struct_version = 1 
)
inlineexplicit

CTOR to create a structure type based on a type.

Parameters
nameThe name of the type.
struct_versionthe version of the type.

Definition at line 656 of file ddstructure.h.

Member Function Documentation

◆ addElement() [1/3]

DDStructureGenerator& addElement ( const std::string &  name,
MemberType T::*  member_offset 
)
inline

Adds a new member of data type (POD) by member reference pointer.

Parameters
[in]nameThe name of the member.
[in]member_offsetThe pointer to the member.
Returns
A reference to the structure.

Definition at line 667 of file ddstructure.h.

References DDStructure::addElement().

Referenced by structure< T >::Add().

◆ addElement() [2/3]

DDStructureGenerator& addElement ( const std::string &  name,
MemberType T::*  member_offset,
const DDEnum enum_type 
)
inline

Adds a new member of an enumeration type by member reference pointer.

Parameters
[in]nameThe name of the member.
[in]member_offsetThe pointer to the member.
[in]enum_typeThe enumeration type.
Returns
A reference to the structure.

Definition at line 688 of file ddstructure.h.

References DDStructure::addElement(), and enum_type.

◆ addElement() [3/3]

DDStructureGenerator& addElement ( const std::string &  name,
MemberType T::*  member_offset,
const DDStructure struct_type 
)
inline

Adds a new member of an structure type by member reference pointer.

Parameters
[in]nameThe name of the member.
[in]member_offsetThe pointer to the member.
[in]struct_typeThe structure type.
Returns
A reference to the structure.

Definition at line 710 of file ddstructure.h.

References DDStructure::addElement(), and struct_type.

◆ getAlignment()

size_t getAlignment ( ) const
inline

Retrieves the current evaluated alignment of the structure.

Returns
the alignment

Definition at line 796 of file ddstructure.h.

References DDStructure::getAlignment().

◆ getDD()

const dd::DataDefinition& getDD ( ) const
inline

returns a valid DDL.

Returns
const dd::DataDefinition&
Exceptions
ddl::dd::ErrorThrows if the evaluated size is not sizeof(T). Check if there may be missed elements.

Definition at line 752 of file ddstructure.h.

References DDStructure::getDD().

Referenced by structure< T >::GetSize().

◆ getSize()

size_t getSize ( ) const
inline

Retrieves the current evaluated size of the structure.

Returns
the size

Definition at line 787 of file ddstructure.h.

References DDStructure::getSize().

◆ getStructDescription()

std::string getStructDescription ( ) const
inline

Gets the Struct Data Description as XML String.

Returns
std::string

Definition at line 730 of file ddstructure.h.

References DDStructure::getStructDescription().

◆ getStructName()

std::string getStructName ( ) const
inline

Gets the Struct Name.

Returns
std::string

Definition at line 740 of file ddstructure.h.

References DDStructure::getStructName().

Referenced by structure< T >::GetSize().

◆ getStructType()

const dd::StructType& getStructType ( ) const
inline

Get the Struct Type object.

Returns
const dd::StructType&
Exceptions
ddl::dd::ErrorThrows if the evaluated size is not sizeof(T). Check if there may be missed elements.

Definition at line 765 of file ddstructure.h.

References DDStructure::getStructType().

Referenced by structure< T >::GetAlignment().

◆ getStructure()

const DDStructure& getStructure ( ) const
inline

Get the current valid DDStructure object.

Returns
const DDStructure&
Exceptions
ddl::dd::ErrorThrows if the evaluated size is not sizeof(T). Check if there may be missed elements.

Definition at line 777 of file ddstructure.h.

Referenced by structure< T >::GetStructure(), and DDStructureGenerator< T, align_with_padding >::operator const DDStructure &().

◆ operator const DDStructure &()

operator const DDStructure & ( ) const
inline

Get the current valid DDStructure object.

Returns
const DDStructure&
Exceptions
ddl::dd::ErrorThrows if the evaluated size is not sizeof(T). Check if there may be missed elements.

Definition at line 808 of file ddstructure.h.

References DDStructureGenerator< T, align_with_padding >::getStructure().

◆ setElementInfo()

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 = {} 
)
inline

Set additional element information to the given element_name.

Remarks
The element with the name element_name must have been added before! The info will only be set if the string of the parameter is not empty!
Parameters
element_nameThe element name to set the additional info to
descriptionThe description
commentThe comment
valueThe value
minimum_valueThe minimum value
maximum_valueThe maximum value
default_valueThe default value
scaleThe scale
offsetThe offset
Exceptions
dd::Errorif element with element_name does not exist.

Definition at line 824 of file ddstructure.h.

◆ setElementUnit() [1/2]

void setElementUnit ( const std::string &  element_name,
const dd::BaseUnit base_unit 
)
inline

Sets additional element base unit information to the given element_name.

  • Any other unit information will be overwritten.
    Remarks
    The element with the name element_name must have been added before!
    Parameters
    element_nameThe element name
    base_unitThe baseunit to set
    Exceptions
    dd::Errorif element with element_name does not exist.

Definition at line 868 of file ddstructure.h.

References ddl::dd::base_unit, and DDStructure::setElementUnit().

◆ setElementUnit() [2/2]

void setElementUnit ( const std::string &  element_name,
const DDUnit unit 
)
inline

Sets additional element unit information to the given element_name.

Any other unit information will be overwritten.

Remarks
The element with the name element_name must have been added before!
Parameters
element_nameThe element name
unitThe unit to set
Exceptions
dd::Errorif element with element_name does not exist.

Definition at line 854 of file ddstructure.h.

References DDStructure::setElementUnit(), and ddl::dd::unit.

◆ setStructInfo()

void setStructInfo ( const std::string &  comment)
inline

Set additional struct information like comment.

This is important to create additional info in type reflection for DDStructureGenerator.

Parameters
commentThe comment of the struct type.

Definition at line 816 of file ddstructure.h.

References DDStructure::setStructInfo().