14#include "PyAttribute.h"
16#include <lagrange/Attribute.h>
17#include <lagrange/IndexedAttribute.h>
18#include <lagrange/utils/Error.h>
19#include <lagrange/internal/weak_ptr.h>
23namespace lagrange::python {
37 auto attr = m_attr.lock();
38 if (attr ==
nullptr)
throw Error(
"Indexed attribute is no longer valid!");
42 template <
typename CallBack>
43 auto process(CallBack&& cb)
45 auto attr = m_attr.lock();
46 if (attr ==
nullptr)
throw Error(
"Indexed attribute is no longer valid!");
47 if (attr->get_element_type() !=
Indexed)
48 throw Error(
"Attribute is not an indexed attribute");
50#define LA_X_process(Index, ValueType) \
52 auto indexed_attr = dynamic_cast<IndexedAttribute<ValueType, Index>*>(attr.get()); \
53 if (indexed_attr != nullptr) { \
54 return cb(*indexed_attr); \
57#define LA_X_process_index(_, Index) LA_ATTRIBUTE_X(process, Index)
59#undef LA_X_process_index
61 throw Error(
"Cannot process indexed attribute with unsupported types!");
66 return process([&](
auto& indexed_attr) {
67 auto attr = m_attr.lock();
69 auto& value_attr = indexed_attr.values();
77 return process([&](
auto& indexed_attr) {
78 auto attr = m_attr.lock();
80 auto& index_attr = indexed_attr.indices();
NOT implemented: custom allocator support.
Definition: shared_ptr.h:110
Definition: weak_ptr.h:26
Definition: PyAttribute.h:24
Definition: PyIndexedAttribute.h:26
@ Indexed
Indexed mesh attributes.
Definition: AttributeFwd.h:45
#define LA_SURFACE_MESH_INDEX_X(mode, data)
X Macro arguments to iterate over index types available for the SurfaceMesh<> class.
Definition: SurfaceMeshTypes.h:71
#define la_debug_assert(...)
Debug assertion check.
Definition: assert.h:189
Base exception for errors thrown by Lagrange functions.
Definition: Error.h:27