From e0fcde4f3ae0603d1f42c1072042b3ab250efbf3 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Mon, 24 Oct 2022 16:40:14 +0200 Subject: [PATCH 1/2] [MeL] Add detailed types output on errors --- MeshLib/Properties-impl.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h index 97ce4ef517e..ae5f7351a0c 100644 --- a/MeshLib/Properties-impl.h +++ b/MeshLib/Properties-impl.h @@ -10,6 +10,8 @@ * */ +#include + template PropertyVector* Properties::createNewPropertyVector( std::string_view name, MeshItemType mesh_item_type, @@ -94,14 +96,24 @@ bool Properties::existsPropertyVector(std::string_view name, auto property = dynamic_cast*>(it->second); if (property == nullptr) { + WARN("Property {} exists but does not have the requested type {}.", + name, typeid(T).name()); return false; } if (property->getMeshItemType() != mesh_item_type) { + WARN( + "Property {} exists but does not have the requested mesh item type " + "{}.", + name, toString(mesh_item_type)); return false; } if (property->getNumberOfGlobalComponents() != number_of_components) { + WARN( + "Property {} exists but does not have the requested number of " + "components {}", + name, number_of_components); return false; } return true; @@ -181,9 +193,10 @@ PropertyVector const* Properties::getPropertyVector( if (property == nullptr) { OGS_FATAL( - "Could not cast the data type of the PropertyVector '{:s}' to " - "requested data type.", - name); + "Could not cast the data type of the PropertyVector '{:s}' (type: " + "'{:s}') to the requested data type '{:s}'.", + name, typeid(decltype(*it->second)).name(), + typeid(PropertyVector).name()); } if (property->getMeshItemType() != item_type) { From 95253a06808bd3b7f052be7668930a8ccff4b364 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Tue, 25 Jun 2024 15:46:56 +0200 Subject: [PATCH 2/2] [MeL] Reuse non-const impl. for const case --- MeshLib/Properties-impl.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h index ae5f7351a0c..2746730ca64 100644 --- a/MeshLib/Properties-impl.h +++ b/MeshLib/Properties-impl.h @@ -123,20 +123,8 @@ template PropertyVector const* Properties::getPropertyVector( std::string_view name) const { - auto it(_properties.find(std::string(name))); - if (it == _properties.end()) - { - OGS_FATAL("The PropertyVector '{:s}' is not available in the mesh.", - name); - } - if (!dynamic_cast const*>(it->second)) - { - OGS_FATAL( - "The PropertyVector '{:s}' has a different type than the requested " - "PropertyVector.", - name); - } - return dynamic_cast const*>(it->second); + return const_cast const*>( + const_cast(this)->getPropertyVector(name)); } template