ADTF
DDStructureGenerator< T, align_with_padding >

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

Classes

struct  PaddingAlignmentGuard
 

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 >
DDElementRef createElement (const std::string &name, MemberType T::*member_offset)
 Creates a new member of data type (POD) by member reference pointer. More...
 
template<typename MemberType >
DDElementRef createElement (const std::string &name, MemberType T::*member_offset, const std::string &valid_element_count_or_array_size_name)
 Creates a new array member of data type (POD) by member reference pointer. 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 std::string &valid_element_count_or_array_size_name)
 Adds a new member of data type (POD) by member reference pointer. More...
 
template<typename MemberType >
DDElementRef createElement (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 >
DDElement createElement (const std::string &name, MemberType T::*member_offset, const DDEnum &enum_type, const std::string &valid_element_count_or_array_size_name)
 Adds a new array member of an enumeration type 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 DDEnum &enum_type, const std::string &valid_element_count_or_array_size_name)
 Adds a new array member of an enumeration type by member reference pointer. More...
 
template<typename MemberType >
DDElementRef createElement (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...
 
template<typename MemberType >
DDElementRef createElement (const std::string &name, MemberType T::*member_offset, const DDStructure &struct_type, const std::string &valid_element_count_or_array_size_name)
 Adds a new array member of an structure 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...
 
template<typename MemberType >
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset, const DDStructure &struct_type, const std::string &valid_element_count_or_array_size_name)
 Adds a new member of an structure type by member reference pointer. More...
 
std::string getStructDescription () const
 Gets the structs data definition 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...
 
DDElementRef getElement (const std::string &element_name)
 Gets a element reference to the element with name element_name owned by the DDStructureGenerator. 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)
 
template<typename DDMemberType >
DDElementRef createElement (const std::string &name, size_t alignment, const DDMemberType &used_type, size_t array_size)
 
template<typename DDMemberType >
DDElementRef createArrayElement (const std::string &name, size_t alignment, const DDMemberType &used_type, size_t array_size, const std::string &corresponding_element_name)
 

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 117 of file ddstructure_generator.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 129 of file ddstructure_generator.h.

Member Function Documentation

◆ addElement() [1/6]

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 207 of file ddstructure_generator.h.

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

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

◆ addElement() [2/6]

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 297 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::enum_type.

◆ addElement() [3/6]

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

Adds a new array 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.
[in]valid_element_count_or_array_size_namename of a sibling element for describing the array in size
  • if MemberType is a static array the name of the 'valid_element_count' element for validate the content of the array.
  • if MemberType is a dynamic array the name of the 'array_size' element for the size of the dynamic array.
Remarks
Dynamic arrays are always a performance issue for the reader of the array. Prefer static arrays with 'valid_element_count' for virtual dynamic arrays! The value of 'valid_element_count' element will mark the leading subset of the array content as valid.
Returns
A reference to the structure.

Definition at line 320 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::enum_type.

◆ addElement() [4/6]

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 390 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::struct_type.

◆ addElement() [5/6]

DDStructureGenerator& addElement ( const std::string &  name,
MemberType T::*  member_offset,
const DDStructure struct_type,
const std::string &  valid_element_count_or_array_size_name 
)
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.
[in]valid_element_count_or_array_size_namename of a sibling element for describing the array in size
  • if MemberType is a static array the name of the 'valid_element_count' element for validate the content of the array.
  • if MemberType is a dynamic array the name of the 'array_size' element for the size of the dynamic array.
Remarks
Dynamic arrays are always a performance issue for the reader of the array. Prefer static arrays with 'valid_element_count' for virtual dynamic arrays! The value of 'valid_element_count' element will mark the leading subset of the array content as valid.
Returns
A reference to the structure.

Definition at line 413 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::struct_type.

◆ addElement() [6/6]

DDStructureGenerator& addElement ( const std::string &  name,
MemberType T::*  member_offset,
const std::string &  valid_element_count_or_array_size_name 
)
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.
[in]valid_element_count_or_array_size_namename of a sibling element for describing the array in size
  • if MemberType is a static array the name of the 'valid_element_count' element for validate the content of the array.
  • if MemberType is a dynamic array the name of the 'array_size' element for the size of the dynamic array.
Remarks
Dynamic arrays are always a performance issue for the reader of the array. Prefer static arrays with 'valid_element_count' for virtual dynamic arrays! The value of 'valid_element_count' element will mark the leading subset of the array content as valid.
Returns
A reference to the structure.

Definition at line 227 of file ddstructure_generator.h.

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

◆ createElement() [1/6]

DDElementRef createElement ( const std::string &  name,
MemberType T::*  member_offset 
)
inline

Creates 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 object to the created element.

