Skip to content
Snippets Groups Projects
Commit e29825a0 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Improve error message if bad mesh variant is accessed

parent 29a73e7f
No related branches found
No related tags found
1 merge request!182Get rid of IMesh (mesh interface class) and use MeshVariant instead
#ifndef MESH_VARIANT_HPP
#define MESH_VARIANT_HPP
#include <mesh/MeshTraits.hpp>
#include <utils/Demangle.hpp>
#include <utils/Exceptions.hpp>
#include <utils/PugsMacros.hpp>
#include <rang.hpp>
#include <iostream>
#include <memory>
#include <sstream>
#include <variant>
class IConnectivity;
......@@ -38,6 +44,16 @@ class MeshVariant
PUGS_INLINE std::shared_ptr<const MeshType>
get() const
{
if (not std::holds_alternative<std::shared_ptr<const MeshType>>(this->m_p_mesh_variant)) {
std::ostringstream error_msg;
error_msg << "invalid mesh type type\n";
error_msg << "- required " << rang::fgB::red << demangle<MeshType>() << rang::fg::reset << '\n';
error_msg << "- contains " << rang::fgB::yellow
<< std::visit([](auto&& p_mesh) -> std::string { return demangle<mesh_type_t<decltype(p_mesh)>>(); },
this->m_p_mesh_variant)
<< rang::fg::reset;
throw NormalError(error_msg.str());
}
return std::get<std::shared_ptr<const MeshType>>(m_p_mesh_variant);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment