FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
attribute_set.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
11
12// includes, system
13#include <vector>
14
15namespace FEAT
16{
17 namespace Geometry
18 {
30 template<typename DataType_>
32 {
33 public:
36 typedef DataType_ DataType;
37
38 protected:
44 std::vector<DataType> _values;
45
46 public:
56 explicit AttributeSet(Index num_values, int dimension = 1) :
57 _num_values(num_values),
58 _dimension(dimension)
59 {
60 XASSERT((dimension > 0) || (num_values == Index(0)));
61 if(num_values > Index(0))
62 {
63 _values.resize(std::size_t(num_values) * std::size_t(dimension));
64 }
65 }
66
71 _values(std::forward<std::vector<DataType>>(other._values))
72 {
73 }
74
77 {
78 // avoid self-move
79 if(this == &other)
80 return *this;
81
82 _num_values = other._num_values;
83 _dimension = other._dimension;
84 _values = std::forward<std::vector<DataType>>(other._values);
85
86 return *this;
87 }
88
90 virtual ~AttributeSet()
91 {
92 }
93
94 void clone(const AttributeSet& other)
95 {
96 this->_num_values = other._num_values;
97 this->_dimension = other._dimension;
98 this->_values = other._values;
99 }
100
101 AttributeSet clone() const
102 {
103 AttributeSet ats(this->_num_values, this->_dimension);
104 ats._values = this->_values;
105 return ats;
106 }
107
109 std::size_t bytes() const
110 {
111 return _values.size() * std::size_t(_dimension) * sizeof(DataType);
112 }
113
119 int get_dimension() const
120 {
121 return _dimension;
122 }
123
126 {
127 return _num_values;
128 }
129
143 {
144 ASSERT(i < _num_values);
145 ASSERT((j >= 0) && (j < _dimension));
146 return _values[std::size_t(i)*std::size_t(_dimension) + std::size_t(j)];
147 }
148
161 const DataType& operator()(Index i, int j) const
162 {
163 ASSERT(i < _num_values);
164 ASSERT((j >= 0) && (j < _dimension));
165 return _values[std::size_t(i)*std::size_t(_dimension) + std::size_t(j)];
166 }
167
169 // interpret attribute i as raw array and return pointer
170 DataType* raw_at(Index i)
171 {
172 ASSERT(i < _num_values);
173 return &_values.data()[std::size_t(i)*std::size_t(_dimension)];
174 }
175
176 const DataType* raw_at(Index i) const
177 {
178 ASSERT(i < _num_values);
179 return &_values.data()[std::size_t(i)*std::size_t(_dimension)];
180 }
182
184 static String name()
185 {
186 return "AttributeSet<...>";
187 }
188 }; // class AttributeSet<...>
189 } // namespace Geometry
190} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
Container for saving data related to mesh entities.
Index get_num_values() const
Returns the number of attribute values.
AttributeSet & operator=(AttributeSet &&other)
move-assignment operator
AttributeSet(Index num_values, int dimension=1)
Constructor.
std::vector< DataType > _values
Value array.
static String name()
Returns the name of the class.
int get_dimension() const
Returns the number attribute dimension.
Index _num_values
Number of attribute values.
int _dimension
Number of entries per attribute value.
const DataType & operator()(Index i, int j) const
Returns a const reference to an attribute value entry.
AttributeSet(AttributeSet &&other)
move constructor
DataType & operator()(Index i, int j)
Returns a reference to an attribute value entry.
virtual ~AttributeSet()
virtual destructor
String class implementation.
Definition: string.hpp:46
@ other
generic/other permutation strategy
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.