Definition at line 141 of file ddstructure_generator.h.

Referenced by DDStructureGenerator< T, align_with_padding >::addElement(), and DDStructureGenerator< T, align_with_padding >::createElement().

◆ createElement() [2/6]

DDElementRef createElement ( 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 object to the created element.

Definition at line 243 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::enum_type.

◆ createElement() [3/6]

DDElement createElement ( const std::string &  name,
MemberType T::*  member_offset,
const DDEnum enum_type,
const std::string &  valid_element_count_or_array_size_name 
)
inline

Adds a new array 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.
[in]valid_element_count_or_array_size_namename of a sibling element for describing the array in size
  • if MemberType is a static array the name of the 'valid_element_count' element for validate the content of the array.
  • if MemberType is a dynamic array the name of the 'array_size' element for the size of the dynamic array.
Remarks
Dynamic arrays are always a performance issue for the reader of the array. Prefer static arrays with 'valid_element_count' for virtual dynamic arrays! The value of 'valid_element_count' element will mark the leading subset of the array content as valid.
Returns
A reference object to the created element.

Definition at line 275 of file ddstructure_generator.h.

References ddl::dd::enum_type.

◆ createElement() [4/6]

DDElementRef createElement ( 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 element created.

Definition at line 337 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::struct_type.

◆ createElement() [5/6]

DDElementRef createElement ( const std::string &  name,
MemberType T::*  member_offset,
const DDStructure struct_type,
const std::string &  valid_element_count_or_array_size_name 
)
inline

Adds a new array 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.
[in]valid_element_count_or_array_size_namename of a sibling element for describing the array in size
  • if MemberType is a static array the name of the 'valid_element_count' element for validate the content of the array.
  • if MemberType is a dynamic array the name of the 'array_size' element for the size of the dynamic array.
Remarks
Dynamic arrays are always a performance issue for the reader of the array. Prefer static arrays with 'valid_element_count' for virtual dynamic arrays! The value of 'valid_element_count' element will mark the leading subset of the array content as valid.
Returns
A reference to the element created.

Definition at line 368 of file ddstructure_generator.h.

References DDStructureGenerator< T, align_with_padding >::createElement(), and ddl::dd::struct_type.

◆ createElement() [6/6]

DDElementRef createElement ( const std::string &  name,
MemberType T::*  member_offset,
const std::string &  valid_element_count_or_array_size_name 
)
inline

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

Parameters
[in]nameThe name of the member.
[in]member_offsetThe pointer to the member.
[in]valid_element_count_or_array_size_namename of a sibling element for describing the array in size
  • if MemberType is a static array the name of the 'valid_element_count' element for validate the content of the array.
  • if MemberType is a dynamic array the name of the 'array_size' element for the size of the dynamic array.
Remarks
Dynamic arrays are always a performance issue for the reader of the array. Prefer static arrays with 'valid_element_count' for virtual dynamic arrays! The value of 'valid_element_count' element will mark the leading subset of the array content as valid.
Returns
A reference object to the created element.

Definition at line 177 of file ddstructure_generator.h.

◆ getAlignment()

size_t getAlignment ( ) const
inline

Retrieves the current evaluated alignment of the structure.

Returns
the alignment

Definition at line 493 of file ddstructure_generator.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 missing elements.

Definition at line 449 of file ddstructure_generator.h.

References DDStructure::getDD().

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

◆ getElement()

DDElementRef getElement ( const std::string &  element_name)
inline

Gets a element reference to the element with name element_name owned by the DDStructureGenerator.

Parameters
element_namethe elements name
Returns
the element reference
Exceptions
dd::Errorif element was not found

Definition at line 577 of file ddstructure_generator.h.

References DDStructure::getElement().

◆ getSize()

size_t getSize ( ) const
inline

Retrieves the current evaluated size of the structure.

Returns
the size

Definition at line 484 of file ddstructure_generator.h.

References DDStructure::getSize().

◆ getStructDescription()

std::string getStructDescription ( ) const
inline

Gets the structs data definition as XML String.

Returns
The XML String of the struct data definition

Definition at line 427 of file ddstructure_generator.h.

References DDStructure::getStructDescription().

◆ getStructName()

std::string getStructName ( ) const
inline

Gets the Struct Name.

Returns
Name of the struct

Definition at line 437 of file ddstructure_generator.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 missing elements.

Definition at line 462 of file ddstructure_generator.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 missing elements.

Definition at line 474 of file ddstructure_generator.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 missing elements.

Definition at line 505 of file ddstructure_generator.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 521 of file ddstructure_generator.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 565 of file ddstructure_generator.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 551 of file ddstructure_generator.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 513 of file ddstructure_generator.h.

References DDStructure::setStructInfo().