From 17b0db37ce302be453e25e0bccc5ca8613544565 Mon Sep 17 00:00:00 2001
From: Wenqing Wang <wenqing.wang@ufz.de>
Date: Tue, 7 Mar 2023 11:57:14 +0100
Subject: [PATCH] [PropertyVector] Added an overload function hasPropertyVector

---
 MeshLib/Properties-impl.h | 17 +++++++++++++++++
 MeshLib/Properties.h      |  8 ++++++++
 2 files changed, 25 insertions(+)

diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h
index ba0dcafd9bb..fbde93ac70f 100644
--- a/MeshLib/Properties-impl.h
+++ b/MeshLib/Properties-impl.h
@@ -147,6 +147,23 @@ PropertyVector<T>* Properties::getPropertyVector(std::string_view name)
     return dynamic_cast<PropertyVector<T>*>(it->second);
 }
 
+template <typename T>
+bool Properties::hasPropertyVector(std::string const& name,
+                                   MeshItemType const item_type) const
+{
+    auto const it = _properties.find(name);
+
+    if (it == _properties.end())
+    {
+        return false;
+    }
+
+    auto property = dynamic_cast<PropertyVector<T>*>(it->second);
+
+    return (property == nullptr) ? false
+                                 : property->getMeshItemType() == item_type;
+}
+
 template <typename T>
 PropertyVector<T> const* Properties::getPropertyVector(
     std::string_view name, MeshItemType const item_type,
diff --git a/MeshLib/Properties.h b/MeshLib/Properties.h
index 94043d16e15..5412c2421b9 100644
--- a/MeshLib/Properties.h
+++ b/MeshLib/Properties.h
@@ -123,6 +123,14 @@ public:
     /// @param name the name of the property (for instance porosity)
     bool hasPropertyVector(std::string_view name) const;
 
+    /// Check if a PropertyVector accessible by the name and by the item type
+    /// is already stored within the Properties object.
+    /// @param name      the name of the property, e.g. porosity.
+    /// @param item_type the type of mesh entity, e.g. CELL.
+    template <typename T>
+    bool hasPropertyVector(std::string const& name,
+                           MeshItemType const item_type) const;
+
     std::vector<std::string> getPropertyVectorNames() const;
     std::vector<std::string> getPropertyVectorNames(
         MeshLib::MeshItemType t) const;
-- 
GitLab