Commit aec6d218 authored by Martin Heistermann's avatar Martin Heistermann

WIP: delete broken assignment operators for PropertyPtrT and ResourceManager;...

WIP: delete broken assignment operators for PropertyPtrT and ResourceManager; implement ResourceManager copy and move constructors/assignment operators
parent d858ab4f
......@@ -46,10 +46,4 @@
namespace OpenVolumeMesh {
BaseProperty& BaseProperty::operator=(const BaseProperty& _cpy) {
resMan_ = _cpy.resMan_;
lock_ = _cpy.lock_;
return *this;
}
} // Namespace OpenVolumeMesh
......@@ -55,11 +55,11 @@ class BaseProperty {
public:
friend class ResourceManager;
explicit BaseProperty(ResourceManager& _resMan) : resMan_(_resMan), lock_(false) {}
explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan), lock_(false) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_), lock_(_cpy.lock_) {}
BaseProperty& operator=(const BaseProperty& _cpy);
BaseProperty& operator=(const BaseProperty& _cpy) = delete;
virtual ~BaseProperty() {}
......@@ -101,7 +101,9 @@ protected:
bool locked() const { return lock_; }
ResourceManager& resMan_;
void setResMan(ResourceManager &resMan) { resMan_ = &resMan;}
ResourceManager* resMan_;
bool lock_;
};
......
......@@ -63,7 +63,7 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* only one who stores the property.
*/
if(!locked() && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
resMan_.release_property(HandleT(handle().idx()));
resMan_->release_property(HandleT(handle().idx()));
unlock();
}
}
......
......@@ -47,7 +47,18 @@ namespace OpenVolumeMesh {
ResourceManager::ResourceManager() {
}
ResourceManager::ResourceManager(const ResourceManager &other) {
ResourceManager::ResourceManager(const ResourceManager &other)
{
*this = other;
}
ResourceManager::ResourceManager(ResourceManager &&other)
{
*this = std::move(other);
}
ResourceManager &ResourceManager::operator=(const ResourceManager &other)
{
auto cloneProps = [this](const Properties &src, Properties &dest) {
dest.reserve(src.size());
for (BaseProperty *bp: src) {
......@@ -61,6 +72,25 @@ ResourceManager::ResourceManager(const ResourceManager &other) {
cloneProps(other.halfface_props_, halfface_props_);
cloneProps(other.cell_props_, cell_props_);
cloneProps(other.mesh_props_, mesh_props_);
return *this;
}
ResourceManager &ResourceManager::operator=(ResourceManager &&other)
{
auto moveProps = [this](Properties &&src, Properties &dest) {
dest = std::move(src);
for (auto prop: dest) {
prop->setResMan(*this);
}
};
moveProps(std::move(other.vertex_props_), vertex_props_);
moveProps(std::move(other.edge_props_), edge_props_);
moveProps(std::move(other.halfedge_props_), halfedge_props_);
moveProps(std::move(other.face_props_), face_props_);
moveProps(std::move(other.halfface_props_), halfface_props_);
moveProps(std::move(other.cell_props_), cell_props_);
moveProps(std::move(other.mesh_props_), mesh_props_);
return *this;
}
ResourceManager::~ResourceManager() {
......
......@@ -77,6 +77,11 @@ class ResourceManager {
public:
ResourceManager();
ResourceManager(const ResourceManager &other);
ResourceManager(ResourceManager &&other);
ResourceManager &operator=(const ResourceManager &other);
// warning: after a move there may still be properties pointing to the old resman ("other"),
// maybe we should track all props?
ResourceManager &operator=(ResourceManager &&other);
virtual ~ResourceManager();
template <class PropT, class HandleT> friend class PropertyPtr;
......
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