From 9c4873ce66d6c33806c2b0c62aeeee72f6d15311 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Fri, 9 Nov 2018 13:58:10 +0100 Subject: [PATCH] [MeL] Add non-const version of getPropertyVector. --- MeshLib/Properties-impl.h | 36 ++++++++++++++++++++++++++++++++++++ MeshLib/Properties.h | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h index e3ee3b9b3ab..ff61aab5242 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 220889273ce..f31ea3c70af 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 -- GitLab