Skip to content

Commit

Permalink
adding print support to AttributeType
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Dec 11, 2024
1 parent 0f866e5 commit e03ee31
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,32 +116,40 @@ wmtk::attribute::MeshAttributeHandle get_attribute(
auto add_option = [&](PrimitiveType prim, AT t) {
ret = get_attribute(mesh, name, prim, t);

assert(ret.is_valid());
uint8_t dimension = wmtk::get_primitive_type_id(prim);
possibilities.emplace_back(AttributeDescription{name, dimension, t});
};
if (pt.has_value() && type.has_value()) {
wmtk::logger().debug("Reading attribute {} with pt {} and type {}", name, primitive_type_name(pt.value()), attribute_type_name(type.value()));
add_option(pt.value(), type.value());

} else if (pt.has_value()) {
wmtk::logger().debug("Reading attribute {} with pt {}", name, primitive_type_name(pt.value()));
for (AT at : types) {
try {
wmtk::logger().trace("Attempting to read attribute {} with pt {} and guess {}", name, primitive_type_name(pt.value()), attribute_type_name(at));
add_option(pt.value(), at);
} catch (const attribute_missing_error& e) {
continue;
}
}
} else if (type.has_value()) {
wmtk::logger().debug("Reading attribute {} with and type {}", name,attribute_type_name(type.value()));
for (PrimitiveType p : wmtk::utils::primitive_below(mesh.top_simplex_type())) {
try {
wmtk::logger().trace("Attempting to read attribute {} with guess pt {} and type {}", name, primitive_type_name(p), attribute_type_name(type.value()));
add_option(p, type.value());
} catch (const attribute_missing_error& e) {
continue;
}
}
} else {
wmtk::logger().debug("Reading attribute {}", name);
for (AT at : types) {
for (PrimitiveType p : wmtk::utils::primitive_below(mesh.top_simplex_type())) {
try {
wmtk::logger().trace("Attempting to read attribute {} with guess pt {} and guess type {}", name, primitive_type_name(p), attribute_type_name(at));
add_option(p, at);
} catch (const attribute_missing_error& e) {
continue;
Expand Down
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) {

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;
}
return "";
}

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

0 comments on commit e03ee31

Please sign in to comment.