diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-11-15 21:34:36 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-11-15 21:34:36 +0100 |
commit | 96de51de8f588b0668d75836d9279210d3311e13 (patch) | |
tree | 062e3e735c2d2bd40ef69ad5966713d8974ac076 /src | |
parent | 165cf9a5c6ab03dab64d5eb5a5577f8c216bb832 (diff) |
Removed type assertion -- makes class definitions very unflexible as it doesn't work with forward declared classes
Diffstat (limited to 'src')
-rw-r--r-- | src/core/Managed.hpp | 39 |
1 files changed, 34 insertions, 5 deletions
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 <class T> Owned<T> acquire(const Handle<T> &h) { @@ -317,9 +340,9 @@ public: } return res; } - + template <class T> - std::vector<Owned<T>> acquire(const std::vector<T*> &vec) + std::vector<Owned<T>> acquire(const std::vector<T *> &vec) { std::vector<Owned<T>> res; for (auto &e : vec) { @@ -346,9 +369,6 @@ protected: friend class Rooted<T>; friend class Owned<T>; - static_assert(std::is_convertible<T *, Managed *>::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 <class T2> + Handle<T2> cast() + { + return Handle<T2>{static_cast<T2 *>(ptr)}; + } }; /** |