44 #ifndef OPENMESH_PROPERTYCONTAINER
45 #define OPENMESH_PROPERTYCONTAINER
47 #include <OpenMesh/Core/Utils/Property.hh>
48 #include <OpenMesh/Core/Utils/typename.hh>
65 virtual ~
PropertyContainer() { std::for_each(properties_.begin(), properties_.end(), Delete()); }
70 typedef std::vector<BaseProperty*> Properties;
71 const Properties& properties()
const {
return properties_; }
72 size_t size()
const {
return properties_.size(); }
83 std::for_each(properties_.begin(), properties_.end(), Delete());
84 properties_ = _rhs.properties_;
85 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
86 for (; p_it!=p_end; ++p_it)
88 *p_it = (*p_it)->clone();
99 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
101 for ( ; p_it!=p_end && *p_it!=
nullptr; ++p_it, ++idx ) {};
102 if (p_it==p_end) properties_.push_back(
nullptr);
103 properties_[idx] =
new PropertyT<T>(_name, get_type_name<T>() );
111 Properties::const_iterator p_it = properties_.begin();
112 for (
int idx=0; p_it != properties_.end(); ++p_it, ++idx)
114 if (*p_it !=
nullptr &&
115 (*p_it)->name() == _name
116 && (*p_it)->internal_type_name() == get_type_name<T>()
125 BaseProperty* property(
const std::string& _name )
const
127 Properties::const_iterator p_it = properties_.begin();
128 for (
int idx=0; p_it != properties_.end(); ++p_it, ++idx)
130 if (*p_it !=
nullptr && (*p_it)->name() == _name)
140 assert(_h.
idx() >= 0 && _h.
idx() < (
int)properties_.size());
141 assert(properties_[_h.
idx()] !=
nullptr);
142 assert( properties_[_h.
idx()]->internal_type_name() == get_type_name<T>() );
144 assert(p !=
nullptr);
151 assert(_h.
idx() >= 0 && _h.
idx() < (
int)properties_.size());
152 assert(properties_[_h.
idx()] !=
nullptr);
153 assert( properties_[_h.
idx()]->internal_type_name() == get_type_name<T>() );
155 assert(p !=
nullptr);
162 assert(_h.
idx() >= 0 && _h.
idx() < (
int)properties_.size());
163 delete properties_[_h.
idx()];
164 properties_[_h.
idx()] =
nullptr;
179 std::for_each(properties_.begin(), properties_.end(), ClearAll());
189 #if ((defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
193 void reserve(
size_t _n)
const {
194 std::for_each(properties_.begin(), properties_.end(),
201 void resize(
size_t _n)
const {
202 std::for_each(properties_.begin(), properties_.end(),
215 std::for_each(properties_.begin(), properties_.end(),
216 [_n](
BaseProperty* p) { if (p && p->n_elements() < _n) p->resize(_n); });
223 void swap(
size_t _i0,
size_t _i1)
const {
224 std::for_each(properties_.begin(), properties_.end(),
225 [_i0, _i1](
BaseProperty* p) { if (p) p->swap(_i0, _i1); });
232 std::for_each(properties_.begin(), properties_.end(), Reserve(_n));
239 std::for_each(properties_.begin(), properties_.end(), Resize(_n));
251 std::for_each(properties_.begin(), properties_.end(), ResizeIfSmaller(_n));
258 void swap(
size_t _i0,
size_t _i1)
const {
259 std::for_each(properties_.begin(), properties_.end(), Swap(_i0, _i1));
269 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
271 for (; p_it!=p_end && *p_it!=
nullptr; ++p_it, ++idx) {};
272 if (p_it==p_end) properties_.push_back(
nullptr);
273 properties_[idx] = _bp;
277 BaseProperty& _property(
size_t _idx )
279 assert( _idx < properties_.size());
280 assert( properties_[_idx] !=
nullptr);
281 BaseProperty *p = properties_[_idx];
282 assert( p !=
nullptr );
286 const BaseProperty& _property(
size_t _idx )
const
288 assert( _idx < properties_.size());
289 assert( properties_[_idx] !=
nullptr);
290 BaseProperty *p = properties_[_idx];
291 assert( p !=
nullptr );
296 typedef Properties::iterator iterator;
297 typedef Properties::const_iterator const_iterator;
298 iterator begin() {
return properties_.begin(); }
299 iterator end() {
return properties_.end(); }
300 const_iterator begin()
const {
return properties_.begin(); }
301 const_iterator end()
const {
return properties_.end(); }
303 friend class BaseKernel;
309 #ifndef DOXY_IGNORE_THIS
312 explicit Reserve(
size_t _n) : n_(_n) {}
313 void operator()(BaseProperty* _p)
const {
if (_p) _p->reserve(n_); }
319 explicit Resize(
size_t _n) : n_(_n) {}
320 void operator()(BaseProperty* _p)
const {
if (_p) _p->resize(n_); }
324 struct ResizeIfSmaller
326 explicit ResizeIfSmaller(
size_t _n) : n_(_n) {}
327 void operator()(BaseProperty* _p)
const {
if (_p && _p->n_elements() < n_) _p->resize(n_); }
334 void operator()(BaseProperty* _p)
const {
if (_p) _p->clear(); }
339 Swap(
size_t _i0,
size_t _i1) : i0_(_i0), i1_(_i1) {}
340 void operator()(BaseProperty* _p)
const {
if (_p) _p->swap(i0_, i1_); }
347 void operator()(BaseProperty* _p)
const {
if (_p)
delete _p; }
351 Properties properties_;
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:69
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:61
Default property class for any type T.
Definition: Property.hh:93
Base property handle.
Definition: Property.hh:401
A a container for properties.
Definition: PropertyContainer.hh:59
void reserve(size_t _n) const
Reserves space for _n elements in all property vectors.
Definition: PropertyContainer.hh:231
void resize_if_smaller(size_t _n) const
Same as.
Definition: PropertyContainer.hh:250
void swap(size_t _i0, size_t _i1) const
Swaps the items with index _i0 and index _i1 in all property vectors.
Definition: PropertyContainer.hh:258
void resize(size_t _n) const
Resizes all property vectors to the specified size.
Definition: PropertyContainer.hh:238