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;
279 assert( _idx < properties_.size());
280 assert( properties_[_idx] !=
nullptr);
282 assert( p !=
nullptr );
288 assert( _idx < properties_.size());
289 assert( properties_[_idx] !=
nullptr);
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(); }
309 #ifndef DOXY_IGNORE_THIS 312 explicit Reserve(
size_t _n) : n_(_n) {}
319 explicit Resize(
size_t _n) : n_(_n) {}
324 struct ResizeIfSmaller
326 explicit ResizeIfSmaller(
size_t _n) : n_(_n) {}
339 Swap(
size_t _i0,
size_t _i1) : i0_(_i0), i1_(_i1) {}
347 void operator()(
BaseProperty* _p)
const {
if (_p)
delete _p; }
351 Properties properties_;
356 #endif//OPENMESH_PROPERTYCONTAINER virtual size_t n_elements() const =0
Number of elements in property.
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
int idx() const
Get the underlying index of this handle.
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
A a container for properties.
void resize(size_t _n) const
Default property class for any type T.
void reserve(size_t _n) const
void swap(size_t _i0, size_t _i1) const
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
void resize_if_smaller(size_t _n) const
virtual void clear()=0
Clear all elements and free memory.