Commit ca62efce authored by Mike Kremer's avatar Mike Kremer

Property handle is now encapsulated in property class itself.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@128 66977474-1d4b-4f09-8fe9-267525286df2
parent d92ef52f
......@@ -48,6 +48,8 @@
#include <string>
#include <iostream>
#include "OpenVolumeMeshHandle.hh"
//== CLASS DEFINITION =========================================================
/** \class OpenVolumeMeshBaseProperty
......@@ -67,11 +69,11 @@ public:
public:
OpenVolumeMeshBaseProperty(const std::string& _name = "<unknown>") :
name_(_name), persistent_(false) {
name_(_name), persistent_(false), handle_(-1) {
}
OpenVolumeMeshBaseProperty(const OpenVolumeMeshBaseProperty& _rhs) :
name_(_rhs.name_), persistent_(_rhs.persistent_) {
name_(_rhs.name_), persistent_(_rhs.persistent_), handle_(_rhs.handle_.idx()) {
}
virtual ~OpenVolumeMeshBaseProperty() {}
......@@ -145,11 +147,17 @@ public:
: UnknownSize;
}
const OpenVolumeMeshHandle& handle() const { return handle_; }
void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }
private:
std::string name_;
bool persistent_;
OpenVolumeMeshHandle handle_;
};
} // Namespace OpenVolumeMesh
......
......@@ -50,7 +50,7 @@
#include "BaseProperty.hh"
#include "PropertyHandles.hh"
#include "MemoryInclude.hh"
#include "../System/MemoryInclude.hh"
namespace OpenVolumeMesh {
......@@ -70,15 +70,13 @@ public:
friend class ResourceManager;
typedef HandleT Handle;
typedef typename PropT::vector_type::const_iterator const_iterator;
typedef typename PropT::vector_type::iterator iterator;
typedef typename PropT::reference reference;
typedef typename PropT::const_reference const_reference;
/// Constructor
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, Handle _handle);
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle);
/// Destructor
virtual ~PropertyPtr();
......@@ -105,10 +103,6 @@ protected:
virtual void resize(unsigned int _size);
virtual void set_handle(const OpenVolumeMeshHandle& _handle);
private:
Handle handle_;
};
} // Namespace OpenVolumeMesh
......
......@@ -50,7 +50,7 @@ namespace OpenVolumeMesh {
template <class PropT, class HandleT>
PropertyPtr<PropT,HandleT>::PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle) :
ptr::shared_ptr<PropT>(_ptr), BaseProperty(_resMan), handle_(_handle) {
ptr::shared_ptr<PropT>(_ptr), BaseProperty(_resMan) {
}
template <class PropT, class HandleT>
......@@ -62,7 +62,8 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* only one who stores the property.
*/
if(!locked() && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
resMan_.release_property(handle_);
std::cerr << "Trying to release property " << ptr::shared_ptr<PropT>::get() << std::endl;
resMan_.release_property(HandleT(handle().idx()));
unlock();
}
}
......@@ -84,12 +85,12 @@ void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) {
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_handle(const OpenVolumeMeshHandle& _handle) {
handle_.idx(_handle.idx());
return ptr::shared_ptr<PropT>::get()->set_handle(_handle);
}
template <class PropT, class HandleT>
OpenVolumeMeshHandle PropertyPtr<PropT,HandleT>::handle() const {
return handle_;
return ptr::shared_ptr<PropT>::get()->handle();
}
} // Namespace OpenVolumeMesh
......@@ -172,7 +172,10 @@ void ResourceManager::remove_property(StdVecT& _vec, size_t _idx) {
(*(_vec.begin() + _idx))->lock();
delete *(_vec.begin() + _idx);
std::cerr << "Before erase with idx " << _idx << std::endl;
std::cerr << "Vector still has " << _vec.size() << " elements" << std::endl;
_vec.erase(_vec.begin() + _idx);
std::cerr << "After erase" << std::endl;
size_t n = _vec.size();
for(size_t i = 0; i < n; ++i) {
_vec[i]->set_handle(OpenVolumeMeshHandle(i));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment