diff --git a/MaterialLib/MPL/Component.cpp b/MaterialLib/MPL/Component.cpp index b1315d0c1fea9cec97c8947a6c1812b9a4a35f01..ad24c9e12bc0bea80fd436529f6b7d75541ba803 100644 --- a/MaterialLib/MPL/Component.cpp +++ b/MaterialLib/MPL/Component.cpp @@ -34,4 +34,9 @@ Property const& Component::property(PropertyType const& p) const { return *_properties[p]; } + +bool Component::hasProperty(PropertyType const& p) const +{ + return _properties[p] != nullptr; +} } // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Component.h b/MaterialLib/MPL/Component.h index 03aba9e4c05f7d99691b4b7b521dd9d1da3bab21..05aaca3c6dd6505e50595ad40946c3f4018bb363 100644 --- a/MaterialLib/MPL/Component.h +++ b/MaterialLib/MPL/Component.h @@ -34,6 +34,7 @@ public: /// A get-function for retrieving a certain property. Property const& property(PropertyType const& /*p*/) const; + bool hasProperty(PropertyType const& p) const; template <typename T> T value(PropertyType const p) const @@ -84,4 +85,18 @@ protected: std::unique_ptr<Component> newComponent(std::string const& component_name, bool& isCustomComponent); +template <typename Container> +void checkRequiredProperties(Component const& c, + Container const& required_properties) +{ + for (auto const& p : required_properties) + { + if (!c.hasProperty(p)) + { + OGS_FATAL("The property '%s' is missing in the component '%s'.", + property_enum_to_string[p].c_str(), c.name.c_str()); + } + } +} + } // namespace MaterialPropertyLib