Wildmeshing Toolkit
CachingAccessor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <optional>
4 #include "AccessorBase.hpp"
5 
6 namespace wmtk {
7 class Mesh;
8 class TetMesh;
9 class TriMesh;
10 } // namespace wmtk
11 namespace wmtk::attribute {
12 
13 
18 template <typename T, int Dim = Eigen::Dynamic>
19 class CachingAccessor : public AccessorBase<T, Dim>
20 {
21 public:
22  friend class wmtk::Mesh;
23  friend class wmtk::TetMesh;
24  friend class wmtk::TriMesh;
25  using Scalar = T;
26 
28 
29  template <int D = Dim>
31  typename BaseType::template ConstMapResult<D>; // Eigen::Map<const VectorX<T>>
32  template <int D = Dim>
33  using MapResult = typename BaseType::template MapResult<D>; // Eigen::Map<VectorX<T>>
34 
35 
38 
40  CachingAccessor(const CachingAccessor&) = delete;
44 
45 
46  // returns the size of the underlying attribute
47 
48  //using BaseType::dimension; // const() -> int64_t
49  //using BaseType::reserved_size; // const() -> int64_t
50 
51  //using BaseType::attribute; // access to Attribute object being used here
52  //using BaseType::set_attribute; // (const vector<T>&) -> void
53  // shows the depth of scope stacks if they exist, mostly for debug
54  int64_t stack_depth() const;
55 
56  bool has_stack() const;
57 
58  template <int D = Dim>
59  ConstMapResult<D> const_vector_attribute(const int64_t index) const;
60 
61  T const_scalar_attribute(const int64_t index) const;
62  T const_scalar_attribute(const int64_t index, const int8_t offset) const;
63 
64  template <int D = Dim>
65  MapResult<D> vector_attribute(const int64_t index);
66 
67  T& scalar_attribute(const int64_t index);
68  T& scalar_attribute(const int64_t index, const int8_t offset);
69 
70  // deprecated because we should be more explicit in const/nonconst on internal interfaces
71  ConstMapResult<> vector_attribute(const int64_t index) const;
72  // deprecated because we should be more explicit in const/nonconst on internal interfaces
73  T scalar_attribute(const int64_t index) const;
74 
75  using BaseType::attribute;
76  using BaseType::mesh;
77 
78  bool writing_enabled() const;
79 
80 protected:
81  BaseType& base_type() { return *this; }
82  const BaseType& base_type() const { return *this; }
83 
84 private:
86 };
87 } // namespace wmtk::attribute
88 #include "CachingAccessor.hxx"
Attribute< T > & attribute()
An accessor for cached attribute values.
typename BaseType::template MapResult< D > MapResult
typename BaseType::template ConstMapResult< D > ConstMapResult
T const_scalar_attribute(const int64_t index) const
CachingAccessor(CachingAccessor &&)=default
const BaseType & base_type() const
CachingAccessor & operator=(const CachingAccessor &)=delete
MapResult< D > vector_attribute(const int64_t index)
T & scalar_attribute(const int64_t index)
CachingAccessor(Mesh &m, const TypedAttributeHandle< T > &handle)
internal::AttributeTransactionStack< T > & m_cache_stack
ConstMapResult< D > const_vector_attribute(const int64_t index) const
CachingAccessor & operator=(CachingAccessor &&)=default
CachingAccessor(const CachingAccessor &)=delete
Handle that represents attributes for some mesh.
Definition: Accessor.hpp:6