diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h index e3ee3b9b3abe29f164894fba6af0bef979b0b11f..ff61aab52427491336525bc03ca8069ea4be5942 100644 --- a/MeshLib/Properties-impl.h +++ b/MeshLib/Properties-impl.h @@ -163,3 +163,39 @@ PropertyVector<T> const* Properties::getPropertyVector( } return property; } + +template <typename T> +PropertyVector<T>* Properties::getPropertyVector(std::string const& name, + MeshItemType const item_type, + int const n_components) +{ + auto const it = _properties.find(name); + if (it == _properties.end()) + { + OGS_FATAL("A PropertyVector with name '%s' does not exist in the mesh.", + name.c_str()); + } + + auto property = dynamic_cast<PropertyVector<T>*>(it->second); + if (property == nullptr) + { + OGS_FATAL( + "Could not cast the data type of the PropertyVector '%s' to " + "requested data type.", + name.c_str()); + } + if (property->getMeshItemType() != item_type) + { + OGS_FATAL( + "The PropertyVector '%s' has type '%s'. A '%s' field is requested.", + name.c_str(), toString(property->getMeshItemType()), + toString(item_type)); + } + if (property->getNumberOfComponents() != n_components) + { + OGS_FATAL( + "PropertyVector '%s' has %d components, %d components are needed.", + name.c_str(), property->getNumberOfComponents(), n_components); + } + return property; +} diff --git a/MeshLib/Properties.h b/MeshLib/Properties.h index 220889273ce304535c789317a54ffc5c6ab45ab5..f31ea3c70afa69da712150eb5bbdbb62a127152b 100644 --- a/MeshLib/Properties.h +++ b/MeshLib/Properties.h @@ -103,6 +103,14 @@ public: MeshItemType const item_type, int const n_components) const; + /// Non-const version of getPropertyVector returns a property vector with + /// given \c name, \c item_type and \c number_of_components or calls + /// OGS_FATAL if no such property vector exists. + template <typename T> + PropertyVector<T>* getPropertyVector(std::string const& name, + MeshItemType const item_type, + int const number_of_components); + void removePropertyVector(std::string const& name); /// Check if a PropertyVector accessible by the name is already