3#include <wmtk/utils/VectorUtils.h>
4#include <wmtk/utils/Logger.hpp>
6#include <wmtk/threading/enumerable_thread_specific.hpp>
13#include <unordered_map>
25 virtual void move(
size_t from,
size_t to) {};
26 virtual void resize(
size_t) = 0;
27 virtual void clear() = 0;
28 virtual void rollback() = 0;
29 virtual void begin_protect() = 0;
30 virtual void end_protect() = 0;
37 void move(
size_t from,
size_t to)
override
39 if (from == to)
return;
40 m_attributes[to] = std::move(m_attributes[from]);
47 void resize(
size_t s)
override
49 if (s > m_attributes.size()) m_attributes.resize(s);
51 void clear()
override { m_attributes.clear(); }
53 bool assign(
size_t to, T&& val)
55 m_attributes[to] = val;
56 if (recording.local()) m_rollback_list.local()[to] = val;
66 for (
auto& [i, v] : m_rollback_list.local()) {
67 m_attributes[i] = std::move(v);
77 m_rollback_list.local().clear();
78 recording.local() =
true;
86 m_rollback_list.local().clear();
87 recording.local() =
false;
90 const T& at(
size_t i)
const {
return m_attributes[i]; }
92 const T& operator[](
size_t i)
const {
return at(i); }
94 T& operator[](
size_t i)
96 if (recording.local()) {
97 m_rollback_list.local().emplace(i, m_attributes[i]);
99 return m_attributes[i];
103 size_t size()
const {
return m_attributes.size(); }
106 std::vector<T> m_attributes;
136 void move(
size_t from,
size_t to)
override
138 for (
auto* c : m_children) c->move(from, to);
140 void resize(
size_t s)
override
142 for (
auto* c : m_children) c->resize(s);
144 void clear()
override
146 for (
auto* c : m_children) c->clear();
148 void rollback()
override
150 for (
auto* c : m_children) c->rollback();
152 void begin_protect()
override
154 for (
auto* c : m_children) c->begin_protect();
156 void end_protect()
override
158 for (
auto* c : m_children) c->end_protect();
162 std::vector<AbstractAttributeContainer*> m_children;
serving as buffers for attributes data that can be modified by operations
Definition AttributeCollection.hpp:22
Several attribute collections for the same simplex type, behind one container.
Definition AttributeCollection.hpp:132
Definition enumerable_thread_specific.hpp:26
Definition AttributeCollection.hpp:36
void rollback() override
retrieve the protected attribute data on operation-fail
Definition AttributeCollection.hpp:64
void end_protect() override
clear local buffers and finish recording
Definition AttributeCollection.hpp:84
void begin_protect() override
clean local buffers for attribute, and start recording
Definition AttributeCollection.hpp:75