ADTF  3.18.2
datamodel_types.h
Go to the documentation of this file.
1 
15 #ifndef DD_DATA_MODEL_TYPES_H_INCLUDED
16 #define DD_DATA_MODEL_TYPES_H_INCLUDED
17 
21 #include <ddl/dd/dd_common_types.h>
24 
25 #include <string>
26 #include <unordered_map>
27 #include <vector>
28 
29 namespace ddl {
30 
31 namespace dd {
32 
33 namespace datamodel {
34 
39 class TypeBase {
40 public:
45  TypeBase() = default;
50  TypeBase(const TypeBase&) = default;
55  TypeBase(TypeBase&&) = default;
61  TypeBase& operator=(const TypeBase&) = default;
67  TypeBase& operator=(TypeBase&&) = default;
73  TypeBase(const std::string& name);
78  virtual ~TypeBase() = default;
79 
86  virtual TypeOfType getTypeOfType() const = 0;
94  virtual void setName(const std::string& name);
100  const std::string& getName() const;
101 
102 protected:
104  std::string _name;
105 };
106 
111 class DataType : public TypeBase,
112  public ModelSubject<DataType>,
113  public utility::TypeAccessMapSubject<DataType>,
114  public InfoMap {
115 public:
120  DataType(){};
125  DataType(const DataType&) = default;
130  DataType(DataType&&) = default;
136  DataType& operator=(const DataType&) = default;
142  DataType& operator=(DataType&&) = default;
158  DataType(const std::string& name,
159  size_t bit_size,
160  const std::string& description = {},
161  OptionalSize array_size = {},
162  const std::string& unit_name = {},
163  const std::string& minimum_value = {},
164  const std::string& maximum_value = {},
165  OptionalSize default_type_alignment = {});
166 
180  DataType(const std::initializer_list<std::string>& initializer);
185  virtual ~DataType() = default;
194  bool operator==(const DataType& other) const;
203  bool operator!=(const DataType& other) const;
204 
208  TypeOfType getTypeOfType() const override;
212  void setName(const std::string& name) override;
213 
219  size_t getBitSize() const;
225  void setBitSize(size_t size);
226 
238  void setArraySize(OptionalSize array_size);
239 
245  const std::string& getUnitName() const;
251  void setUnitName(const std::string& unit_name);
252 
259  const std::string& getMin() const;
266  void setMin(const std::string& minimum_value);
267 
274  const std::string& getMax() const;
281  void setMax(const std::string& maximum_value);
282 
288  const std::string& getDescription() const;
294  void setDescription(const std::string& description);
295 
302 
303 private:
304  void notify(const std::string& additional_info);
305  size_t _bit_size = 0;
306  std::string _description = {};
307  OptionalSize _array_size = {};
308  std::string _unit_name = {};
309  std::string _minimum_value = {};
310  std::string _maximum_value = {};
311  OptionalSize _default_type_alignment = {};
312 };
313 
318 class EnumType : public TypeBase,
319  public ModelSubject<EnumType>,
320  public utility::TypeAccessMapSubject<EnumType>,
321  public InfoMap {
322 public: // types
334  friend Elements;
336 
337 public:
342  EnumType() = delete;
359  EnumType(const EnumType& other);
365  EnumType& operator=(const EnumType& other);
374  EnumType(const std::string& name,
375  const std::string& data_type_name,
376  const std::vector<Element>& elements = {});
381  virtual ~EnumType() = default;
389  bool operator==(const EnumType& other) const;
397  bool operator!=(const EnumType& other) const;
398 
404  const Elements& getElements() const;
411 
415  TypeOfType getTypeOfType() const override;
419  void setName(const std::string& name) override;
420 
426  const std::string& getDataTypeName() const;
432  void setDataTypeName(const std::string& data_type_name);
433 
434 private:
435  void notify(ModelEventCode code,
436  utility::TypeAccessMapEventCode forward_code,
437  const std::string& additional_info);
438  bool validateContains(const Elements::access_type& element_name) const;
439  void notifyChangedMapContent(utility::TypeAccessMapEventCode code,
440  Elements::access_type& element,
441  const std::string& additional_info);
442 
443  std::string _data_type_name = {};
444  Elements _elements;
445 };
446 
451 class StructType : public TypeBase,
452  public ModelSubject<StructType>,
453  public utility::TypeAccessMapSubject<StructType>,
454  public InfoMap {
455 public:
460  StructType() = delete;
477  StructType(const StructType& other);
489  virtual ~StructType() = default;
490 
495  public:
505  SerializedInfo(const SerializedInfo&) = default;
527  virtual ~SerializedInfo() = default;
528 
539  OptionalSize bit_pos = {},
540  OptionalSize num_bits = {});
557  SerializedInfo(const std::initializer_list<size_t>& intializer);
565  bool operator==(const SerializedInfo& other) const;
566 
581  void setBytePos(OptionalSize byte_pos, bool prevent_notification = false);
582 
597  void setBitPos(OptionalSize bit_pos, bool prevent_notification = false);
598 
610  void setNumBits(OptionalSize num_bits);
611 
623  void setByteOrder(ByteOrder byte_order);
624 
625  protected:
633  virtual void notifyChangeSerialized(const std::string&){};
634 
635  private:
636  OptionalSize _byte_pos = {};
637  OptionalSize _bit_pos = {};
638  OptionalSize _num_bits = {};
639  ByteOrder _byte_order = e_le;
640  };
641 
646  public:
678  virtual ~DeserializedInfo() = default;
679 
685  DeserializedInfo(size_t alignment);
691  DeserializedInfo(const std::initializer_list<size_t>& intializer);
692 
700  bool operator==(const DeserializedInfo& other) const;
701 
707  virtual size_t getAlignment() const;
715  void setAlignment(size_t alignment);
716 
717  protected:
724  virtual void notifyChangeDeserialized(const std::string&){};
725 
726  private:
727  size_t _alignment = Alignment::e_invalid;
728  };
729 
734  class Element : public SerializedInfo,
735  public DeserializedInfo,
736  public utility::TypeAccessListSubject<Element>,
737  public InfoMap {
738  public:
743  Element(){};
748  Element(const Element&) = default;
753  Element(Element&&) = default;
759  Element& operator=(const Element&) = default;
765  Element& operator=(Element&&) = default;
766 
789  Element(const std::string& name,
790  const std::string& type_name,
791  const DeserializedInfo& deserialized_info,
792  const SerializedInfo& serialized_info,
793  const dd::ArraySize& array_size = {},
794  const std::string& description = {},
795  const std::string& comment = {},
796  const std::string& unit_name = {},
797  const std::string& value = {},
798  const std::string& minimum_value = {},
799  const std::string& maximum_value = {},
800  const std::string& default_value = {},
801  const std::string& scale = {},
802  const std::string& offset = {});
803 
811  bool operator==(const Element& other) const;
819  bool operator!=(const Element& other) const;
820 
826  const std::string& getName() const;
835  void setName(const std::string& name);
836 
842  const std::string& getTypeName() const;
849  void setTypeName(const std::string& type_name);
850 
856  const std::string& getDescription() const;
863  void setDescription(const std::string& description);
864 
870  const std::string& getComment() const;
877  void setComment(const std::string& comment);
878 
884  const ArraySize& getArraySize() const;
891  void setArraySize(const ArraySize& array_size);
892 
898  const std::string& getUnitName() const;
905  void setUnitName(const std::string& unit_name);
906 
912  const std::string& getValue() const;
922  void setValue(const std::string& value);
923 
930  const std::string& getMin() const;
937  void setMin(const std::string& minimum_value);
938 
945  const std::string& getMax() const;
952  void setMax(const std::string& maximum_value);
953 
959  const std::string& getDefault() const;
967  void setDefault(const std::string& default_value);
968 
974  const std::string& getScale() const;
981  void setScale(const std::string& scale);
982 
988  const std::string& getOffset() const;
995  void setOffset(const std::string& offset);
996 
997  private:
998  void notifyChangeSerialized(const std::string& additional_info) override;
999  void notifyChangeDeserialized(const std::string& additional_info) override;
1000 
1001  private:
1002  std::string _name;
1003  std::string _type_name;
1004  std::string _description;
1005  std::string _unit_name;
1006  std::string _comment;
1007  ArraySize _array_size = 1;
1008  std::string _value;
1009  std::string _minimum_value;
1010  std::string _maximum_value;
1011  std::string _default_value;
1012  std::string _scale;
1013  std::string _offset;
1014  };
1015 
1028  StructType(const std::string& name,
1029  const std::string& struct_version = "1",
1030  OptionalSize alignment = {},
1031  const std::string& comment = {},
1032  dd::Version ddl_version = dd::Version(0, 0),
1033  const std::vector<Element>& elements = {});
1041  bool operator==(const StructType& other) const;
1049  bool operator!=(const StructType& other) const;
1050 
1054  TypeOfType getTypeOfType() const override;
1058  void setName(const std::string& name) override;
1059 
1072  void setAlignment(OptionalSize alignment);
1073 
1079  const std::string& getComment() const;
1086  void setComment(const std::string& comment);
1087 
1093  const std::string& getVersion() const;
1099  void setVersion(const std::string& struct_version);
1100 
1114  void setLanguageVersion(const Version& ddl_version);
1115 
1116 public:
1122  friend Elements;
1124 
1129  const Elements& getElements() const;
1136 
1137 private:
1138  void notify(ModelEventCode code,
1140  const std::string& additional_info);
1141  bool validateContains(const Elements::access_type& element_name) const;
1142  void notifyChangedListContent(utility::TypeAccessListEventCode code,
1143  Elements::access_type& element,
1144  const std::string& additional_info);
1145  [[deprecated]]
1146  const Elements::container_named_compatibility_type* getNamedItemList() const;
1147  [[deprecated]]
1149 
1150  const Elements::container_named_type* getNamedItemViewList() const;
1151  Elements::container_named_type* getNamedItemViewList();
1152 
1153  std::string _struct_version;
1154  dd::Version _ddl_version;
1155  std::string _comment;
1156  OptionalSize _alignment = Alignment::e1;
1157  Elements _elements;
1158 };
1159 
1164 class StreamMetaType : public TypeBase,
1165  public ModelSubject<StreamMetaType>,
1166  public utility::TypeAccessMapSubject<StreamMetaType>,
1167  public InfoMap {
1168 public: // types
1180  friend Properties;
1182 
1183 public:
1188  StreamMetaType() = delete;
1222  StreamMetaType(const std::string& name,
1223  const std::string& version,
1224  const std::string& parent = {},
1225  const std::vector<Property>& properties = {});
1230  virtual ~StreamMetaType() = default;
1238  bool operator==(const StreamMetaType& other) const;
1246  bool operator!=(const StreamMetaType& other) const;
1247 
1253  const Properties& getProperties() const;
1260 
1264  TypeOfType getTypeOfType() const override;
1268  void setName(const std::string& name) override;
1269 
1275  const std::string& getParent() const;
1283  void setParent(const std::string& parent);
1284 
1290  const std::string& getVersion() const;
1297  void setVersion(const std::string& version);
1298 
1299 private:
1300  void notify(ModelEventCode code,
1301  utility::TypeAccessMapEventCode forward_code,
1302  const std::string& additional_info);
1303  bool validateContains(const Properties::access_type& prop) const;
1304  void notifyChangedMapContent(utility::TypeAccessMapEventCode code,
1305  Properties::access_type& element,
1306  const std::string& additional_info);
1307 
1308  std::string _version = {};
1309  std::string _parent = {};
1310  Properties _properties;
1311 };
1312 
1317 struct ElementType {
1326  std::shared_ptr<datamodel::DataType> _data_type = {};
1330  std::shared_ptr<datamodel::EnumType> _enum_type = {};
1334  std::shared_ptr<datamodel::StructType> _struct_type = {};
1335 };
1336 
1337 } // namespace datamodel
1338 } // namespace dd
1339 } // namespace ddl
1340 
1341 #endif // DD_DATA_MODEL_TYPES_H_INCLUDED
Sinc DDL 2.0 it is possible to define arraysize with a string that indicates a dynamic array.
static ByteOrder getPlatformDefault()
Get the current Platform Byteorder.
observable DataDefinition object class to describe (POD) DataType.
void setMax(const std::string &maximum_value)
Set the Max (introduced in DDL 3.0)
bool operator==(const DataType &other) const
equality operator.
const std::string & getDescription() const
Get the Description.
bool operator!=(const DataType &other) const
non equality operator.
void setUnitName(const std::string &unit_name)
Set the Unit Name.
DataType & operator=(const DataType &)=default
copy assignment operator.
void setDescription(const std::string &description)
Set the Description.
size_t getBitSize() const
Get the Bit Size.
void setBitSize(size_t size)
Set the Bit Size.
DataType(const std::string &name, size_t bit_size, const std::string &description={}, OptionalSize array_size={}, const std::string &unit_name={}, const std::string &minimum_value={}, const std::string &maximum_value={}, OptionalSize default_type_alignment={})
CTOR.
const OptionalSize & getDefaultAlignment() const
Get the default Alignment if set.
OptionalSize getArraySize() const
Get the Array Size (optional)
const std::string & getMax() const
Get the Max Value for information (introduced in DDL 3.0)
DataType & operator=(DataType &&)=default
move assignment operator.
const std::string & getMin() const
Get the Min Value for information (introduced in DDL 3.0)
void setMin(const std::string &minimum_value)
Set the Min (introduced in DDL 3.0)
void setName(const std::string &name) override
Set the Name.
DataType(DataType &&)=default
move CTOR
const std::string & getUnitName() const
Get the Unit Name.
void setArraySize(OptionalSize array_size)
Set the Array Size object.
DataType(const std::initializer_list< std::string > &initializer)
CTOR with initializer.
DataType(const DataType &)=default
copy CTOR
TypeOfType getTypeOfType() const override
Get the Type Of the Type (data_type, enum_type, struct_type, stream_meta_type).
virtual ~DataType()=default
DTOR.
observable DataDefinition object class to describe EnumType.
EnumType & operator=(EnumType &&)
move assignment operator
EnumType(EnumType &&)
move CTOR.
const std::string & getDataTypeName() const
Get the Data Type Name.
void setDataTypeName(const std::string &data_type_name)
Set the Data Type Name.
EnumType()=delete
no default CTOR
utility::TypeAccessMap< Element, EnumType > Elements
container class for elements in EnumType
bool operator==(const EnumType &other) const
equality operator.
EnumType & operator=(const EnumType &other)
copy assignment operator
bool operator!=(const EnumType &other) const
non equality operator.
void setName(const std::string &name) override
Set the Name.
virtual ~EnumType()=default
DTOR.
const Elements & getElements() const
Get the Elements object.
Elements & getElements()
Get the Elements object.
EnumType(const EnumType &other)
Copy CTOR.
TypeOfType getTypeOfType() const override
Get the Type Of the Type (data_type, enum_type, struct_type, stream_meta_type).
EnumType(const std::string &name, const std::string &data_type_name, const std::vector< Element > &elements={})
Construct a new Enum Type object.
Info Map for the datamodel to hold a set of optional IInfo instances.
observable DataDefinition object class to describe StreamMetaType.
StreamMetaType & operator=(const StreamMetaType &other)
copy assignment operator
bool operator==(const StreamMetaType &other) const
equality operator.
const std::string & getParent() const
Get the Parent.
StreamMetaType()=delete
no default CTOR
const std::string & getVersion() const
Get the Version.
StreamMetaType(const StreamMetaType &other)
copy CTOR
const Properties & getProperties() const
Get the Properties object.
StreamMetaType(const std::string &name, const std::string &version, const std::string &parent={}, const std::vector< Property > &properties={})
CTOR.
Properties & getProperties()
Get the Properties object.
StreamMetaType & operator=(StreamMetaType &&)
move assignment operator
virtual ~StreamMetaType()=default
DTOR.
utility::TypeAccessMap< Property, StreamMetaType > Properties
container of properties for the StreamMetaType::Property.
void setName(const std::string &name) override
Set the Name.
void setParent(const std::string &parent)
Set the Parent This is only valid if the parent is a valid other streammetatype.
void setVersion(const std::string &version)
Set the Version.
TypeOfType getTypeOfType() const override
Get the Type Of the Type (data_type, enum_type, struct_type, stream_meta_type).
bool operator!=(const StreamMetaType &other) const
non equality operator.
StreamMetaType(StreamMetaType &&)
move CTOR
class to describe the deserialized information of a StructType::Element.
DeserializedInfo(DeserializedInfo &&)=default
move CTOR
DeserializedInfo(const DeserializedInfo &)=default
copy CTOR
virtual void notifyChangeDeserialized(const std::string &)
Forwarding the notification.
DeserializedInfo(const std::initializer_list< size_t > &intializer)
CTOR.
DeserializedInfo & operator=(const DeserializedInfo &)=default
copy assignment operator
void setAlignment(size_t alignment)
Set the Alignment.
DeserializedInfo & operator=(DeserializedInfo &&)=default
move assignment operator
virtual size_t getAlignment() const
Get the Alignment.
bool operator==(const DeserializedInfo &other) const
equality operator.
observable DataDefinition object class for a Element of a StructType.
void setMax(const std::string &maximum_value)
Set the Max (for information only).
const std::string & getTypeName() const
Get the Type Name.
void setTypeName(const std::string &type_name)
Set the Type Name.
const std::string & getDescription() const
Get the Description.
void setUnitName(const std::string &unit_name)
Set the Unit Name.
const std::string & getScale() const
Get the Scale (for information only)
void setDefault(const std::string &default_value)
Set the Default Value.
bool operator==(const Element &other) const
equality operator.
void setDescription(const std::string &description)
Set the Description.
const ArraySize & getArraySize() const
Get the Array Size.
bool operator!=(const Element &other) const
non equality operator.
const std::string & getComment() const
Get the Comment.
Element(const Element &)=default
copy CTOR
const std::string & getValue() const
Get the Value.
const std::string & getMax() const
Get the Max (for information only).
const std::string & getName() const
Get the Name.
const std::string & getMin() const
Get the Min (for information only).
Element(Element &&)=default
move CTOR
void notifyChangeSerialized(const std::string &additional_info) override
notification forwarding of serialized information to the StructType::Element object.
Element & operator=(const Element &)=default
copy assignment operator
void setName(const std::string &name)
Set the Name.
void setMin(const std::string &minimum_value)
Set the Min (for information only).
void setScale(const std::string &scale)
Set the Scale (for information only)
const std::string & getUnitName() const
Get the Unit Name.
Element & operator=(Element &&)=default
move assignment operator
void setValue(const std::string &value)
Set the Value This is only valid if the data type is set to an enum type where this constant value is...
const std::string & getDefault() const
Get the Default object.
void notifyChangeDeserialized(const std::string &additional_info) override
Forwarding the notification.
Element(const std::string &name, const std::string &type_name, const DeserializedInfo &deserialized_info, const SerializedInfo &serialized_info, const dd::ArraySize &array_size={}, const std::string &description={}, const std::string &comment={}, const std::string &unit_name={}, 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={})
CTOR.
void setComment(const std::string &comment)
Set the Comment object.
const std::string & getOffset() const
Get the Offset (for information only)
void setOffset(const std::string &offset)
Set the Offset (for information only)
void setArraySize(const ArraySize &array_size)
Set the Array Size.
class to describe the serialized information of a StructType::Element.
void setBytePos(OptionalSize byte_pos, bool prevent_notification=false)
Set the Byte Pos.
SerializedInfo(SerializedInfo &&)=default
move CTOR
SerializedInfo & operator=(SerializedInfo &&)=default
move assignment operator
SerializedInfo & operator=(const SerializedInfo &)=default
copy assignment operator
ByteOrder getByteOrder() const
Get the Byte Order.
OptionalSize getBytePos() const
Get the Byte Pos.
SerializedInfo(const SerializedInfo &)=default
copy CTOR
OptionalSize getBitPos() const
Get the Bit Pos (if set)
SerializedInfo(OptionalSize byte_pos, ByteOrder byte_order=ByteOrderDefault::getPlatformDefault(), OptionalSize bit_pos={}, OptionalSize num_bits={})
CTOR.
SerializedInfo(const std::initializer_list< size_t > &intializer)
CTOR with string list initializing.
void setByteOrder(ByteOrder byte_order)
Set the Byte Order.
OptionalSize getNumBits() const
Get the Num Bits (if set)
void setBitPos(OptionalSize bit_pos, bool prevent_notification=false)
Sets the Bit Pos.
void setNumBits(OptionalSize num_bits)
Set the Num Bits.
bool operator==(const SerializedInfo &other) const
equality operator.
virtual void notifyChangeSerialized(const std::string &)
notification forwarding of serialized information to the StructType::Element object.
observable DataDefinition object class to describe StructType.
bool operator==(const StructType &other) const
equality operator.
void setLanguageVersion(const Version &ddl_version)
Set the Language Version.
StructType & operator=(StructType &&other)
move assignment operator.
utility::TypeAccessList< Element, StructType > Elements
container of elements for the StructType::Element.
const std::string & getVersion() const
Get the set Version (the struct version! Not the DDL Version!)
StructType(StructType &&other)
move CTOR.
const std::string & getComment() const
Get the Comment.
void setAlignment(OptionalSize alignment)
Set the Alignment.
StructType()=delete
no default CTOR
virtual ~StructType()=default
DTOR.
OptionalSize getAlignment() const
Get the Alignment (if set)
StructType(const StructType &other)
copy CTOR
StructType & operator=(const StructType &other)
copy assignment operator
void setName(const std::string &name) override
Set the Name.
Version getLanguageVersion() const
Get the set language Version.
bool operator!=(const StructType &other) const
non equality operator.
StructType(const std::string &name, const std::string &struct_version="1", OptionalSize alignment={}, const std::string &comment={}, dd::Version ddl_version=dd::Version(0, 0), const std::vector< Element > &elements={})
CTOR.
const Elements & getElements() const
Get the Elements object.
void setVersion(const std::string &struct_version)
Get the Version (the struct version! Not the DDL Version!)
Elements & getElements()
Get the Elements object.
TypeOfType getTypeOfType() const override
Get the Type Of the Type (data_type, enum_type, struct_type, stream_meta_type).
void setComment(const std::string &comment)
Set the Comment.
TypeBase & operator=(const TypeBase &)=default
copy assignment operator
TypeBase(TypeBase &&)=default
move CTOR
virtual void setName(const std::string &name)
Set the Name.
virtual ~TypeBase()=default
DTOR.
virtual TypeOfType getTypeOfType() const =0
Get the Type Of the Type (data_type, enum_type, struct_type, stream_meta_type).
const std::string & getName() const
Get the Name.
TypeBase(const TypeBase &)=default
copy CTOR
std::string _name
name storage value
TypeBase(const std::string &name)
CTOR.
TypeBase & operator=(TypeBase &&)=default
move assignment operator
Model Subject utility to define a Model Subject that notifies one or more observers.
Element access_type
local definition of the access type
std::unordered_map< std::string, value_type > container_named_compatibility_type
local definition of the container type for getNamedItemList, which was had incompatible changes withi...
std::unordered_map< std::string, value_type > container_named_type
local definition of the container type for getNamedItemViewList
Element access_type
local definition of the access type
Definition: dd_access_map.h:76
OO DataDefinition Redesign - Data model Observer - Subject pattern.
OO DataDefinition Redesign.
DataDefinition Utility class for observable items.
DataDefinition Utility class for observable items.
OO DataDefinition Common Design.
OO DataDefinition Redesign - Data model info extension.
ModelEventCode
Model event code for the data model observer.
TypeAccessMapEventCode
Internal event code to inform the parent DD Object about the change of an item within the list.
Definition: dd_access_map.h:35
TypeAccessListEventCode
Internal event code to inform the parent DD Object about the change of an item within the list.
TypeOfType
Classification of a Type.
@ invalid_type
the type is unknown
utility::Optional< size_t > OptionalSize
Optional Size Type.
ByteOrder
Representation of the byteorder enumeration.
@ e1
Default alignment.
helper union class for an element that uses one of the datatype, enumtype, structtype
TypeOfType _type_of_type
the type of the type used (if valid)
std::shared_ptr< datamodel::EnumType > _enum_type
is set to an valid reference if the type is enum_type!
std::shared_ptr< datamodel::StructType > _struct_type
is set to an valid reference if the type is struct_type!
std::shared_ptr< datamodel::DataType > _data_type
is set to an valid reference if the type is data_type OR enum_type!