49 #ifndef OPENMESH_PROPERTYCONTAINER 50 #define OPENMESH_PROPERTYCONTAINER 54 #define OM_FORCE_STATIC_CAST 57 #include <OpenMesh/Core/Utils/Property.hh> 74 virtual ~
PropertyContainer() { std::for_each(properties_.begin(), properties_.end(), Delete()); }
79 typedef std::vector<BaseProperty*> Properties;
80 const Properties& properties()
const {
return properties_; }
81 size_t size()
const {
return properties_.size(); }
92 std::for_each(properties_.begin(), properties_.end(), Delete());
93 properties_ = _rhs.properties_;
94 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
95 for (; p_it!=p_end; ++p_it)
97 *p_it = (*p_it)->clone();
108 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
110 for ( ; p_it!=p_end && *p_it!=NULL; ++p_it, ++idx ) {};
111 if (p_it==p_end) properties_.push_back(NULL);
120 Properties::const_iterator p_it = properties_.begin();
121 for (
int idx=0; p_it != properties_.end(); ++p_it, ++idx)
124 (*p_it)->name() == _name
126 #ifndef OM_FORCE_STATIC_CAST 127 &&
dynamic_cast<PropertyT<T>*
>(properties_[idx]) != NULL
137 BaseProperty* property(
const std::string& _name )
const 139 Properties::const_iterator p_it = properties_.begin();
140 for (
int idx=0; p_it != properties_.end(); ++p_it, ++idx)
142 if (*p_it != NULL && (*p_it)->name() == _name)
152 assert(_h.
idx() >= 0 && _h.
idx() < (int)properties_.size());
153 assert(properties_[_h.
idx()] != NULL);
154 #ifdef OM_FORCE_STATIC_CAST 166 assert(_h.
idx() >= 0 && _h.
idx() < (int)properties_.size());
167 assert(properties_[_h.
idx()] != NULL);
168 #ifdef OM_FORCE_STATIC_CAST 180 assert(_h.
idx() >= 0 && _h.
idx() < (int)properties_.size());
181 delete properties_[_h.
idx()];
182 properties_[_h.
idx()] = NULL;
197 std::for_each(properties_.begin(), properties_.end(), ClearAll());
207 #if ((defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY) 211 void reserve(
size_t _n)
const {
212 std::for_each(properties_.begin(), properties_.end(),
219 void resize(
size_t _n)
const {
220 std::for_each(properties_.begin(), properties_.end(),
233 std::for_each(properties_.begin(), properties_.end(),
234 [_n](
BaseProperty* p) {
if (p && p->n_elements() < _n) p->resize(_n); });
241 void swap(
size_t _i0,
size_t _i1)
const {
242 std::for_each(properties_.begin(), properties_.end(),
243 [_i0, _i1](
BaseProperty* p) {
if (p) p->swap(_i0, _i1); });
250 std::for_each(properties_.begin(), properties_.end(), Reserve(_n));
257 std::for_each(properties_.begin(), properties_.end(), Resize(_n));
269 std::for_each(properties_.begin(), properties_.end(), ResizeIfSmaller(_n));
276 void swap(
size_t _i0,
size_t _i1)
const {
277 std::for_each(properties_.begin(), properties_.end(), Swap(_i0, _i1));
287 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
289 for (; p_it!=p_end && *p_it!=NULL; ++p_it, ++idx) {};
290 if (p_it==p_end) properties_.push_back(NULL);
291 properties_[idx] = _bp;
297 assert( _idx < properties_.size());
298 assert( properties_[_idx] != NULL);
306 assert( _idx < properties_.size());
307 assert( properties_[_idx] != NULL);
314 typedef Properties::iterator iterator;
315 typedef Properties::const_iterator const_iterator;
316 iterator begin() {
return properties_.begin(); }
317 iterator end() {
return properties_.end(); }
318 const_iterator begin()
const {
return properties_.begin(); }
319 const_iterator end()
const {
return properties_.end(); }
327 #ifndef DOXY_IGNORE_THIS 330 Reserve(
size_t _n) : n_(_n) {}
337 Resize(
size_t _n) : n_(_n) {}
342 struct ResizeIfSmaller
344 ResizeIfSmaller(
size_t _n) : n_(_n) {}
357 Swap(
size_t _i0,
size_t _i1) : i0_(_i0), i1_(_i1) {}
365 void operator()(
BaseProperty* _p)
const {
if (_p)
delete _p; _p=NULL; }
369 Properties properties_;
374 #endif//OPENMESH_PROPERTYCONTAINER void resize_if_smaller(size_t _n) const
Same as.
Definition: PropertyContainer.hh:268
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:276
Default property class for any type T.
Definition: Property.hh:94
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
This class provides low-level property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:102
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
A a container for properties.
Definition: PropertyContainer.hh:67
Base property handle.
Definition: Property.hh:471
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
virtual size_t n_elements() const =0
Number of elements in property.
void reserve(size_t _n) const
Reserves space for _n elements in all property vectors.
Definition: PropertyContainer.hh:249
virtual void clear()=0
Clear all elements and free memory.
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:65
void resize(size_t _n) const
Resizes all property vectors to the specified size.
Definition: PropertyContainer.hh:256
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
virtual void resize(size_t _n)=0
Resize storage to hold n elements.