Commit 77c02b81 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

OpenMesh/Core/Utils/PropertyManager: Added non-C++0x move capabilities.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@674 fdac6126-5c0c-442c-9429-916003d36597
parent dea5c91e
......@@ -109,6 +109,12 @@ class PropertyManager {
deleteProperty();
}
void swap(PropertyManager &rhs) {
std::swap(mesh_, rhs.mesh_);
std::swap(prop_, rhs.prop_);
std::swap(retain_, rhs.retain_);
}
#if __cplusplus > 199711L or __GXX_EXPERIMENTAL_CXX0X__
/**
* Move constructor. Transfers ownership (delete responsibility).
......@@ -143,6 +149,44 @@ class PropertyManager {
pm.retain();
return std::move(pm);
}
#else
class Proxy {
private:
Proxy(MeshT *mesh_, PROPTYPE prop_, bool retain_) :
mesh_(mesh_), prop_(prop_), retain_(retain_) {}
MeshT *mesh_;
PROPTYPE prop_;
bool retain_;
friend class PropertyManager;
};
operator Proxy() {
Proxy p(mesh_, prop_, retain_);
mesh_ = 0;
retain_ = true;
return p;
}
PropertyManager(Proxy p) : mesh_(p.mesh_), prop_(p.prop_), retain_(p.retain_) {}
PropertyManager &operator=(Proxy p) {
PropertyManager(p).swap(*this);
return *this;
}
/**
* Create a property manager for the supplied property and mesh.
* If the property doesn't exist, it is created. In any case,
* lifecycle management is disabled.
*/
static Proxy createIfNotExists(MeshT &mesh, const char *propname) {
PROPTYPE dummy_prop;
PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
pm.retain();
return (Proxy)pm;
}
#endif
/**
......
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