Skip to content

Commit

Permalink
Merge branch 'MeshLibErrorMsgImprovements' into 'master'
Browse files Browse the repository at this point in the history
MeshLib error message improvements

See merge request ogs/ogs!5028
  • Loading branch information
endJunction committed Jun 26, 2024
2 parents 1faae5a + 95253a0 commit 2d0109b
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions MeshLib/Properties-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
*/

#include <typeinfo>

template <typename T>
PropertyVector<T>* Properties::createNewPropertyVector(
std::string_view name, MeshItemType mesh_item_type,
Expand Down Expand Up @@ -94,14 +96,24 @@ bool Properties::existsPropertyVector(std::string_view name,
auto property = dynamic_cast<PropertyVector<T>*>(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;
Expand All @@ -111,20 +123,8 @@ template <typename T>
PropertyVector<T> 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<PropertyVector<T> const*>(it->second))
{
OGS_FATAL(
"The PropertyVector '{:s}' has a different type than the requested "
"PropertyVector.",
name);
}
return dynamic_cast<PropertyVector<T> const*>(it->second);
return const_cast<PropertyVector<T> const*>(
const_cast<Properties*>(this)->getPropertyVector<T>(name));
}

template <typename T>
Expand Down Expand Up @@ -181,9 +181,10 @@ PropertyVector<T> 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<T>).name());
}
if (property->getMeshItemType() != item_type)
{
Expand Down

0 comments on commit 2d0109b

Please sign in to comment.