ADTF  3.18.2
dd_validationinfomodel.h
Go to the documentation of this file.
1 
14 #ifndef DD_VALIDATIONINFOMODEL_H_INCLUDED
15 #define DD_VALIDATIONINFOMODEL_H_INCLUDED
16 
17 #include <a_util/preprocessor/deprecated.h> // DEV_ESSENTIAL_DEPRECATED()
19 #include <ddl/dd/dd_error.h>
21 
22 #include <map>
23 #include <memory>
24 #include <unordered_map>
25 #include <unordered_set>
26 
28 #define DEV_ESSENTIAL_DEPRECATED_VALIDATION_API \
29  DEV_ESSENTIAL_DEPRECATED("Use the ddl::dd::DataDefinition::isValid() and " \
30  "ddl::dd::DataDefinition::getValidationProtocol() instead.")
32 
33 namespace ddl {
34 
35 namespace dd {
47 class ValidationServiceInfo : public datamodel::Info<ValidationServiceInfo> {
48 public:
50  static constexpr const uint8_t INFO_TYPE_ID = dd::InfoType::validation_service_info;
51 
56  enum DependencyType : uint8_t {
83  };
84 
88  DEV_ESSENTIAL_DEPRECATED_VALIDATION_API
89  ValidationServiceInfo() = default;
90 
95  struct Dependency {
96  public:
101  Dependency() = delete;
109  Dependency(DependencyType type_of_dependency,
110  const std::string& from,
111  const std::string& to);
116  ~Dependency() = default;
117 
127  std::string _from;
132  std::string _to;
133  };
134 
140  void addDependency(const Dependency& dependency);
154  void removed(const datamodel::UnitPrefix& unit_prefix, datamodel::DataDefinition& parent_dd);
196  datamodel::DataDefinition& parent_dd);
203  void removed(const datamodel::Stream& stream, datamodel::DataDefinition& parent_dd);
204 
213  const std::string& old_name,
214  datamodel::DataDefinition& parent_dd);
222  void renamed(const datamodel::UnitPrefix& unit_prefix,
223  const std::string& old_name,
224  datamodel::DataDefinition& parent_dd);
233  const std::string& old_name,
234  datamodel::DataDefinition& parent_dd);
243  const std::string& old_name,
244  datamodel::DataDefinition& parent_dd);
253  const std::string& old_name,
254  datamodel::DataDefinition& parent_dd);
263  const std::string& old_name,
264  datamodel::DataDefinition& parent_dd);
273  const std::string& old_name,
274  datamodel::DataDefinition& parent_dd);
282  void renamed(const datamodel::Stream& stream,
283  const std::string& old_name,
284  datamodel::DataDefinition& parent_dd);
285 
292  bool validationNeeded() const;
296  typedef std::unordered_map<std::string, std::unordered_set<std::string>> ToFromMap;
297 
306  std::vector<std::string> _enum_type_names;
310  std::vector<std::string> _struct_type_names;
311  };
319  void forceRevalidationOfTypeDependencies(const std::string& type_name,
320  ddl::dd::TypeOfType type,
321  datamodel::DataDefinition& parent_dd,
322  InvalidatedTypes& invalidated_types_to_return) const;
326  using ValidationProblemId = void*;
331  public:
335  ValidationProblem() = default;
357 
358  private:
360  ddl::dd::Problem _problem = {};
361  };
362 
369  const std::shared_ptr<const ValidationProblem>& problem);
386  std::vector<Problem> getProblems() const;
387 
388 private:
393 #if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
394 #pragma GCC diagnostic push
395 #pragma GCC diagnostic ignored "-Wattributes"
396 #endif // defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
397 
398  std::unordered_map<uint8_t, ToFromMap> _dependencies;
399  std::map<uint8_t,
400  std::unordered_map<ValidationProblemId, std::shared_ptr<const ValidationProblem>>>
401  _validation_problems;
402 
403 #if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
404 #pragma GCC diagnostic pop
405 #endif // defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
406 
407  bool _validation_needed = true;
408 };
409 
420 class ValidationInfo : public datamodel::Info<ValidationInfo> {
421 public:
423  static constexpr const uint8_t INFO_TYPE_ID = dd::InfoType::validation_info;
424 
428  DEV_ESSENTIAL_DEPRECATED_VALIDATION_API
429  ValidationInfo() = default;
436  DEV_ESSENTIAL_DEPRECATED_VALIDATION_API
444  DEV_ESSENTIAL_DEPRECATED_VALIDATION_API
452  DEV_ESSENTIAL_DEPRECATED_VALIDATION_API
460  DEV_ESSENTIAL_DEPRECATED_VALIDATION_API
466  virtual ~ValidationInfo();
467 
471  enum ValidationLevel : uint8_t {
501  valid
502  };
503 
509 
518 
530 
536  std::vector<Problem> getProblems() const;
549 
554 
579  enum class UpdateType {
580  all = 0,
581  only_last = 1
582  };
591  datamodel::DataDefinition& parent_dd,
592  UpdateType update_type = UpdateType::all);
607 
608 private:
609  bool _currently_on_validation = false; // to prevent recursive validation calls if somebody
610  // defines this type as a part of the type
611  void addProblem(const std::shared_ptr<ValidationServiceInfo::ValidationProblem>& problem);
612  std::map<uint8_t,
614  std::shared_ptr<ValidationServiceInfo::ValidationProblem>>>
615  _validation_problems;
616  ValidationServiceInfo* _current_validation_service = {};
617  bool _is_validated = false;
618 };
619 
620 } // namespace dd
621 } // namespace ddl
622 
623 #endif // DD_VALIDATIONINFOMODEL_H_INCLUDED
Validation Info model will check for validation.
UpdateType
Update type for the struct update.
@ only_last
update the last element only
@ all
update all elements validation info
DEV_ESSENTIAL_DEPRECATED_VALIDATION_API ValidationInfo(datamodel::EnumType &enum_type, datamodel::DataDefinition &parent_dd)
CTOR and immediatelly update a Validation Info for enum_type.
ValidationLevel getValidationLevel() const
Get the Validation Level.
virtual ~ValidationInfo()
DTOR.
void removeProblems(datamodel::DataDefinition &parent_dd)
Remove all problems.
bool isValid(ValidationLevel level=ValidationLevel::valid) const
checks if the validation level is reached
void addProblem(ValidationServiceInfo::ValidationProblem &&problem)
adds a problem
static constexpr const uint8_t INFO_TYPE_ID
the type info id to use the datamodel::Info template.
void forceRevalidation()
sets the Info to invalid to force revalidation
void update(datamodel::StructType &struct_type, datamodel::DataDefinition &parent_dd, UpdateType update_type=UpdateType::all)
Update and revalidate the struct_type.
std::vector< Problem > getProblems() const
Get the Validation Problems (only set if below "valid")
DEV_ESSENTIAL_DEPRECATED_VALIDATION_API ValidationInfo(datamodel::DataType &data_type, datamodel::DataDefinition &parent_dd)
CTOR and immediatelly update a Validation Info for data_types.
void update(datamodel::Stream &stream, datamodel::DataDefinition &parent_dd)
Update and revalidate the stream.
void update(datamodel::StreamMetaType &stream_meta_type, datamodel::DataDefinition &parent_dd)
Update and revalidate the stream_meta_type.
void addProblem(const ValidationServiceInfo::ValidationProblem &problem)
adds a problem
void update(datamodel::DataType &data_type, datamodel::DataDefinition &parent_dd)
Update and revalidate the data_type.
DEV_ESSENTIAL_DEPRECATED_VALIDATION_API ValidationInfo()=default
default CTOR
DEV_ESSENTIAL_DEPRECATED_VALIDATION_API ValidationInfo(datamodel::Unit &unit, datamodel::DataDefinition &parent_dd)
CTOR and immediatelly update a Validation Info for units.
@ valid
every thing is well defined.
@ good_enough
Structs and elements can be "good_enough" for the TypeInfo.
@ invalid
the validation level is invalid, dependencies can not be obtained or the dependency "to" is invalid (...
@ dont_know
The validation is not known.
void update(datamodel::Unit &unit, datamodel::DataDefinition &parent_dd)
Update and revalidate the unit.
DEV_ESSENTIAL_DEPRECATED_VALIDATION_API ValidationInfo(datamodel::Stream &stream, datamodel::DataDefinition &parent_dd)
CTOR and immediatelly update a Validation Info for streams.
void update(datamodel::EnumType &enum_type, datamodel::DataDefinition &parent_dd)
Update and revalidate the enum_type.
ValidationLevel getLevel() const
Get the Level.
ValidationProblem(const ddl::dd::Problem &problem)
CTOR which sets the level to ValidationLevel::invalid.
ValidationProblem(ValidationLevel level, const ddl::dd::Problem &problem)
CTOR.
ddl::dd::Problem getProblem() const
Get the Problem.
Validation Service Info used only as one global instance at the dd::DataDefinition.
void renamed(const datamodel::Stream &stream, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed stream.
ValidationLevel getValidationLevel() const
Get the current Validation Level.
std::unordered_map< uint8_t, ToFromMap > _dependencies
dependencies are stored in ToFrom maps (not in FromTo maps)
DependencyType
dependency type for loose coupling
@ struct_type_to_unit
dependency struct type depends on a unit, if one element belongs to it
@ struct_type_to_enum_type
dependency struct type depends on a enum type
@ data_type_to_unit
dependency data type depends on a unit
@ data_type_to_base_unit
dependency data type depends on a base unit
@ stream_meta_type_to_stream_meta_type
dependency stream_meta_type depends on a stream_meta_type
@ struct_type_to_data_type
dependency struct type depends on a data type
@ unit_to_base_unit
dependency unit depends on a base unit
@ stream_to_stream_meta_type
dependency stream depends on a stream_meta_type
@ struct_type_to_struct_type
dependency struct type depends on a struct type
@ enum_type_to_data_type
dependency enum type depends on a data type
@ struct_type_to_base_unit
dependency struct type depends on a base unit, if one element belongs to it
@ stream_to_struct_type
dependency stream depends on a struct_type
@ unit_to_unit_prefix
dependency unit depends on a unit prefix
void removed(const datamodel::StreamMetaType &stream_meta_type, datamodel::DataDefinition &parent_dd)
A stream_meta_type was removed.
void renamed(const datamodel::UnitPrefix &unit_prefix, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed unit_prefix.
void removed(const datamodel::EnumType &enum_type, datamodel::DataDefinition &parent_dd)
A enum_type was removed.
void forceRevalidationOfTypeDependencies(const std::string &type_name, ddl::dd::TypeOfType type, datamodel::DataDefinition &parent_dd, InvalidatedTypes &invalidated_types_to_return) const
Collect all dependent types to the given one and sets them invalid.
std::unordered_map< std::string, std::unordered_set< std::string > > ToFromMap
dependencies are stored in ToFrom maps (not in FromTo maps) to raise performance.
static constexpr const uint8_t INFO_TYPE_ID
definiton of info type to use the datamodel::Info
void renamed(const datamodel::BaseUnit &base_unit, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed base_unit.
void renamed(const datamodel::Unit &unit, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed unit.
void renamed(const datamodel::DataType &data_type, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed data_type.
DEV_ESSENTIAL_DEPRECATED_VALIDATION_API ValidationServiceInfo()=default
default CTOR
void removed(const datamodel::BaseUnit &base_unit, datamodel::DataDefinition &parent_dd)
A base unit was removed.
std::vector< Problem > getProblems() const
Get all current known problems of validation.
void removed(const datamodel::UnitPrefix &unit_prefix, datamodel::DataDefinition &parent_dd)
A unit prefix was removed.
void renamed(const datamodel::EnumType &enum_type, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed enum_type.
void addDependency(const Dependency &dependency)
add the dependency to the depemndency model
void removed(const datamodel::Unit &unit, datamodel::DataDefinition &parent_dd)
A unit was removed.
void renamed(const datamodel::StreamMetaType &stream_meta_type, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed base_stream_meta_typeunit.
void removed(const datamodel::Stream &stream, datamodel::DataDefinition &parent_dd)
A stream was removed.
void renamed(const datamodel::StructType &struct_type, const std::string &old_name, datamodel::DataDefinition &parent_dd)
Update all dependency to the renamed struct_type.
void removeProblem(ValidationProblemId id, ValidationLevel level)
Removes a validation propbelm entry by id and level.
void * ValidationProblemId
Id to identify a concrete validation problem entry.
void updateProblem(ValidationProblemId id, const std::shared_ptr< const ValidationProblem > &problem)
updates or add a problem entry by id
void removed(const datamodel::DataType &data_type, datamodel::DataDefinition &parent_dd)
A data_type was removed.
void removed(const datamodel::StructType &struct_type, datamodel::DataDefinition &parent_dd)
A struct_type was removed.
bool validationNeeded() const
this will internally prevent multiple revalidations
DataDefinition Datamodel This datamodel is observable for any change of:
observable DataDefinition object class to describe (POD) DataType.
observable DataDefinition object class to describe EnumType.
Helper template class to create valid IInfo objects.
observable Stream DataDefinition object.
observable DataDefinition object class to describe StreamMetaType.
observable DataDefinition object class to describe StructType.
Unit Prefix - datamodel pefixes.
OO DataDefinition Redesign.
OO DataDefinition Redesign.
OO DataDefinition info model types.
Definition of preprocessor macro DEV_ESSENTIAL_DEPRECATED.
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)
@ stream_meta_type
the type is an stream meta type (StreamMetaType)
@ unit
the unit is a unit (Unit)
@ base_unit
the unit is a base unit (BaseUnit)
ValidationLevel
Validation level.
@ valid
every thing is well defined.
@ validation_info
Validation Info.
@ validation_service_info
Validation Info Service.
Problem to report to find the corresponding item name in a simple way.
Definition: dd_error.h:29
DependencyType _type_of_dependency
Dependency type.
Dependency(DependencyType type_of_dependency, const std::string &from, const std::string &to)
CTOR.
Return structure for forceRevalidationOfTypeDependencies call.
std::vector< std::string > _enum_type_names
Collection of enum type names that are invalidated.
std::vector< std::string > _struct_type_names
Collection of struct type names that are invalidated.