From abbfae912b8d54106dbcbb7260c10e3a204c9f93 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 16 Dec 2014 02:10:53 +0100 Subject: added possibility to register a ManagedType for a class derived from Managed, improved Managed readData function --- src/core/managed/Managed.hpp | 65 ++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 38 deletions(-) (limited to 'src/core/managed/Managed.hpp') diff --git a/src/core/managed/Managed.hpp b/src/core/managed/Managed.hpp index 8b0bb17..4818c3d 100644 --- a/src/core/managed/Managed.hpp +++ b/src/core/managed/Managed.hpp @@ -19,6 +19,7 @@ #ifndef _OUSIA_MANAGED_HPP_ #define _OUSIA_MANAGED_HPP_ +#include "ManagedType.hpp" #include "Manager.hpp" namespace ousia { @@ -32,6 +33,9 @@ class Rooted; template class Owned; +template +class DefaultListener; + // TODO: Implement clone, getReferenced and getReferencing /** @@ -93,33 +97,36 @@ public: return Owned{t, this}; } - template - std::vector> acquire(const std::vector> &vec) - { - std::vector> res; - for (auto &e : vec) { - res.push_back(acquire(e)); - } - return res; - } - - template - std::vector> acquire(const std::vector &vec) - { - std::vector> res; - for (auto &e : vec) { - res.push_back(acquire(e)); - } - return res; - } - void storeData(const std::string &key, Handle h); bool hasDataKey(const std::string &key); Rooted readData(const std::string &key); + std::map> readData(); + bool deleteData(const std::string &key); + + /** + * Returns the ManagedType instance registered for instances of the type + * of this Managed instance. + * + * @return a reference to the registered ManagedType for this particular + * Managed class. + */ + const ManagedType& type() const { + return ManagedType::typeOf(typeid(*this)); + } + + /** + * Returns true if this Managed instance is of the given ManagedType. + * + * @param true if the ManagedType registered for this particular Managed + * class is + */ + bool isa(const ManagedType &t) const { + return type().isa(t); + } }; /** @@ -506,24 +513,6 @@ public: Managed *getOwner() const { return owner; } }; - -inline void Managed::storeData(const std::string &key, Handle h) { - mgr.storeData(this, key, h.get()); -} - -inline bool Managed::hasDataKey(const std::string &key) -{ - return mgr.readData(this, key) != nullptr; -} - -inline Rooted Managed::readData(const std::string &key) { - return mgr.readData(this, key); -} - -inline bool Managed::deleteData(const std::string &key) { - return mgr.deleteData(this, key); -} - } #endif /* _OUSIA_MANAGED_HPP_ */ -- cgit v1.2.3