ADTF  3.18.2
DDStructure

Utility class for a complete valid data definition of one StructType and its dependencies. More...

Inheritance diagram for DDStructure:
[legend]

Public Types

typedef dd::datamodel::StructType::Elements::const_iterator const_iterator
 iterator to iterate the elements of the struct
 

Public Member Functions

 DDStructure ()=delete
 Construct a new DDStructure object.
 
 DDStructure (DDStructure &&other)
 Construct a new DDStructure object. More...
 
 DDStructure (const DDStructure &other)
 Construct a new DDStructure object. More...
 
DDStructureoperator= (DDStructure &&other)
 move assignment operator More...
 
DDStructureoperator= (const DDStructure &other)
 copy assignment operator More...
 
 ~DDStructure ()=default
 Destroy the DDStructure object.
 
 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. More...
 
 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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (const std::string &element_name, const DDDataType &data_type, size_t array_size=1)
 Adds one element to the struct using a (POD) DataType. More...
 
DDStructureaddElement (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. More...
 
template<typename PREDEF_DATA_TYPE >
DDStructureaddElement (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. More...
 
template<typename PREDEF_DATA_TYPE >
DDStructureaddElement (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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (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. More...
 
DDStructureaddElement (const DDElement &element)
 Adds one element to the struct using the convenience class DDElement. More...
 
DDStructureaddElements (const std::vector< DDElement > &elements)
 Adds a list of element to the struct using the convenience class DDElement. More...
 
const_iterator cbegin () const
 returns the first elements iterator. More...
 
const_iterator cend () const
 returns the end elements iterator. More...
 
const_iterator begin () const
 returns the first elenents iterator for range based iterations. More...
 
const_iterator end () const
 returns the end elements iterator. More...
 
const dd::DataDefinitiongetDD () const
 returns a valid DDL. More...
 
const dd::StructTypegetStructType () const
 Get the Struct Type object. More...
 
std::string getStructDescription () const
 Gets the Struct Data Description as XML String. More...
 
std::string getStructName () const
 Gets the Struct Name. More...
 
bool isCompatible (const DDStructure &other) const
 binary compares the structs More...
 
bool isEqual (const DDStructure &other) const
 equal in names and descriptions More...
 
size_t getSize () const
 Retrieves the current evaluated deserialized size (in bytes) of the structure. More...
 
size_t getAlignment () const
 Retrieves the current evaluated alignment of the structure. 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 popLastElement ()
 

Private Attributes

dd::DataDefinition _dd
 
std::shared_ptr< dd::StructType_struct_type
 
dd::OptionalSize _initial_alignment = {}
 

Detailed Description

Utility class for a complete valid data definition of one StructType and its dependencies.

This class is for convenience to use create a StructType data defintion in code.
The class is to use as follows:

DDEnum e1("e1", DataType<int8_t>(), {{"val11", "1"}, {"val12", "2"}, {"val13", "3"}});
DDStructure a("A");
a.addElement<int32_t>("elem1");
a.addElement("elem2", DataType<uint16_t>());
a.addElement("elem3", e1, "val13");
DDStructure b("B");
b.addElement("nestedA1", a);
b.addElement("nestedA2", a);
//now you can do something with the created DD
b.getDD().isValid();
std::string dd_struct = b.getStructName();
std::string dd_description = b.getStructDescription();
DDStructure()=delete
Construct a new DDStructure object.
@ e1
Default alignment.
See also
ddl::DDEnum, ddl::DataType

Definition at line 55 of file ddstructure.h.

Constructor & Destructor Documentation

◆ DDStructure() [1/4]

DDStructure ( DDStructure &&  other)

Construct a new DDStructure object.

Parameters
otherthe structure to move.

◆ DDStructure() [2/4]

DDStructure ( const DDStructure other)

Construct a new DDStructure object.

Parameters
otherthe structure to copy.

◆ DDStructure() [3/4]

DDStructure ( const std::string &  name,
const uint32_t  struct_version = 1,
dd::OptionalSize  alignment = {},
const std::string &  comment = {},
const dd::Version ddl_version = {} 
)
explicit

Construct a new DDStructure object.

Parameters
nametypename of the new StructType
struct_versionversion of the struct
alignmentoptional alignment (if not set the alignment will be calculated automatically)
commentoptional comment
ddl_versionoptional DDL language version of this struct (defines the size of the struct by alignment or not!)

◆ DDStructure() [4/4]

DDStructure ( const std::string &  name,
const std::string &  xml_string,
const dd::Version ddl_xml_file_version_to_parse = dd::Version(0, 0) 
)
explicit

Construct a new DDStructure object.

Parameters
nametypename of the new StructType
xml_stringthe xml string to read
ddl_xml_file_version_to_parseoptional DDL language version of the string.
Exceptions
ddl::dd::Errorif the xml string is not valid against the xsd definition! (depending on the DDL Version).
ddl::dd::Errorif the validation level of the created DataDefinition is not at least "good_enough"!
ddl::dd::Errorif the given name is not part of this description.

Member Function Documentation

◆ addElement() [1/12]

DDStructure& addElement ( const DDElement element)

Adds one element to the struct using the convenience class DDElement.

Usage:

DDStructure a("A");
a.addElement(ddl::DDElement("elem1", ddl::DataType<uint32_t>()));
Utility class for a complete valid data definition of one StructType::Element and its dependencies.
Definition: ddelement.h:36
Generator template to create DataType for the plain c-types.
Parameters
elementthe DDElement
Exceptions
ddl::dd::Errorif the name of the given element already exists.

◆ addElement() [2/12]

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.

Usage:

DDStructure a("A");
a.addElement("elem1", DataType<uint16_t>(), 1, 2);
Parameters
element_namethe name of the element
data_typethe data type
array_sizethe arrysize of the element (by default 1)
alignmentalignment of the element
Remarks
all default DataTypes are always part of the DataDefinition if needed. See ddl::PredefinedDataTypes.
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [3/12]

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.

Usage:

DDStructure a("A");
a.addElement("elem1", DataType<uint16_t>());
Parameters
element_namethe name of the element
data_typethe data type
array_sizethe arrysize of the element (by default 1)
Remarks
all default DataTypes are always part of the DataDefinition if needed. See ddl::PredefinedDataTypes.
Exceptions
ddl::dd::Errorif the given element_name already exists.

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

◆ addElement() [4/12]

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.

Usage:

DDDataType custom_type("custom", 1);
DDStructure a("A");
a.addElement("elem1", custom_type);
Parameters
element_namethe name of the element
data_typethe data type
array_sizethe arrysize of the element (by default 1)
alignmentalignment of the element
Remarks
all default DataTypes are always part of the DataDefinition if needed. See ddl::PredefinedDataTypes.
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [5/12]

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.

Usage:

DDDataType custom_type("custom", 1);
DDStructure a("A");
a.addElement("elem1", custom_type);
Parameters
element_namethe name of the element
data_typethe data type
array_sizethe arrysize of the element (by default 1)
Remarks
all default DataTypes are always part of the DataDefinition if needed. See ddl::PredefinedDataTypes.
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [6/12]

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.

Usage:

DDEnum e1("e1", DataType<int8_t>(), { {"val11", "1"}, {"val12", "2"}, {"val13", "3"} });
DDStructure a("A");
a.addElement("elem1", e1);
Parameters
element_namethe name of the element
enum_typethe enum type
constant_valuethe constant value name, defined within enum_type
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [7/12]

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.

Usage:

DDEnum e1("e1", DataType<int8_t>(), { {"val11", "1"}, {"val12", "2"}, {"val13", "3"} });
DDStructure a("A");
a.addElement("elem1", e1);
Parameters
element_namethe name of the element
enum_typethe enum type
array_sizethe arrysize of the element (by default 1)
constant_valuethe constant value name, defined within enum_type
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [8/12]

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.

Usage:

DDEnum e1("e1", DataType<int8_t>(), { {"val11", "1"}, {"val12", "2"}, {"val13", "3"} });
DDStructure a("A");
a.addElement("elem1", e1);
Parameters
element_namethe name of the element
enum_typethe enum type
array_sizethe arrysize of the element (by default 1)
alignmentalignment of the element
constant_valuethe constant value name, defined within enum_type
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [9/12]

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.

Usage:

DDEnum e1("e1", DataType<int8_t>(), { {"val11", "1"}, {"val12", "2"}, {"val13", "3"} });
DDStructure a("A");
a.addElement("elem1", e1);
a.addElement<uint16_t>("elem2");
DDStructure b("B");
b.addElement("nested1", a);
b.addElement("nested2", a);
Parameters
element_namethe name of the element
struct_typethe struct type
array_sizethe arraysize of the element (by default 1)
alignmentthe alignment for the element
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [10/12]

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.

Usage:

DDEnum e1("e1", DataType<int8_t>(), { {"val11", "1"}, {"val12", "2"}, {"val13", "3"} });
DDStructure a("A");
a.addElement("elem1", e1);
a.addElement<uint16_t>("elem2");
DDStructure b("B");
b.addElement("nested1", a);
b.addElement("nested2", a);
Parameters
element_namethe name of the element
struct_typethe struct type
array_sizethe arrysize of the element (by default 1)
Exceptions
ddl::dd::Errorif the given element_name already exists.

◆ addElement() [11/12]

DDStructure& addElement ( const std::string &  element_name,
size_t  array_size,
size_t  alignment,
const std::string &  special_type_name = {} 
)
inline

Adds one element to the struct using a (POD) DataType.

Usage:

DDStructure a("A");
a.addElement<uint16_t>("elem1", 1, 2);
a.addElement<uint16_t>("elem2", 1, 4, "tUInt16");
Template Parameters
PREDEF_DATA_TYPEThe POD type (float, int32_t ... etc. )
Parameters
element_namethe name of the element
array_sizethe arrysize of the element (by default 1)
special_type_namethis typename is used instead of the typename predefined in DataType
alignmentalignment of the element
Remarks
all default DataTypes are always part of the DataDefinition if needed. See ddl::PredefinedDataTypes.
Exceptions
ddl::dd::Errorif the given element_name already exists.

Definition at line 262 of file ddstructure.h.

◆ addElement() [12/12]

DDStructure& addElement ( const std::string &  element_name,
size_t  array_size = 1,
const std::string &  special_type_name = {} 
)
inline

Adds one element to the struct using a (POD) DataType.

Usage:

DDStructure a("A");
a.addElement<uint16_t>("elem1");
a.addElement<uint16_t>("elem2", "tUInt16");
Template Parameters
PREDEF_DATA_TYPEThe POD type (float, int32_t ... etc. )
Parameters
element_namethe name of the element
array_sizethe arrysize of the element (by default 1)
special_type_namethis typename is used instead of the typename predefined in DataType
Remarks
all default DataTypes are always part of the DataDefinition if needed. See ddl::PredefinedDataTypes.
Exceptions
ddl::dd::Errorif the given element_name already exists.

Definition at line 228 of file ddstructure.h.

◆ addElements()

DDStructure& addElements ( const std::vector< DDElement > &  elements)

Adds a list of element to the struct using the convenience class DDElement.

Usage:

DDEnum e1("e1", DataType<int8_t>(), { {"val11", "1"}, {"val12", "2"}, {"val13", "3"} }
DDStructure a("A");
a.addElements({ DDElement("elem1", DataType<uint64_t>()),
DDElement("elem2", DataType<float>()) } );
a.addElements({ {"elem3", DataType<double>() },
{"elem4", DataType<bool>() },
{"elem5", e1 } });
Parameters
elementsthe list of DDElement
Exceptions
ddl::dd::Errorif a name of the given elements already exists.

◆ begin()

const_iterator begin ( ) const
inline

returns the first elenents iterator for range based iterations.

Returns
const_iterator

Definition at line 447 of file ddstructure.h.

◆ cbegin()

const_iterator cbegin ( ) const
inline

returns the first elements iterator.

Returns
const_iterator

Definition at line 429 of file ddstructure.h.

◆ cend()

const_iterator cend ( ) const
inline

returns the end elements iterator.

Returns
const_iterator

Definition at line 438 of file ddstructure.h.

◆ end()

const_iterator end ( ) const
inline

returns the end elements iterator.

Returns
const_iterator

Definition at line 456 of file ddstructure.h.

◆ getAlignment()

size_t getAlignment ( ) const

Retrieves the current evaluated alignment of the structure.

Returns
the alignment

Referenced by DDStructureGenerator< T, align_with_padding >::getAlignment().

◆ getDD()

const dd::DataDefinition& getDD ( ) const

returns a valid DDL.

Returns
const dd::DataDefinition&

Referenced by DDStructureGenerator< T, align_with_padding >::getDD().

◆ getSize()

size_t getSize ( ) const

Retrieves the current evaluated deserialized size (in bytes) of the structure.

Returns
the size (in bytes)

Referenced by DDStructureGenerator< T, align_with_padding >::getSize().

◆ getStructDescription()

std::string getStructDescription ( ) const

Gets the Struct Data Description as XML String.

Returns
std::string

Referenced by DDStructureGenerator< T, align_with_padding >::getStructDescription().

◆ getStructName()

std::string getStructName ( ) const

Gets the Struct Name.

Returns
std::string

Referenced by DDStructureGenerator< T, align_with_padding >::getStructName().

◆ getStructType()

const dd::StructType& getStructType ( ) const

Get the Struct Type object.

Returns
const dd::StructType&

Referenced by DDStructureGenerator< T, align_with_padding >::getStructType().

◆ isCompatible()

bool isCompatible ( const DDStructure other) const

binary compares the structs

Parameters
otherthe other struct to binary compare to
Returns
true The structs are binary comaptible in memory
false the struct are not binary compatible

◆ isEqual()

bool isEqual ( const DDStructure other) const

equal in names and descriptions

Parameters
otherthe other struct
Returns
true the structs are identically
false the structs are different

◆ operator=() [1/2]

DDStructure& operator= ( const DDStructure other)

copy assignment operator

Parameters
otherthe structure to copy.
Returns
DDStructure&

◆ operator=() [2/2]

DDStructure& operator= ( DDStructure &&  other)

move assignment operator

Parameters
otherthe structure to move.
Returns
DDStructure&

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

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]

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 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]

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.
    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.

Referenced by DDStructureGenerator< T, align_with_padding >::setElementUnit().

◆ setStructInfo()

void setStructInfo ( const std::string &  comment)

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.

Referenced by DDStructureGenerator< T, align_with_padding >::setStructInfo().