23 std::vector<std::string> attribute_names;
27 std::back_inserter(attribute_names),
28 [](
const auto& ptr) -> std::string {
36 attribute_names.erase(
38 attribute_names.begin(),
39 attribute_names.end(),
40 [](
const std::string& name) { return name.empty(); }),
41 attribute_names.end());
44 if (hdf5_w !=
nullptr) {
48 for (
const auto& attr_ptr : m_attributes) {
50 attr_ptr->serialize(dim, writer);
61 for (int64_t i = 0; i < m_attributes.size(); ++i) {
62 if (!m_attributes[i]) {
65 const std::string& name = m_attributes[i]->name();
67 ret[
"attr_handle_" + name] = std::hash<AttributeHandle>{}(handle);
77 std::map<std::string, const wmtk::utils::Hashable*> ret;
79 for (int64_t i = 0; i < m_attributes.size(); ++i) {
80 if (!m_attributes[i]) {
83 const std::string& name = m_attributes[i]->name();
85 const auto& attr = attribute(handle);
87 ret[
"attr_" + name] = &attr;
96 for (
auto& attr_ptr : m_attributes) {
105 for (
auto& attr_ptr : m_attributes) {
106 if (
bool(attr_ptr)) {
114 for (
auto& attr_ptr : m_attributes) {
115 if (
bool(attr_ptr)) {
123 for (
const auto& attr_ptr : m_attributes) {
124 if (
bool(attr_ptr)) {
125 attr_ptr->change_to_next_scope();
133 for (
const auto& attr_ptr : m_attributes) {
134 if (
bool(attr_ptr)) {
135 attr_ptr->change_to_previous_scope();
142 const std::string& name,
147 if (!replace && has_attribute(name)) {
149 "Cannot register attribute '{}' because it exists already. Set replace to true if you "
150 "want to overwrite the attribute",
155 for (int64_t i = 0; i < m_attributes.size(); ++i) {
156 if (!m_attributes[i]) {
159 if (m_attributes[i]->name() == name) {
166 m_attributes.emplace_back(
175 for (
const auto& a : m_attributes) {
177 assert(a->reserved_size() >= cap);
184 for (int64_t i = 0; i < m_attributes.size(); ++i) {
185 if (!m_attributes[i]) {
188 if (m_attributes[i]->name() == name) {
198 for (int64_t i = 0; i < m_attributes.size(); ++i) {
199 if (!m_attributes[i]) {
202 if (m_attributes[i]->name() == name) {
216 for (
size_t j = 0; j < m_attributes.size(); ++j) {
217 const bool exists = bool(m_attributes[j]);
219 if (exists != o_exists) {
221 }
else if (exists && o_exists && !(*m_attributes[j] == *other.
m_attributes[j])) {
233 auto& attr_ptr = m_attributes[handle.
index()];
234 assert(
bool(attr_ptr));
235 auto& attr = *attr_ptr;
236 attr.set(std::move(val));
242 auto& attr_ptr = m_attributes[handle.
index()];
243 assert(
bool(attr_ptr));
244 return attr_ptr->reserved_size();
250 return m_reserved_size;
256 return active_attributes().size();
261 std::vector<AttributeHandle> handles;
262 handles.reserve(m_attributes.size());
263 for (
size_t j = 0; j < m_attributes.size(); ++j) {
264 if (
bool(m_attributes[j])) {
274 const size_t index = h.
index();
275 assert(index < m_attributes.size());
276 return bool(m_attributes[index]);
282 m_reserved_size = size;
283 for (
auto& attr_ptr : m_attributes) {
284 if (
bool(attr_ptr)) {
293 reserve(m_reserved_size + size);
299 if (size > m_reserved_size) {
317 auto& attr = m_attributes[attribute.
index()];
319 logger().warn(
"Attribute was already deleted.");
323 m_attributes[attribute.
index()].reset();
329 if (handle.
index() >= m_attributes.size()) {
330 logger().warn(
"Handle index is larger than the attribute vector");
334 if (!m_attributes[handle.
index()]) {
344 size_t old_index = 0;
345 size_t new_index = 0;
346 std::vector<int64_t> old_to_new_id(m_attributes.size(), -1);
347 for (old_index = 0; old_index < m_attributes.size(); ++old_index) {
348 if (
bool(m_attributes[old_index])) {
349 old_to_new_id[old_index] = new_index;
350 m_attributes[new_index++] = std::move(m_attributes[old_index]);
353 m_attributes.resize(new_index);
358 assert(handle.
index() < m_attributes.size());
359 if (m_attributes[handle.
index()]) {
360 return m_attributes[handle.
index()]->name();
362 throw std::runtime_error(
"Could not find handle in TypedAttributeManager");
369 const std::string old_name = get_name(handle);
371 if (old_name == name) {
375 auto& attr = m_attributes[handle.
index()];
377 assert(attr->name() == old_name);
379 assert(!has_attribute(name));
381 attr->set_name(name);
void write_attribute_names(int dim, const std::vector< std::string > &names)
Internal handle representation used by TypedAttributeManager.
int64_t index() const noexcept
Contains all attributes of type T for a single mesh.
void reserve(const int64_t size)
void pop_scope(bool apply_updates=true)
void rollback_current_scope()
std::vector< std::unique_ptr< CachingAttribute< T > > > m_attributes
void serialize(const int dim, MeshWriter &writer) const
std::map< std::string, std::size_t > child_hashes() const override
void log_and_throw_error(const std::string &msg)
spdlog::logger & logger()
Retrieves the current logger.