14 auto& stack = get_local_scope_stack();
15 writer.
write(name, dim, dimension(), m_data, m_default_value);
22 , m_dimension(dimension)
23 , m_default_value(default_value)
26 assert(m_dimension > 0);
28 m_data = std::vector<T>(size * dimension, m_default_value);
38 std::map<std::string, size_t> hashes;
39 hashes[
"dimension"] = m_dimension;
40 if constexpr (std::is_same_v<T, Rational>) {
41 constexpr
static std::hash<std::string> h;
42 hashes[
"default_value"] = h(m_default_value.serialize());
44 hashes[
"default_value"] = m_default_value;
68 if (size > (m_data.size() / m_dimension)) {
69 m_data.resize(m_dimension * size, m_default_value);
75 return reserved_size(m_data);
80 return data.size() / m_dimension;
87 assert(val.size() % m_dimension == 0);
88 m_data = std::move(val);
93 for (int64_t i = 0; i < new2old.size(); ++i) {
94 vector_attribute(i) = vector_attribute(new2old[i]);
97 m_data.resize(new2old.size() * m_dimension);
100 #if defined(__GNUG__) && !defined(__clang__)
101 #pragma GCC diagnostic push
102 #pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
104 template <
typename T>
107 std::vector<Eigen::Index> indices(dimension());
108 std::iota(indices.begin(), indices.end(), Eigen::Index(0));
109 index_remap(old2new, indices);
112 template <
typename T>
115 if constexpr (std::is_same_v<T, int64_t>) {
116 for (int64_t i = 0; i < reserved_size(); ++i) {
117 auto vec = vector_attribute(i);
118 for (Eigen::Index idx : cols) {
119 int64_t& v = vec(idx);
125 throw std::runtime_error(
"Only int64_t attributes can be index remapped.");
128 #if defined(__GNUG__) && !defined(__clang__)
129 #pragma GCC diagnostic pop
virtual bool write(const int dim)=0
This class stores data of type T in a vector.
Attribute & operator=(Attribute &&o)
Attribute(const std::string &name, int64_t dimension, T default_value=T(0), int64_t size=0)
Initialize the attribute.
void index_remap(const std::vector< T > &old2new)
Applies the scalar old2new map to the indices in the attribute This is commonly used after a consolid...
bool operator==(const Attribute< T > &o) const
void serialize(const std::string &name, const int dim, MeshWriter &writer) const
void reserve(const int64_t size)
void consolidate(const std::vector< int64_t > &new2old)
Consolidate the vector, using the new2old map m provided and resizing the vector to m....
int64_t reserved_size() const
The total number of elements in a vector.
void set(std::vector< T > val)
Replace the internal data with val.
std::map< std::string, size_t > child_hashes() const override
std::size_t vector_hash(const std::vector< size_t > &data)