From 8a5669d0d937e175b201afa3687d264010a11d45 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Fri, 13 Dec 2024 16:45:57 -0500 Subject: [PATCH] cleaning up mah and making attributetype printable --- src/wmtk/attribute/AttributeType.cpp | 24 ++++++++++++++++++++++ src/wmtk/attribute/AttributeType.hpp | 17 +++++++++------ src/wmtk/attribute/CMakeLists.txt | 1 + src/wmtk/attribute/MeshAttributeHandle.hpp | 21 +++++++------------ 4 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 src/wmtk/attribute/AttributeType.cpp diff --git a/src/wmtk/attribute/AttributeType.cpp b/src/wmtk/attribute/AttributeType.cpp new file mode 100644 index 0000000000..a3fc3185ff --- /dev/null +++ b/src/wmtk/attribute/AttributeType.cpp @@ -0,0 +1,24 @@ +#include "AttributeType.hpp" +namespace wmtk::attribute { +const std::string_view attribute_type_name(AttributeType pt) { + + switch(pt) { + case AttributeType::Char: + return attribute_type_traits::name; + case AttributeType::Int64: + return attribute_type_traits::name; + case AttributeType::Double: + return attribute_type_traits::name; + case AttributeType::Rational: + return attribute_type_traits::name; + default: + break; + } + return ""; +} + +const std::string_view attribute_type_traits::name = "Rational"; +const std::string_view attribute_type_traits::name = "Double"; +const std::string_view attribute_type_traits::name = "Int64"; +const std::string_view attribute_type_traits::name = "Char"; +} diff --git a/src/wmtk/attribute/AttributeType.hpp b/src/wmtk/attribute/AttributeType.hpp index 3cccfddf19..c7e3938f50 100644 --- a/src/wmtk/attribute/AttributeType.hpp +++ b/src/wmtk/attribute/AttributeType.hpp @@ -5,32 +5,36 @@ namespace wmtk::attribute { enum class AttributeType { Char = 0, Int64 = 1, Double = 2, Rational = 3 }; template -struct type_from_attribute_type_enum +struct attribute_type_traits { }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = char; + const static std::string_view name; }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = double; + const static std::string_view name; }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = int64_t; + const static std::string_view name; }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = wmtk::Rational; + const static std::string_view name; }; template -using type_from_attribute_type_enum_t = typename type_from_attribute_type_enum::type; +using type_from_attribute_type_enum_t = typename attribute_type_traits::type; template inline constexpr auto attribute_type_enum_from_type() -> AttributeType @@ -53,4 +57,5 @@ inline constexpr auto attribute_type_enum_from_type() -> AttributeType return AttributeType::Char; } } +const std::string_view attribute_type_name(AttributeType pt); } // namespace wmtk::attribute diff --git a/src/wmtk/attribute/CMakeLists.txt b/src/wmtk/attribute/CMakeLists.txt index cd8f3506ca..7b2d12439b 100644 --- a/src/wmtk/attribute/CMakeLists.txt +++ b/src/wmtk/attribute/CMakeLists.txt @@ -35,6 +35,7 @@ set(SRC_FILES Accessor.hpp AttributeType.hpp + AttributeType.cpp ) target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES}) diff --git a/src/wmtk/attribute/MeshAttributeHandle.hpp b/src/wmtk/attribute/MeshAttributeHandle.hpp index 5faf2539e4..7c895088f0 100644 --- a/src/wmtk/attribute/MeshAttributeHandle.hpp +++ b/src/wmtk/attribute/MeshAttributeHandle.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace wmtk { class Mesh; @@ -76,21 +77,13 @@ class MeshAttributeHandle bool operator==(const MeshAttributeHandle& o) const { -#if defined(MTAO_DEBUG_MESH_COMP) - std::visit( - [&](const auto& h, const auto& oh) { - spdlog::warn( - "{} {} == {} {}", - std::string(h), - fmt::ptr(m_mesh), - std::string(oh), - fmt::ptr(m_mesh)); - }, - m_handle, - o.m_handle); -#endif - return m_handle == o.m_handle && m_mesh == o.m_mesh; + return std::tie(m_mesh, m_handle) == std::tie(o.m_mesh, o.m_handle); } + bool operator<(const MeshAttributeHandle& o) const + { + return std::tie(m_mesh, m_handle) < std::tie(o.m_mesh, o.m_handle); + } + // reutrns if the target mesh is the same as the one represented in the handle bool is_same_mesh(const Mesh&) const;