44 #ifndef OPENMESH_PROPERTYCONTAINER 45 #define OPENMESH_PROPERTYCONTAINER 49 #define OM_FORCE_STATIC_CAST 52 #include <OpenMesh/Core/Utils/Property.hh> 69 virtual ~
PropertyContainer() { std::for_each(properties_.begin(), properties_.end(), Delete()); }
74 typedef std::vector<BaseProperty*> Properties;
75 const Properties& properties()
const {
return properties_; }
76 size_t size()
const {
return properties_.size(); }
87 std::for_each(properties_.begin(), properties_.end(), Delete());
88 properties_ = _rhs.properties_;
89 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
90 for (; p_it!=p_end; ++p_it)
92 *p_it = (*p_it)->clone();
103 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
105 for ( ; p_it!=p_end && *p_it!=NULL; ++p_it, ++idx ) {};
106 if (p_it==p_end) properties_.push_back(NULL);
115 Properties::const_iterator p_it = properties_.begin();
116 for (
int idx=0; p_it != properties_.end(); ++p_it, ++idx)
119 (*p_it)->name() == _name
121 #ifndef OM_FORCE_STATIC_CAST 122 &&
dynamic_cast<PropertyT<T>*
>(properties_[idx]) != NULL
132 BaseProperty* property(
const std::string& _name )
const 134 Properties::const_iterator p_it = properties_.begin();
135 for (
int idx=0; p_it != properties_.end(); ++p_it, ++idx)
137 if (*p_it != NULL && (*p_it)->name() == _name)
147 assert(_h.
idx() >= 0 && _h.
idx() < (int)properties_.size());
148 assert(properties_[_h.
idx()] != NULL);
149 #ifdef OM_FORCE_STATIC_CAST 161 assert(_h.
idx() >= 0 && _h.
idx() < (int)properties_.size());
162 assert(properties_[_h.
idx()] != NULL);
163 #ifdef OM_FORCE_STATIC_CAST 175 assert(_h.
idx() >= 0 && _h.
idx() < (int)properties_.size());
176 delete properties_[_h.
idx()];
177 properties_[_h.
idx()] = NULL;
192 std::for_each(properties_.begin(), properties_.end(), ClearAll());
202 #if ((defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY) 206 void reserve(
size_t _n)
const {
207 std::for_each(properties_.begin(), properties_.end(),
214 void resize(
size_t _n)
const {
215 std::for_each(properties_.begin(), properties_.end(),
228 std::for_each(properties_.begin(), properties_.end(),
229 [_n](
BaseProperty* p) {
if (p && p->n_elements() < _n) p->resize(_n); });
236 void swap(
size_t _i0,
size_t _i1)
const {
237 std::for_each(properties_.begin(), properties_.end(),
238 [_i0, _i1](
BaseProperty* p) {
if (p) p->swap(_i0, _i1); });
245 std::for_each(properties_.begin(), properties_.end(), Reserve(_n));
252 std::for_each(properties_.begin(), properties_.end(), Resize(_n));
264 std::for_each(properties_.begin(), properties_.end(), ResizeIfSmaller(_n));
271 void swap(
size_t _i0,
size_t _i1)
const {
272 std::for_each(properties_.begin(), properties_.end(), Swap(_i0, _i1));
282 Properties::iterator p_it=properties_.begin(), p_end=properties_.end();
284 for (; p_it!=p_end && *p_it!=NULL; ++p_it, ++idx) {};
285 if (p_it==p_end) properties_.push_back(NULL);
286 properties_[idx] = _bp;
292 assert( _idx < properties_.size());
293 assert( properties_[_idx] != NULL);
301 assert( _idx < properties_.size());
302 assert( properties_[_idx] != NULL);
309 typedef Properties::iterator iterator;
310 typedef Properties::const_iterator const_iterator;
311 iterator begin() {
return properties_.begin(); }
312 iterator end() {
return properties_.end(); }
313 const_iterator begin()
const {
return properties_.begin(); }
314 const_iterator end()
const {
return properties_.end(); }
322 #ifndef DOXY_IGNORE_THIS 325 Reserve(
size_t _n) : n_(_n) {}
332 Resize(
size_t _n) : n_(_n) {}
337 struct ResizeIfSmaller
339 ResizeIfSmaller(
size_t _n) : n_(_n) {}
352 Swap(
size_t _i0,
size_t _i1) : i0_(_i0), i1_(_i1) {}
360 void operator()(
BaseProperty* _p)
const {
if (_p)
delete _p; _p=NULL; }
364 Properties properties_;
369 #endif//OPENMESH_PROPERTYCONTAINER void resize_if_smaller(size_t _n) const
Same as.
Definition: PropertyContainer.hh:263
This class provides low-level property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:97
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:271
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
A a container for properties.
Definition: PropertyContainer.hh:62
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:60
void resize(size_t _n) const
Resizes all property vectors to the specified size.
Definition: PropertyContainer.hh:251
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
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
void reserve(size_t _n) const
Reserves space for _n elements in all property vectors.
Definition: PropertyContainer.hh:244
virtual size_t n_elements() const =0
Number of elements in property.
Base property handle.
Definition: Property.hh:466
virtual void clear()=0
Clear all elements and free memory.
Default property class for any type T.
Definition: Property.hh:89
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.