Mercurial > hg > svcore
changeset 1746:826e0cb77d8e by-id
Add isa
author | Chris Cannam |
---|---|
date | Tue, 02 Jul 2019 15:28:46 +0100 |
parents | 074b860a7828 |
children | 498b426191e5 |
files | base/ById.h |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/base/ById.h Tue Jul 02 14:08:25 2019 +0100 +++ b/base/ById.h Tue Jul 02 15:28:46 2019 +0100 @@ -121,9 +121,15 @@ public: static void add(int, std::shared_ptr<WithId>); static void release(int); - static std::shared_ptr<WithId> get(int); + static std::shared_ptr<WithId> get(int); template <typename Derived> + static bool isa(int id) { + std::shared_ptr<WithId> p = get(id); + return bool(std::dynamic_pointer_cast<Derived>(p)); + } + + template <typename Derived> static std::shared_ptr<Derived> getAs(int id) { std::shared_ptr<WithId> p = get(id); return std::dynamic_pointer_cast<Derived>(p); @@ -154,6 +160,11 @@ } template <typename Derived> + static bool isa(Id id) { + return AnyById::isa<Derived>(id.untyped); + } + + template <typename Derived> static std::shared_ptr<Derived> getAs(Id id) { return AnyById::getAs<Derived>(id.untyped); }