Skip to content
Snippets Groups Projects
Commit 6c5d77d3 authored by Tom Fischer's avatar Tom Fischer
Browse files

[MPL/Component] hasProperty(): check if the prop. exists.

parent a5af0320
No related branches found
No related tags found
No related merge requests found
...@@ -34,4 +34,9 @@ Property const& Component::property(PropertyType const& p) const ...@@ -34,4 +34,9 @@ Property const& Component::property(PropertyType const& p) const
{ {
return *_properties[p]; return *_properties[p];
} }
bool Component::hasProperty(PropertyType const& p) const
{
return _properties[p] != nullptr;
}
} // namespace MaterialPropertyLib } // namespace MaterialPropertyLib
...@@ -34,6 +34,7 @@ public: ...@@ -34,6 +34,7 @@ public:
/// A get-function for retrieving a certain property. /// A get-function for retrieving a certain property.
Property const& property(PropertyType const& /*p*/) const; Property const& property(PropertyType const& /*p*/) const;
bool hasProperty(PropertyType const& p) const;
template <typename T> template <typename T>
T value(PropertyType const p) const T value(PropertyType const p) const
...@@ -84,4 +85,18 @@ protected: ...@@ -84,4 +85,18 @@ protected:
std::unique_ptr<Component> newComponent(std::string const& component_name, std::unique_ptr<Component> newComponent(std::string const& component_name,
bool& isCustomComponent); 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 } // namespace MaterialPropertyLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment