Clear Patch for OpenMesh.. free all used memory on mesh clear

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@190 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2009-08-10 10:50:34 +00:00
parent 00613d349b
commit 4c8440de8f
5 changed files with 61 additions and 14 deletions

View File

@@ -97,6 +97,9 @@ public: // synchronized array interface
/// Resize storage to hold n elements.
virtual void resize(size_t _n) = 0;
/// Clear all elements and free memory.
virtual void clear() = 0;
/// Extend the number of elements by one.
virtual void push_back() = 0;

View File

@@ -109,6 +109,7 @@ public: // inherited from BaseProperty
virtual void reserve(size_t _n) { data_.reserve(_n); }
virtual void resize(size_t _n) { data_.resize(_n); }
virtual void clear() { data_.clear(); vector_type().swap(data_); }
virtual void push_back() { data_.push_back(T()); }
virtual void swap(size_t _i0, size_t _i1)
{ std::swap(data_[_i0], data_[_i1]); }
@@ -161,18 +162,18 @@ public:
public: // data access interface
/// Get pointer to array (does not work for T==bool)
const T* data() const {
const T* data() const {
if( data_.empty() )
return 0;
return &data_[0];
return &data_[0];
}
/// Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!)
vector_type& data_vector() {
vector_type& data_vector() {
return data_;
return data_;
}
/// Access the i'th element. No range check is performed!
@@ -230,6 +231,7 @@ public: // inherited from BaseProperty
virtual void reserve(size_t _n) { data_.reserve(_n); }
virtual void resize(size_t _n) { data_.resize(_n); }
virtual void clear() { data_.clear(); vector_type().swap(data_); }
virtual void push_back() { data_.push_back(bool()); }
virtual void swap(size_t _i0, size_t _i1)
{ bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
@@ -387,6 +389,7 @@ public: // inherited from BaseProperty
virtual void reserve(size_t _n) { data_.reserve(_n); }
virtual void resize(size_t _n) { data_.resize(_n); }
virtual void clear() { data_.clear(); vector_type().swap(data_); }
virtual void push_back() { data_.push_back(std::string()); }
virtual void swap(size_t _i0, size_t _i1) {
std::swap(data_[_i0], data_[_i1]);

View File

@@ -64,7 +64,7 @@ public:
//-------------------------------------------------- constructor / destructor
PropertyContainer() {}
virtual ~PropertyContainer() { clear(); }
virtual ~PropertyContainer() { std::for_each(properties_.begin(), properties_.end(), Delete()); }
//------------------------------------------------------------- info / access
@@ -177,7 +177,16 @@ public:
void clear()
{
std::for_each(properties_.begin(), properties_.end(), Delete());
// Clear properties vector:
// Replaced the old version with new one
// which performs a swap to clear values and
// deallocate memory.
// Old version (changed 22.07.09) {
// std::for_each(properties_.begin(), properties_.end(), Delete());
// }
std::for_each(properties_.begin(), properties_.end(), ClearAll());
}
@@ -256,6 +265,12 @@ private:
size_t n_;
};
struct ClearAll
{
ClearAll() {}
void operator()(BaseProperty* _p) const { if (_p) _p->clear(); }
};
struct Swap
{
Swap(size_t _i0, size_t _i1) : i0_(_i0), i1_(_i1) {}