Dev Essential
Loading...
Searching...
No Matches
ddl::DDStructureGenerator< T, align_with_padding > Class Template Reference

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

#include <ddstructure_generator.h>

Public Member Functions

 DDStructureGenerator (const std::string &name, uint32_t struct_version=1)
 CTOR to create a structure type based on a type.
 
template<typename MemberType>
DDElementRef createElement (const std::string &name, MemberType T::*member_offset)
 
template<typename MemberType>
DDElementRef createElement (const std::string &name, MemberType T::*member_offset, const std::string &valid_element_count_or_array_size_name)
 
template<typename MemberType>
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset)
 
template<typename MemberType>
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset, const std::string &valid_element_count_or_array_size_name)
 
template<typename MemberType>
DDElementRef createElement (const std::string &name, MemberType T::*member_offset, const DDEnum &enum_type)
 
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)
 
template<typename MemberType>
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset, const DDEnum &enum_type)
 
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)
 
template<typename MemberType>
DDElementRef createElement (const std::string &name, MemberType T::*member_offset, const DDStructure &struct_type)
 
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)
 
template<typename MemberType>
DDStructureGeneratoraddElement (const std::string &name, MemberType T::*member_offset, const DDStructure &struct_type)
 
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)
 
std::string getStructDescription () const
 Gets the structs data definition as XML String.
 
std::string getStructName () const
 Gets the Struct Name.
 
const dd::DataDefinitiongetDD () const
 returns a valid DDL.
 
const dd::StructTypegetStructType () const
 Get the Struct Type object.
 
const DDStructuregetStructure () const
 Get the current valid DDStructure object.
 
size_t getSize () const
 Retrieves the current evaluated size of the structure.
 
size_t getAlignment () const
 Retrieves the current evaluated alignment of the structure.
 
 operator const DDStructure & () const
 Get the current valid DDStructure object.
 
void setStructInfo (const std::string &comment)
 Set additional struct information like comment. This is important to create additional info in type reflection for DDStructureGenerator.
 
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.
 
void setElementUnit (const std::string &element_name, const DDUnit &unit)
 Sets additional element unit information to the given element_name. Any other unit information will be overwritten.
 
void setElementUnit (const std::string &element_name, const dd::BaseUnit &base_unit)
 Sets additional element base unit information to the given element_name.
 
DDElementRef getElement (const std::string &element_name)
 Gets a element reference to the element with name element_name owned by the DDStructureGenerator.
 

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);
DDStructureGenerator(const std::string &name, uint32_t struct_version=1)
CTOR to create a structure type based on a type.
Definition ddstructure_generator.h:129

Constructor & Destructor Documentation

◆ DDStructureGenerator()

template<typename T, bool align_with_padding = true>
ddl::DDStructureGenerator< T, align_with_padding >::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.

Member Function Documentation

◆ addElement() [1/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDStructureGenerator & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ addElement() [2/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDStructureGenerator & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ addElement() [3/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDStructureGenerator & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ addElement() [4/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDStructureGenerator & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ addElement() [5/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDStructureGenerator & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ addElement() [6/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDStructureGenerator & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ createElement() [1/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDElementRef ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ createElement() [2/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDElementRef ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ createElement() [3/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDElement ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ createElement() [4/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDElementRef ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ createElement() [5/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDElementRef ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ createElement() [6/6]

template<typename T, bool align_with_padding = true>
template<typename MemberType>
DDElementRef ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ getAlignment()

template<typename T, bool align_with_padding = true>
size_t ddl::DDStructureGenerator< T, align_with_padding >::getAlignment ( ) const
inline

Retrieves the current evaluated alignment of the structure.

Returns
the alignment

◆ getDD()

template<typename T, bool align_with_padding = true>
const dd::DataDefinition & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ getElement()

template<typename T, bool align_with_padding = true>
DDElementRef ddl::DDStructureGenerator< T, align_with_padding >::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

◆ getSize()

template<typename T, bool align_with_padding = true>
size_t ddl::DDStructureGenerator< T, align_with_padding >::getSize ( ) const
inline

Retrieves the current evaluated size of the structure.

Returns
the size

◆ getStructDescription()

template<typename T, bool align_with_padding = true>
std::string ddl::DDStructureGenerator< T, align_with_padding >::getStructDescription ( ) const
inline

Gets the structs data definition as XML String.

Returns
The XML String of the struct data definition

◆ getStructName()

template<typename T, bool align_with_padding = true>
std::string ddl::DDStructureGenerator< T, align_with_padding >::getStructName ( ) const
inline

Gets the Struct Name.

Returns
Name of the struct

◆ getStructType()

template<typename T, bool align_with_padding = true>
const dd::StructType & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ getStructure()

template<typename T, bool align_with_padding = true>
const DDStructure & ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ operator const DDStructure &()

template<typename T, bool align_with_padding = true>
ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ setElementInfo()

template<typename T, bool align_with_padding = true>
void ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ setElementUnit() [1/2]

template<typename T, bool align_with_padding = true>
void ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ setElementUnit() [2/2]

template<typename T, bool align_with_padding = true>
void ddl::DDStructureGenerator< T, align_with_padding >::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.

◆ setStructInfo()

template<typename T, bool align_with_padding = true>
void ddl::DDStructureGenerator< T, align_with_padding >::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.

The documentation for this class was generated from the following file: