ADTF  3.18.2
dd.h
Go to the documentation of this file.
1 
15 #ifndef DD_DD_H_INCLUDED
16 #define DD_DD_H_INCLUDED
17 
19 #include <ddl/dd/dd_common_types.h>
22 
23 #include <string>
24 
25 namespace ddl {
26 namespace dd {
63 
80  datamodel::ModelObserver<BaseUnit>,
81  datamodel::ModelObserver<UnitPrefix>,
83  datamodel::ModelObserver<DataType>,
84  datamodel::ModelObserver<EnumType>,
85  datamodel::ModelObserver<StructType>,
86  datamodel::ModelObserver<StreamMetaType>,
87  datamodel::ModelObserver<Stream> {
88 public:
98  DataDefinition(Version ddl_version);
130  DataDefinition(const std::shared_ptr<datamodel::DataDefinition>& datamodel);
135  virtual ~DataDefinition();
136 
142  void setModel(const std::shared_ptr<datamodel::DataDefinition>& datamodel);
148  std::shared_ptr<const datamodel::DataDefinition> getModel() const;
149 
150 public:
190 
198  void setVersion(const Version& ddl_version);
205 
213  void setHeader(const Header& header);
219  const Header& getHeader() const;
226 
232  const BaseUnits& getBaseUnits() const;
239 
252 
258  const Units& getUnits() const;
265 
271  const DataTypes& getDataTypes() const;
278 
284  const EnumTypes& getEnumTypes() const;
291 
297  const StructTypes& getStructTypes() const;
304 
313  bool containsType(const std::string& type_name) const;
326  TypeOfType getTypeOfType(const std::string& type_name) const;
327 
336  bool containsUnit(const std::string& unit_name) const;
346  TypeOfUnit getTypeOfUnit(const std::string& unit_name) const;
347 
360 
366  const Streams& getStreams() const;
373 
391  void validate(bool force_revalidation = false);
401  std::vector<ddl::dd::Problem> getValidationProtocol() const;
402 
414  void calculatePositions(const std::string& type_name = {},
415  TypeOfType type_of_type = TypeOfType::invalid_type,
416  bool force_recalculation = false);
425  StructTypeAccess getStructTypeAccess(const std::string& type_name) const;
426 
427  // merge/add
437  void add(const BaseUnit& base_unit, const DataDefinition& source_dd);
448  void add(const UnitPrefix& unit_prefix, const DataDefinition& source_dd);
460  void add(const Unit& unit, const DataDefinition& source_dd);
472  void add(const DataType& data_type, const DataDefinition& source_dd);
483  void add(const EnumType& enum_type, const DataDefinition& source_dd);
495  void add(const StructType& struct_type, const DataDefinition& source_dd);
507  void add(const StreamMetaType& stream_meta_type, const DataDefinition& source_dd);
519  void add(const Stream& stream, const DataDefinition& source_dd);
528  void add(const DataDefinition& source_dd);
529 
530 private:
531  std::shared_ptr<datamodel::DataDefinition> _datamodel;
532  void attachToModel();
533  void detachFromModel();
534  void modelChanged(datamodel::ModelEventCode event_code,
535  datamodel::Header& changed_subject,
536  const std::string& additional_info) override;
537  void modelChanged(datamodel::ModelEventCode event_code,
538  datamodel::BaseUnit& changed_subject,
539  const std::string& additional_info) override;
540  void modelChanged(datamodel::ModelEventCode event_code,
541  datamodel::UnitPrefix& changed_subject,
542  const std::string& additional_info) override;
543  void modelChanged(datamodel::ModelEventCode event_code,
544  datamodel::Unit& changed_subject,
545  const std::string& additional_info) override;
546  void modelChanged(datamodel::ModelEventCode event_code,
547  datamodel::DataType& changed_subject,
548  const std::string& additional_info) override;
549  void modelChanged(datamodel::ModelEventCode event_code,
550  datamodel::EnumType& changed_subject,
551  const std::string& additional_info) override;
552  void modelChanged(datamodel::ModelEventCode event_code,
553  datamodel::StructType& changed_subject,
554  const std::string& additional_info) override;
555  void modelChanged(datamodel::ModelEventCode event_code,
556  datamodel::StreamMetaType& changed_subject,
557  const std::string& additional_info) override;
558  void modelChanged(datamodel::ModelEventCode event_code,
559  datamodel::Stream& changed_subject,
560  const std::string& additional_info) override;
561 
562  Version _last_known_ddl_version;
563  // this member variable must stay there for ABI compatibility!
564  // NOLINTNEXTLINE(clang-diagnostic-unused-private-field)
565  ValidationLevel _dummy_validation_level = ValidationLevel::dont_know;
566  std::unordered_map<std::string, std::string> _recursion_detection_stream_meta_types;
567  std::unordered_map<std::string, std::string> _recursion_detection_struct;
568 };
569 
587 bool addTypeByName(const std::string& type_name,
588  const DataDefinition& source_dd,
589  DataDefinition& destination_dd);
608 bool addStreamTypeByName(const std::string& stream_type_name,
609  const DataDefinition& source_dd,
610  DataDefinition& destination_dd);
624 bool addUnitByName(const std::string& unit_name,
625  const DataDefinition& source_dd,
626  DataDefinition& destination_dd);
627 
645 std::vector<std::string> transformValidationProblemList(
646  const std::vector<ddl::dd::Problem>& problems);
647 
653 
654 } // namespace dd
655 using dd::DataDefinition;
656 using dd::DataDescription;
657 } // namespace ddl
658 
659 #endif // DD_DD_H_INCLUDED
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition: dd.h:87
DataDefinition & operator=(DataDefinition &&other)
Assigns the DataDefinition object and moves the datamodel.
DataDefinition()
Construct a new DataDefinition object with a new datamodel::DataDefinition.
BaseUnits & getBaseUnits()
Get the Base Units of the datamodel.
bool containsType(const std::string &type_name) const
Retrieve information if the datamodel contains a type with the given name.
TypeOfType getTypeOfType(const std::string &type_name) const
Retrieve information if the datamodel contains a type with the given name and return the type of it.
void setHeader(const Header &header)
Resets the DataDefinition Header of the datamodel.
Units & getUnits()
Get the Units of the datamodel.
const EnumTypes & getEnumTypes() const
Get the Enum Types of the datamodel.
void add(const EnumType &enum_type, const DataDefinition &source_dd)
Merges or add the given enumtype.
void add(const DataDefinition &source_dd)
Merges or add the DataDefinition objects of the given source_dd.
DataDefinition(Version ddl_version)
Construct a new DataDefinition object with a new datamodel::DataDefinition.
EnumTypes & getEnumTypes()
Get the Enum Types of the datamodel.
void add(const DataType &data_type, const DataDefinition &source_dd)
Merges or add the given datatype.
std::vector< ddl::dd::Problem > getValidationProtocol() const
Gets a collection of all problems obtained while validating the DataDefinition Objects-.
bool isValid(ValidationLevel level=ValidationLevel::valid) const
Obtains if the validation level has reached at least the given level.
void validate(bool force_revalidation=false)
Calculate the validation level of all DataDefinition objects that does not have a validation level ye...
void setModel(const std::shared_ptr< datamodel::DataDefinition > &datamodel)
Sets and references the datamodel object, that is to validate and observe.
TypeOfUnit getTypeOfUnit(const std::string &unit_name) const
Retrieve information if the datamodel contains a unit with the given name and return the type of it.
void calculatePositions(const std::string &type_name={}, TypeOfType type_of_type=TypeOfType::invalid_type, bool force_recalculation=false)
calculates the element sizes and positions of all structs, enumtypes and datatypes or dedicated for t...
bool containsUnit(const std::string &unit_name) const
Retrieve information if the datamodel contains a unit with the given name.
void add(const UnitPrefix &unit_prefix, const DataDefinition &source_dd)
Merges or add the given unit prefix.
void add(const BaseUnit &base_unit, const DataDefinition &source_dd)
Merges or add the given base unit.
void setVersion(const Version &ddl_version)
Set the language version of the containing datamodel.
const BaseUnits & getBaseUnits() const
Get the Base Units of the datamodel.
void add(const StructType &struct_type, const DataDefinition &source_dd)
Merges or add the given structtype.
StructTypes & getStructTypes()
Get the Struct Types of the datamodel.
const StructTypes & getStructTypes() const
Get the Struct Types of the datamodel.
Header & getHeader()
Gets the Header of the datamodel.
Streams & getStreams()
Get the Streams of the datamodel.
void add(const Stream &stream, const DataDefinition &source_dd)
Merges or add the given stream.
void add(const StreamMetaType &stream_meta_type, const DataDefinition &source_dd)
Merges or add the given streammetatype.
StructTypeAccess getStructTypeAccess(const std::string &type_name) const
Get the Struct Type Access, where to enter the type and calculated element position information.
const StreamMetaTypes & getStreamMetaTypes() const
Get the Streammeta Types of the datamodel.
DataDefinition(DataDefinition &&other)
Construct a new DataDefinition object and take the datamodel of the other.
DataDefinition & operator=(const DataDefinition &other)
Assigns the DataDefinition object and copies the datamodel.
const DataTypes & getDataTypes() const
Get the Data Types of the datamodel.
const Streams & getStreams() const
Get the Streams of the datamodel.
DataDefinition(const DataDefinition &other)
Construct a new DataDefinition object and copies the datamodel.
StreamMetaTypes & getStreamMetaTypes()
Get the Streammeta Types of the datamodel.
const Header & getHeader() const
Gets the Header of the datamodel.
void add(const Unit &unit, const DataDefinition &source_dd)
Merges or add the given unit.
const Units & getUnits() const
Get the Units of the datamodel.
std::shared_ptr< const datamodel::DataDefinition > getModel() const
Gets the datamodel reference.
DataDefinition(const std::shared_ptr< datamodel::DataDefinition > &datamodel)
Construct a new DataDefinition object and set the datamodel to the given one.
Version getVersion() const
Get the current language version set in datamodel.
DataTypes & getDataTypes()
Get the Data Types of the datamodel.
UnitPrefixes & getUnitPrefixes()
Get the Unit Prefixes of the datamodel.
virtual ~DataDefinition()
Destroy the DataDefinition object.
const UnitPrefixes & getUnitPrefixes() const
Get the Unit Prefixes of the datamodel.
Accessing class for a instance of a struct.
utility::TypeAccessMap< UnitPrefix, DataDefinition > UnitPrefixes
container class for all UnitPrefixes
utility::TypeAccessMap< DataType, DataDefinition > DataTypes
container class for all DataTypes
utility::TypeAccessMap< EnumType, DataDefinition > EnumTypes
container class for all EnumTypes
utility::TypeAccessMap< Stream, DataDefinition > Streams
container class for all Streams
utility::TypeAccessMap< StructType, DataDefinition > StructTypes
container class for all StructTypes
utility::TypeAccessMap< StreamMetaType, DataDefinition > StreamMetaTypes
container class for all StreamMetaTypes
utility::TypeAccessMap< BaseUnit, DataDefinition > BaseUnits
container class for all BaseUnits
utility::TypeAccessMap< Unit, DataDefinition > Units
container class for all Units
observable DataDefinition object class to describe (POD) DataType.
observable DataDefinition object class to describe EnumType.
Data Definition datamodel for the Header.
observable Stream DataDefinition object.
observable DataDefinition object class to describe StreamMetaType.
observable DataDefinition object class to describe StructType.
Unit Prefix - datamodel pefixes.
The ModelObserver utility template.
OO DataDefinition Redesign.
OO DataDefinition Common Design.
OO DataDefinition info model types.
OO DataDefinition Redesign.
ModelEventCode
Model event code for the data model observer.
datamodel::StreamMetaType StreamMetaType
Reuse of datamodel streammetatype class - ddl::dd::datamodel::StreamMetaType.
Definition: dd.h:58
datamodel::DataType DataType
Reuse of datamodel datatype class - ddl::dd::datamodel::DataType.
Definition: dd.h:46
bool addStreamTypeByName(const std::string &stream_type_name, const DataDefinition &source_dd, DataDefinition &destination_dd)
Merges or add the streamtype with the name of stream_type_name.
datamodel::EnumType EnumType
Reuse of datamodel enumtype class - ddl::dd::datamodel::EnumType.
Definition: dd.h:50
datamodel::BaseUnit BaseUnit
Reuse of datamodel base unit class - ddl::dd::datamodel::BaseUnit.
Definition: dd.h:34
std::vector< std::string > transformValidationProblemList(const std::vector< ddl::dd::Problem > &problems)
transforms the validation protocol of problems to a simple vrctor of strings.
datamodel::UnitPrefix UnitPrefix
Reuse of datamodel unit prefix class - ddl::dd::datamodel::UnitPrefix.
Definition: dd.h:38
datamodel::Unit Unit
Reuse of datamodel unit class - ddl::dd::datamodel::Unit.
Definition: dd.h:42
bool addTypeByName(const std::string &type_name, const DataDefinition &source_dd, DataDefinition &destination_dd)
Helper function which merges or adds the type with the name of type_name.
TypeOfType
Classification of a Type.
@ enum_type
the type is a enum type (EnumType)
@ data_type
the type is a data type (DataType)
@ struct_type
the type is a struct type (StructType)
@ invalid_type
the type is unknown
@ stream_meta_type
the type is an stream meta type (StreamMetaType)
datamodel::StructType StructType
Reuse of datamodel structtype class - ddl::dd::datamodel::StructType.
Definition: dd.h:54
TypeOfUnit
Classification of unit.
@ unit
the unit is a unit (Unit)
@ base_unit
the unit is a base unit (BaseUnit)
datamodel::Stream Stream
Reuse of datamodel stream class - ddl::dd::datamodel::Stream.
Definition: dd.h:62
bool addUnitByName(const std::string &unit_name, const DataDefinition &source_dd, DataDefinition &destination_dd)
Merges or add the unit with the name of unit_name.
datamodel::Header Header
Reuse of datamodel header class - ddl::dd::datamodel::Header.
Definition: dd.h:30
dd::DataDefinition DataDescription
Alias Name for DataDefinition, formally known as DataDescription.
Definition: dd.h:652
ValidationLevel
Validation level.
@ dont_know
The validation is not known.
@ valid
every thing is well defined.