46 #include "OpenVolumeMeshBaseProperty.hh" 48 #include "Serializers.hh" 62 class OpenVolumeMeshPropertyT:
public OpenVolumeMeshBaseProperty {
65 template <
class PropT,
class Entity>
friend class PropertyPtr;
68 typedef std::vector<T> vector_type;
70 typedef typename vector_type::reference reference;
71 typedef typename vector_type::const_reference const_reference;
75 explicit OpenVolumeMeshPropertyT(
76 const std::string& _name,
77 const std::string& _internal_type_name,
79 : OpenVolumeMeshBaseProperty(_name, _internal_type_name),
84 OpenVolumeMeshPropertyT(
const OpenVolumeMeshPropertyT& _rhs) =
default;
92 data_.resize(_n, def_);
94 size_t size()
const override {
99 vector_type().swap(data_);
102 data_.push_back(def_);
104 void swap(
size_t _i0,
size_t _i1)
override {
105 std::swap(data_[_i0], data_[_i1]);
108 virtual void copy(
size_t _src_idx,
size_t _dst_idx) {
109 data_[_dst_idx] = data_[_src_idx];
112 data_.erase(data_.begin() + _idx);
125 #ifndef DOXY_IGNORE_THIS 127 size_t operator ()(
size_t _b,
const T& ) {
128 return _b +
sizeof(T);
136 return std::accumulate(data_.begin(), data_.end(), size_t(0), plus());
139 size_t size_of(
size_t _n_elem)
const override {
144 void serialize(std::ostream& _ostr)
const override {
145 for(
typename vector_type::const_iterator it = data_.begin();
146 it != data_.end(); ++it) {
147 OpenVolumeMesh::serialize(_ostr, *it) << std::endl;
152 void deserialize(std::istream& _istr)
override {
153 for(
unsigned int i = 0; i <
n_elements(); ++i) {
154 OpenVolumeMesh::deserialize(_istr, data_[i]);
178 assert(_idx < data_.size());
184 assert(_idx < data_.size());
194 typename vector_type::const_iterator begin()
const {
return data_.begin(); }
196 typename vector_type::iterator begin() {
return data_.begin(); }
198 typename vector_type::const_iterator end()
const {
return data_.end(); }
200 typename vector_type::iterator end() {
return data_.end(); }
207 assert(_tags.size() == data_.size());
208 vector_type new_data;
209 typename vector_type::iterator d_it = data_.begin();
210 std::vector<bool>::const_iterator t_it = _tags.begin();
211 std::vector<bool>::const_iterator t_end = _tags.end();
212 for(; t_it != t_end; ++t_it, ++d_it) {
214 new_data.push_back(*d_it);
217 data_.swap(new_data);
239 auto tmp = data_[_i0];
240 data_[_i0] = data_[_i1];
247 return _n_elem / 8 + ((_n_elem % 8) != 0);
265 for(
unsigned int i = 0; i <
n_elements(); ++i) {
267 OpenVolumeMesh::deserialize(_istr, val);
285 return sizeof(data_);
void clear() override
Clear all elements and free memory.
size_t n_elements() const override
Number of elements in property.
void delete_element(size_t _idx) override
Erase an element of the vector.
void reserve(size_t _n) override
Reserve memory for n elements.
void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
OpenVolumeMeshPropertyT< T > * clone() const override
Make a copy of self.
size_t size() const override
Return underlying container size.
Default property class for any type T.
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash) ...
size_t size_of(size_t _n_elem) const override
size_t size_of() const override
Return size of property in bytes.
void resize(size_t _n) override
Resize storage to hold n elements.
void delete_multiple_entries(const std::vector< bool > &_tags) override
Delete multiple entries in list.
reference operator[](size_t _idx)
Access the i'th element. No range check is performed!
size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
void push_back() override
Extend the number of elements by one.
virtual size_t size_of() const
Return size of property in bytes.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
const_reference operator[](size_t _idx) const
Const access to the i'th element. No range check is performed!
const T * data() const
Get pointer to array (does not work for T==bool)