Skip to content

Commit

Permalink
cleaning up mah and making attributetype printable
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Dec 13, 2024
1 parent bd2e000 commit 8a5669d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
24 changes: 24 additions & 0 deletions src/wmtk/attribute/AttributeType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "AttributeType.hpp"
namespace wmtk::attribute {
const std::string_view attribute_type_name(AttributeType pt) {

Check warning on line 3 in src/wmtk/attribute/AttributeType.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/attribute/AttributeType.cpp#L3

Added line #L3 was not covered by tests

switch(pt) {
case AttributeType::Char:
return attribute_type_traits<AttributeType::Char>::name;
case AttributeType::Int64:
return attribute_type_traits<AttributeType::Int64>::name;
case AttributeType::Double:
return attribute_type_traits<AttributeType::Double>::name;
case AttributeType::Rational:
return attribute_type_traits<AttributeType::Rational>::name;
default:
break;

Check warning on line 15 in src/wmtk/attribute/AttributeType.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/attribute/AttributeType.cpp#L5-L15

Added lines #L5 - L15 were not covered by tests
}
return "";

Check warning on line 17 in src/wmtk/attribute/AttributeType.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/attribute/AttributeType.cpp#L17

Added line #L17 was not covered by tests
}

const std::string_view attribute_type_traits<AttributeType::Rational>::name = "Rational";
const std::string_view attribute_type_traits<AttributeType::Double>::name = "Double";
const std::string_view attribute_type_traits<AttributeType::Int64>::name = "Int64";
const std::string_view attribute_type_traits<AttributeType::Char>::name = "Char";
}
17 changes: 11 additions & 6 deletions src/wmtk/attribute/AttributeType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ namespace wmtk::attribute {
enum class AttributeType { Char = 0, Int64 = 1, Double = 2, Rational = 3 };

template <AttributeType AT>
struct type_from_attribute_type_enum
struct attribute_type_traits
{
};
template <>
struct type_from_attribute_type_enum<AttributeType::Char>
struct attribute_type_traits<AttributeType::Char>
{
using type = char;
const static std::string_view name;
};
template <>
struct type_from_attribute_type_enum<AttributeType::Double>
struct attribute_type_traits<AttributeType::Double>
{
using type = double;
const static std::string_view name;
};
template <>
struct type_from_attribute_type_enum<AttributeType::Int64>
struct attribute_type_traits<AttributeType::Int64>
{
using type = int64_t;
const static std::string_view name;
};
template <>
struct type_from_attribute_type_enum<AttributeType::Rational>
struct attribute_type_traits<AttributeType::Rational>
{
using type = wmtk::Rational;
const static std::string_view name;
};

template <AttributeType AT>
using type_from_attribute_type_enum_t = typename type_from_attribute_type_enum<AT>::type;
using type_from_attribute_type_enum_t = typename attribute_type_traits<AT>::type;

template <typename T>
inline constexpr auto attribute_type_enum_from_type() -> AttributeType
Expand All @@ -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
1 change: 1 addition & 0 deletions src/wmtk/attribute/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(SRC_FILES
Accessor.hpp

AttributeType.hpp
AttributeType.cpp

)
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})
Expand Down
21 changes: 7 additions & 14 deletions src/wmtk/attribute/MeshAttributeHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <tuple>
#include <variant>
#include <tuple>

namespace wmtk {
class Mesh;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8a5669d

Please sign in to comment.