Wildmeshing Toolkit
Loading...
Searching...
No Matches
FlagAccessor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Accessor.hpp"
4namespace wmtk::attribute {
5
6
7// A wrapper around standard accessor specify the semantics of individual bits in Flag attributes
8// This Index variant daels with indices as inputs directly
9template <typename MeshType = wmtk::Mesh>
11{
12public:
13 enum class FlagBit : char { Active = 0x1 };
14 static bool _is_active(char value) { return value & static_cast<char>(FlagBit::Active); }
15 static void _activate(char& value) { value |= static_cast<char>(FlagBit::Active); }
16 static void _deactivate(char& value) { value &= inverse_mask(FlagBit::Active); }
18
19
23 template <typename MeshType2>
27
28
29 bool is_active(int64_t t) const { return _is_active(attribute().const_scalar_attribute(t)); }
30 void activate(int64_t t) { return _activate(attribute().scalar_attribute(t)); }
31 void deactivate(int64_t t) { return _deactivate(attribute().scalar_attribute(t)); }
32
33 constexpr static char inverse_mask(FlagBit bit) { return 0xFF ^ static_cast<char>(bit); }
34
35
37 const BaseAccessor& base_accessor() const { return m_base_accessor; }
38 operator BaseAccessor() const { return m_base_accessor; }
39
42
43protected:
45
46
47 IndexFlagAccessor index_access() const { return IndexAccessor(*this); }
48};
49
50// A wrawpper around standard accessor specify the semantics of individual bits in Flag attributes
51// This Index variant daels with simplices/tuples as inputs
52template <typename MeshType = wmtk::Mesh>
53class FlagAccessor : private IndexFlagAccessor<MeshType>
54{
55public:
56 enum class FlagBit : char { Active = 1 };
58
60 using IndexBaseType::IndexBaseType;
61
62 template <typename MeshType2>
66
67 template <typename T>
68 bool is_active(const T& t) const
69 {
70 return IndexBaseType::_is_active(IndexBaseType::m_base_accessor.const_scalar_attribute(t));
71 }
72 template <typename T>
73 void activate(const T& t)
74 {
76 }
77 template <typename T>
78 void deactivate(const T& t)
79 {
81 }
82
83
84 const IndexBaseType& index_access() const { return *this; }
85 IndexBaseType& index_access() { return *this; }
86};
87
88
89} // namespace wmtk::attribute
An Accessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:44
AttributeType & attribute()
Definition Accessor.hxx:159
FlagAccessor(const FlagAccessor< MeshType2 > &o)
const IndexBaseType & index_access() const
bool is_active(const T &t) const
static bool _is_active(char value)
CachingAttribute< char > & attribute()
static void _deactivate(char &value)
IndexFlagAccessor(const IndexFlagAccessor< MeshType2 > &o)
static constexpr char inverse_mask(FlagBit bit)
IndexFlagAccessor index_access() const
const CachingAttribute< char > & attribute() const
Accessor< char, MeshType, CachingAttribute< char >, 1 > BaseAccessor
const BaseAccessor & base_accessor() const
static void _activate(char &value)