From 96de51de8f588b0668d75836d9279210d3311e13 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sat, 15 Nov 2014 21:34:36 +0100 Subject: Removed type assertion -- makes class definitions very unflexible as it doesn't work with forward declared classes --- src/core/Managed.hpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src/core/Managed.hpp') diff --git a/src/core/Managed.hpp b/src/core/Managed.hpp index 8cef1d2..3e7bbdd 100644 --- a/src/core/Managed.hpp +++ b/src/core/Managed.hpp @@ -281,15 +281,38 @@ public: */ class Managed { protected: + /** + * mgr is the reference to the managed object manager which owns this + * managed object. + */ Manager &mgr; public: + /** + * Constructor of the Managed class. Associates the new instance with the + * given Manager, which is now in charge for managing this instance. Never + * manually free instances of this class (even by using stack instances). + * Always use the Rooted and Owned smart pointer classes when refering to + * types derived from Managed. + * + * @param mgr is the Manager which should take ownership of this instance. + */ Managed(Manager &mgr) : mgr(mgr) { mgr.manage(this); }; + /** + * Virtual destuctor which may be overwritten by child classes. + */ virtual ~Managed(){}; + /** + * Returns a reference ot the manager instance which owns this managed + * object. + */ Manager &getManager() { return mgr; } + /** + * Acquires a reference to the object wraped in the given handle. + */ template Owned acquire(const Handle &h) { @@ -317,9 +340,9 @@ public: } return res; } - + template - std::vector> acquire(const std::vector &vec) + std::vector> acquire(const std::vector &vec) { std::vector> res; for (auto &e : vec) { @@ -346,9 +369,6 @@ protected: friend class Rooted; friend class Owned; - static_assert(std::is_convertible::value, - "T must be a Managed"); - /** * Reference to the represented managed object. */ @@ -441,6 +461,15 @@ public: * Returns true if the handle is the null pointer. */ bool operator!() const { return isNull(); } + + /** + * Statically casts the handle to a handle of the given type. + */ + template + Handle cast() + { + return Handle{static_cast(ptr)}; + } }; /** -- cgit v1.2.3