43 #ifndef OPENVOLUMEMESHPROPERTY_HH
44 #define OPENVOLUMEMESHPROPERTY_HH
55 #include "OpenVolumeMeshBaseProperty.hh"
57 #include "Serializers.hh"
74 template <
class PropT,
class HandleT>
friend class PropertyPtr;
77 typedef std::vector<T> vector_type;
79 typedef typename vector_type::reference reference;
80 typedef typename vector_type::const_reference const_reference;
103 data_.resize(_n, def_);
107 vector_type().swap(data_);
110 data_.push_back(def_);
112 virtual void swap(
size_t _i0,
size_t _i1) {
113 std::swap(data_[_i0], data_[_i1]);
117 data_.erase(data_.begin() + _idx);
129 #ifndef DOXY_IGNORE_THIS
131 size_t operator ()(
size_t _b,
const T& ) {
132 return _b +
sizeof(T);
140 return std::accumulate(data_.begin(), data_.end(), 0, plus());
143 virtual size_t size_of(
size_t _n_elem)
const {
148 virtual void serialize(std::ostream& _ostr)
const {
149 for(
typename vector_type::const_iterator it = data_.begin();
150 it != data_.end(); ++it) {
151 OpenVolumeMesh::serialize(_ostr, *it) << std::endl;
156 virtual void deserialize(std::istream& _istr) {
157 for(
unsigned int i = 0; i <
n_elements(); ++i) {
158 OpenVolumeMesh::deserialize(_istr, data_[i]);
182 assert(
size_t(_idx) < data_.size());
188 assert(
size_t(_idx) < data_.size());
198 typename vector_type::const_iterator begin()
const {
return data_.begin(); }
200 typename vector_type::iterator begin() {
return data_.begin(); }
202 typename vector_type::const_iterator end()
const {
return data_.end(); }
204 typename vector_type::iterator end() {
return data_.end(); }
211 assert(_tags.size() == data_.size());
212 vector_type new_data;
213 typename vector_type::iterator d_it = data_.begin();
214 std::vector<bool>::const_iterator t_it = _tags.begin();
215 std::vector<bool>::const_iterator t_end = _tags.end();
216 for(; t_it != t_end; ++t_it, ++d_it) {
218 new_data.push_back(*d_it);
221 data_.swap(new_data);
241 template <
class PropT,
class HandleT>
friend class PropertyPtr;
243 typedef std::vector<bool> vector_type;
244 typedef bool value_type;
245 typedef vector_type::reference reference;
246 typedef vector_type::const_reference const_reference;
262 data_.resize(_n, def_);
266 vector_type().swap(data_);
269 data_.push_back(def_);
271 virtual void swap(
size_t _i0,
size_t _i1) {
273 data_[_i0] = data_[_i1];
278 data_.erase(data_.begin() + _idx);
292 virtual size_t size_of(
size_t _n_elem)
const {
293 return _n_elem / 8 + ((_n_elem % 8) != 0);
297 virtual void serialize(std::ostream& _ostr)
const {
298 for(vector_type::const_iterator it = data_.begin();
299 it != data_.end(); ++it) {
300 OpenVolumeMesh::serialize(_ostr, *it) << std::endl;
305 virtual void deserialize(std::istream& _istr) {
306 for(
unsigned int i = 0; i <
n_elements(); ++i) {
308 OpenVolumeMesh::deserialize(_istr, val);
317 assert(
size_t(_idx) < data_.size());
323 assert(
size_t(_idx) < data_.size());
334 vector_type::const_iterator begin()
const {
return data_.begin(); }
336 vector_type::iterator begin() {
return data_.begin(); }
338 vector_type::const_iterator end()
const {
return data_.end(); }
340 vector_type::iterator end() {
return data_.end(); }
347 assert(_tags.size() == data_.size());
348 vector_type new_data;
349 vector_type::iterator d_it = data_.begin();
350 std::vector<bool>::const_iterator t_it = _tags.begin();
351 std::vector<bool>::const_iterator t_end = _tags.end();
352 for(; t_it != t_end; ++t_it, ++d_it) {
354 new_data.push_back(*d_it);
357 data_.swap(new_data);
377 template <
class PropT,
class HandleT>
friend class PropertyPtr;
379 typedef std::string Value;
380 typedef std::vector<std::string> vector_type;
381 typedef std::string value_type;
382 typedef vector_type::reference reference;
383 typedef vector_type::const_reference const_reference;
399 data_.resize(_n, def_);
403 vector_type().swap(data_);
406 data_.push_back(def_);
408 virtual void swap(
size_t _i0,
size_t _i1) {
409 std::swap(data_[_i0], data_[_i1]);
413 data_.erase(data_.begin() + _idx);
425 return sizeof(data_);
432 virtual void stats(std::ostream& _ostr)
const {
433 for(vector_type::const_iterator it = data_.begin();
434 it != data_.end(); ++it) {
440 virtual void serialize(std::ostream& _ostr)
const {
441 for(vector_type::const_iterator it = data_.begin();
442 it != data_.end(); ++it) {
443 OpenVolumeMesh::serialize(_ostr, *it) << std::endl;
448 virtual void deserialize(std::istream& _istr) {
449 for(
unsigned int i = 0; i <
n_elements(); ++i) {
450 OpenVolumeMesh::deserialize(_istr, data_[i]);
456 const value_type*
data()
const {
460 return (value_type*) &data_[0];
465 assert(
size_t(_idx) < data_.size());
466 return ((value_type*) &data_[0])[_idx];
471 assert(
size_t(_idx) < data_.size());
472 return ((value_type*) &data_[0])[_idx];
481 vector_type::const_iterator begin()
const {
return data_.begin(); }
483 vector_type::iterator begin() {
return data_.begin(); }
485 vector_type::const_iterator end()
const {
return data_.end(); }
487 vector_type::iterator end() {
return data_.end(); }
494 assert(_tags.size() == data_.size());
495 vector_type new_data;
496 vector_type::iterator d_it = data_.begin();
497 std::vector<bool>::const_iterator t_it = _tags.begin();
498 std::vector<bool>::const_iterator t_end = _tags.end();
499 for(; t_it != t_end; ++t_it, ++d_it) {
501 new_data.push_back(*d_it);
504 data_.swap(new_data);
511 const std::string def_;
517 #endif // OPENVOLUMEMESHPROPERTY_HH defined
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual size_t size_of(size_t _n_elem) const
void delete_element(size_t _idx)
Erase an element of the vector.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
virtual void clear()
Clear all elements and free memory.
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
virtual void clear()
Clear all elements and free memory.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
virtual size_t size_of() const
Return size of property in bytes.
void delete_element(size_t _idx)
Erase an element of the vector.
virtual void delete_multiple_entries(const std::vector< bool > &_tags)
Delete multiple entries in list.
virtual size_t size_of(size_t _n_elem) const
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
virtual void push_back()
Extend the number of elements by one.
virtual size_t size_of() const
Return size of property in bytes.
OpenVolumeMeshPropertyT< value_type > * clone() const
Return a deep copy of self.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
virtual size_t size_of(size_t) const
virtual size_t n_elements() const
Number of elements in property.
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash) ...
const T * data() const
Get pointer to array (does not work for T==bool)
virtual void reserve(size_t _n)
Reserve memory for n elements.
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
OpenVolumeMeshPropertyT< bool > * clone() const
Make a copy of self.
virtual void reserve(size_t _n)
Reserve memory for n elements.
virtual size_t size_of() const
Return size of property in bytes.
virtual void reserve(size_t _n)
Reserve memory for n elements.
virtual size_t n_elements() const
Number of elements in property.
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual void delete_multiple_entries(const std::vector< bool > &_tags)
Delete multiple entries in list.
virtual void push_back()
Extend the number of elements by one.
Default property class for any type T.
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
virtual void clear()
Clear all elements and free memory.
virtual size_t size_of() const
Return size of property in bytes.
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
OpenVolumeMeshPropertyT< T > * clone() const
Make a copy of self.
OpenVolumeMeshPropertyT(const OpenVolumeMeshPropertyT &_rhs)
Copy constructor.
OpenVolumeMeshPropertyT(const std::string &_name="<unknown>", const T _def=T())
Default constructor.
virtual size_t n_elements() const
Number of elements in property.
virtual void push_back()
Extend the number of elements by one.
virtual void delete_multiple_entries(const std::vector< bool > &_tags)
Delete multiple entries in list.
virtual void delete_element(size_t _idx)
Erase an element of the vector.