Commit ca62efce authored by Mike Kremer's avatar Mike Kremer
Browse files

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 @@ ...@@ -48,6 +48,8 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "OpenVolumeMeshHandle.hh"
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
/** \class OpenVolumeMeshBaseProperty /** \class OpenVolumeMeshBaseProperty
...@@ -67,11 +69,11 @@ public: ...@@ -67,11 +69,11 @@ public:
public: public:
OpenVolumeMeshBaseProperty(const std::string& _name = "<unknown>") : OpenVolumeMeshBaseProperty(const std::string& _name = "<unknown>") :
name_(_name), persistent_(false) { name_(_name), persistent_(false), handle_(-1) {
} }
OpenVolumeMeshBaseProperty(const OpenVolumeMeshBaseProperty& _rhs) : OpenVolumeMeshBaseProperty(const OpenVolumeMeshBaseProperty& _rhs) :
name_(_rhs.name_), persistent_(_rhs.persistent_) { name_(_rhs.name_), persistent_(_rhs.persistent_), handle_(_rhs.handle_.idx()) {
} }
virtual ~OpenVolumeMeshBaseProperty() {} virtual ~OpenVolumeMeshBaseProperty() {}
...@@ -145,11 +147,17 @@ public: ...@@ -145,11 +147,17 @@ public:
: UnknownSize; : UnknownSize;
} }
const OpenVolumeMeshHandle& handle() const { return handle_; }
void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }
private: private:
std::string name_; std::string name_;
bool persistent_; bool persistent_;
OpenVolumeMeshHandle handle_;
}; };
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
#include "BaseProperty.hh" #include "BaseProperty.hh"
#include "PropertyHandles.hh" #include "PropertyHandles.hh"
#include "MemoryInclude.hh" #include "../System/MemoryInclude.hh"
namespace OpenVolumeMesh { namespace OpenVolumeMesh {
...@@ -70,15 +70,13 @@ public: ...@@ -70,15 +70,13 @@ public:
friend class ResourceManager; friend class ResourceManager;
typedef HandleT Handle;
typedef typename PropT::vector_type::const_iterator const_iterator; typedef typename PropT::vector_type::const_iterator const_iterator;
typedef typename PropT::vector_type::iterator iterator; typedef typename PropT::vector_type::iterator iterator;
typedef typename PropT::reference reference; typedef typename PropT::reference reference;
typedef typename PropT::const_reference const_reference; typedef typename PropT::const_reference const_reference;
/// Constructor /// Constructor
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, Handle _handle); PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle);
/// Destructor /// Destructor
virtual ~PropertyPtr(); virtual ~PropertyPtr();
...@@ -105,10 +103,6 @@ protected: ...@@ -105,10 +103,6 @@ protected:
virtual void resize(unsigned int _size); virtual void resize(unsigned int _size);
virtual void set_handle(const OpenVolumeMeshHandle& _handle); virtual void set_handle(const OpenVolumeMeshHandle& _handle);
private:
Handle handle_;
}; };
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
......
...@@ -50,7 +50,7 @@ namespace OpenVolumeMesh { ...@@ -50,7 +50,7 @@ namespace OpenVolumeMesh {
template <class PropT, class HandleT> template <class PropT, class HandleT>
PropertyPtr<PropT,HandleT>::PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle) : 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> template <class PropT, class HandleT>
...@@ -62,7 +62,8 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() { ...@@ -62,7 +62,8 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* only one who stores the property. * only one who stores the property.
*/ */
if(!locked() && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) { 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(); unlock();
} }
} }
...@@ -84,12 +85,12 @@ void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) { ...@@ -84,12 +85,12 @@ void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) {
template <class PropT, class HandleT> template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_handle(const OpenVolumeMeshHandle& _handle) { 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> template <class PropT, class HandleT>
OpenVolumeMeshHandle PropertyPtr<PropT,HandleT>::handle() const { OpenVolumeMeshHandle PropertyPtr<PropT,HandleT>::handle() const {
return handle_; return ptr::shared_ptr<PropT>::get()->handle();
} }
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
...@@ -172,7 +172,10 @@ void ResourceManager::remove_property(StdVecT& _vec, size_t _idx) { ...@@ -172,7 +172,10 @@ void ResourceManager::remove_property(StdVecT& _vec, size_t _idx) {
(*(_vec.begin() + _idx))->lock(); (*(_vec.begin() + _idx))->lock();
delete *(_vec.begin() + _idx); 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); _vec.erase(_vec.begin() + _idx);
std::cerr << "After erase" << std::endl;
size_t n = _vec.size(); size_t n = _vec.size();
for(size_t i = 0; i < n; ++i) { for(size_t i = 0; i < n; ++i) {
_vec[i]->set_handle(OpenVolumeMeshHandle(i)); _vec[i]->set_handle(OpenVolumeMeshHandle(i));
......
Supports Markdown
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