33 if (m_indices_end + 1 >= m_indices.size()) {
34 assert(m_indices.size() > 2);
35 m_indices.resize(m_indices.size() * 1.75);
38 if (m_buffer_end + data_size >= m_buffer.size()) {
39 assert(m_buffer.size() > 2);
40 m_buffer.resize(m_buffer.size() * 1.75);
45 template <
typename Derived>
48 const Eigen::MatrixBase<Derived>& value)
52 size_t dim = value.size();
55 update_buffer_sizes_for_add(dim);
60 m_indices[m_indices_end] = {index, m_buffer_end};
63 assert(m_buffer.size() >= m_buffer_end + dim);
65 std::copy(value.begin(), value.end(), m_buffer.begin() + m_buffer_end);
68 assert(m_buffer_end == m_indices_end * dim);
74 update_buffer_sizes_for_add(1);
76 m_indices[m_indices_end] = {index, m_buffer_end};
77 m_buffer[m_buffer_end] = value;
81 assert(m_buffer_end == m_indices_end);
88 apply_to(attribute, attribute.
m_data);
94 std::vector<T>& other)
const
96 assert(at_current_scope());
97 for (
auto it = final_transaction_rbegin();
98 it != transaction_start_rend(current_transaction_index() - 1);
100 const auto& [global, local] = *it;
107 template <
typename T>
110 for (
auto it = transaction_start_begin(current_transaction_index());
111 it != final_transaction_end();
113 const auto& [global_index, local_index] = *it;
114 if (global_index == index) {
115 const T* ptr = m_buffer.data() + local_index;
122 template <
typename T>
125 assert(at_current_scope());
127 m_transaction_starts.emplace_back(m_indices_end);
128 change_to_current_scope();
130 template <
typename T>
133 assert(at_current_scope());
135 if (preserve_changes) {
142 m_transaction_starts.pop_back();
144 change_to_current_scope();
152 template <
typename T>
155 return m_transaction_starts.empty();
159 template <
typename T>
162 assert(at_current_scope());
167 template <
typename T>
171 assert(!at_current_scope());
172 m_current_transaction_index++;
175 template <
typename T>
178 if (at_current_scope()) {
181 m_current_transaction_index--;
183 template <
typename T>
186 m_current_transaction_index = m_transaction_starts.size();
188 template <
typename T>
191 assert(m_current_transaction_index <= m_transaction_starts.size());
192 return m_current_transaction_index == m_transaction_starts.size();
194 template <
typename T>
197 return at_current_scope();
This class stores data of type T in a vector.
MapResult< D > vector_attribute(const int64_t index)
ConstMapResult< D > const_vector_attribute_from_start(const int64_t index, const std::vector< T > &data) const
Accesses the attribute using the specified vector as the underlying data This is internally used by t...
void update_buffer_sizes_for_add(size_t data_size)
void pop(Attribute< T > &attribute, bool preserve_changes)
void change_to_previous_scope()
bool at_current_scope() const
checks that we are viewing the active state of the attribute
void change_to_current_scope()
void try_caching(int64_t index, const Eigen::MatrixBase< Derived > &value)
bool writing_enabled() const
~AttributeTransactionStack()
AttributeTransactionStack()
void apply_to(Attribute< T > &attribute) const
void apply_last_scope(Attribute< T > &attr)
void change_to_next_scope()
const T * get_value(int64_t index) const