[beast: 16/26] BSE: allow as<shared_ptr<>>() from Bse::ItemIface
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 16/26] BSE: allow as<shared_ptr<>>() from Bse::ItemIface
- Date: Mon, 13 Jul 2015 02:27:48 +0000 (UTC)
commit d551e2af35b50e28eda786d5f82d4f95cec45d69
Author: Tim Janik <timj gnu org>
Date: Thu Jul 2 13:47:03 2015 +0200
BSE: allow as<shared_ptr<>>() from Bse::ItemIface
bse/bseserverinsert.hh | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/bse/bseserverinsert.hh b/bse/bseserverinsert.hh
index 3a3bd2e..04d8eaa 100644
--- a/bse/bseserverinsert.hh
+++ b/bse/bseserverinsert.hh
@@ -5,7 +5,8 @@ struct DUMMY { // dummy class for auto indentation
class_scope:Object:
- template<class BseObjectPtr>
+ // as<BseObjectPtr>()
+ template<class BseObjectPtr, typename ::std::enable_if<std::is_pointer<BseObjectPtr>::value, bool>::type =
true>
BseObjectPtr as ()
{
static_assert (std::is_pointer<BseObjectPtr>::value, "'BseObject*' required");
@@ -13,6 +14,19 @@ class_scope:Object:
static_assert (std::is_base_of<GObject, BseObjectT>::value, "'BseObject*' required");
return this ? (BseObjectPtr) this->as_bse_object() : NULL;
}
+ // DERIVES_shared_ptr (uses void_t to prevent errors for T without shared_ptr's typedefs)
+ template<class T, typename = void> struct DERIVES_shared_ptr : std::false_type {};
+ template<class T> struct DERIVES_shared_ptr<T, Rapicorn::void_t< typename T::element_type > > :
+ std::is_base_of< std::shared_ptr<typename T::element_type>, T > {};
+ // as<shared_ptr<T>>()
+ template<class ObjectImplP, typename ::std::enable_if<DERIVES_shared_ptr<ObjectImplP>::value, bool>::type
= true>
+ ObjectImplP as ()
+ {
+ typedef typename ObjectImplP::element_type ObjectImplT;
+ static_assert (std::is_base_of<Rapicorn::Aida::ImplicitBase, ObjectImplT>::value, "");
+ ObjectImplT *impl = this ? dynamic_cast<ObjectImplT*> (this) : NULL;
+ return impl ? Rapicorn::shared_ptr_cast<ObjectImplT> (impl) : NULL;
+ }
protected:
virtual BseObject* as_bse_object() = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]