46 #include "OpenVolumeMeshBaseProperty.hh" 48 #include "Serializers.hh" 65 template <
class PropT,
class HandleT>
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 OpenVolumeMeshPropertyT(
const std::string& _name =
"<unknown>",
const T &_def = T()) :
81 OpenVolumeMeshPropertyT(
const OpenVolumeMeshPropertyT& _rhs) =
default;
89 data_.resize(_n, def_);
93 vector_type().swap(data_);
96 data_.push_back(def_);
98 virtual void swap(
size_t _i0,
size_t _i1) {
99 std::swap(data_[_i0], data_[_i1]);
103 virtual void copy(
size_t _src_idx,
size_t _dst_idx) {
104 data_[_dst_idx] = data_[_src_idx];
107 data_.erase(data_.begin() + _idx);
120 #ifndef DOXY_IGNORE_THIS 122 size_t operator ()(
size_t _b,
const T& ) {
123 return _b +
sizeof(T);
131 return std::accumulate(data_.begin(), data_.end(), size_t(0), plus());
134 virtual size_t size_of(
size_t _n_elem)
const {
139 virtual void serialize(std::ostream& _ostr)
const {
140 for(
typename vector_type::const_iterator it = data_.begin();
141 it != data_.end(); ++it) {
142 OpenVolumeMesh::serialize(_ostr, *it) << std::endl;
147 virtual void deserialize(std::istream& _istr) {
148 for(
unsigned int i = 0; i <
n_elements(); ++i) {
149 OpenVolumeMesh::deserialize(_istr, data_[i]);
173 assert(_idx < data_.size());
179 assert(_idx < data_.size());
189 typename vector_type::const_iterator begin()
const {
return data_.begin(); }
191 typename vector_type::iterator begin() {
return data_.begin(); }
193 typename vector_type::const_iterator end()
const {
return data_.end(); }
195 typename vector_type::iterator end() {
return data_.end(); }
202 assert(_tags.size() == data_.size());
203 vector_type new_data;
204 typename vector_type::iterator d_it = data_.begin();
205 std::vector<bool>::const_iterator t_it = _tags.begin();
206 std::vector<bool>::const_iterator t_end = _tags.end();
207 for(; t_it != t_end; ++t_it, ++d_it) {
209 new_data.push_back(*d_it);
212 data_.swap(new_data);
234 auto tmp = data_[_i0];
235 data_[_i0] = data_[_i1];
242 return _n_elem / 8 + ((_n_elem % 8) != 0);
260 for(
unsigned int i = 0; i <
n_elements(); ++i) {
262 OpenVolumeMesh::deserialize(_istr, val);
280 return sizeof(data_);
const T * data() const
Get pointer to array (does not work for T==bool)
virtual void clear()
Clear all elements and free memory.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
void delete_element(size_t _idx)
Erase an element of the vector.
virtual size_t n_elements() const
Number of elements in property.
virtual void delete_multiple_entries(const std::vector< bool > &_tags)
Delete multiple entries in list.
OpenVolumeMeshPropertyT< T > * clone() const
Make a copy of self.
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Default property class for any type T.
const_reference operator[](size_t _idx) const
Const access to the i'th element. No range check is performed!
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash) ...
reference operator[](size_t _idx)
Access the i'th element. No range check is performed!
virtual size_t size_of(size_t _n_elem) const
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual size_t size_of() const
Return size of property in bytes.
virtual void reserve(size_t _n)
Reserve memory for n elements.
virtual void push_back()
Extend the number of elements by one.
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual size_t size_of() const
Return size of property in bytes.