From 77c02b8107d086765d3b55112c828524731b64ef Mon Sep 17 00:00:00 2001 From: Hans-Christian Ebke Date: Mon, 17 Sep 2012 06:28:07 +0000 Subject: [PATCH] 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 --- src/OpenMesh/Core/Utils/PropertyManager.hh | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/OpenMesh/Core/Utils/PropertyManager.hh b/src/OpenMesh/Core/Utils/PropertyManager.hh index f7aa33a0..5acf958d 100644 --- a/src/OpenMesh/Core/Utils/PropertyManager.hh +++ b/src/OpenMesh/Core/Utils/PropertyManager.hh @@ -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 /**