0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd::mods: Checkpoint experimental invocation stack; add sym_ptr::get() ref.

This commit is contained in:
Jason Volk 2019-02-11 13:15:17 -08:00
parent d2744f02c9
commit fe25959658
2 changed files with 60 additions and 30 deletions

View file

@ -38,8 +38,8 @@ struct ircd::mods::import
void reload();
public:
template<class... args> decltype(auto) operator()(args&&... a) const;
template<class... args> decltype(auto) operator()(args&&... a);
template<class... args> decltype(auto) operator()(args&&...) const;
template<class... args> decltype(auto) operator()(args&&...);
const T *operator->() const;
const T &operator*() const;
@ -147,6 +147,17 @@ ircd::mods::import<T>::operator->()
return sym_ptr::operator-><T>();
}
template<class T>
template<class... args>
decltype(auto)
ircd::mods::import<T>::operator()(args&&... a)
{
if(unlikely(!*this))
reload();
return sym_ptr::operator()<T>(std::forward<args>(a)...);
}
template<class T>
ircd::mods::import<T>::operator
const T &()
@ -171,26 +182,13 @@ const
return sym_ptr::operator-><T>();
}
template<class T>
template<class... args>
decltype(auto)
ircd::mods::import<T>::operator()(args&&... a)
{
if(unlikely(!*this))
reload();
using R = decltype(get<T>()(a...));
return sym_ptr::operator()<T, R>(std::forward<args>(a)...);
}
template<class T>
template<class... args>
decltype(auto)
ircd::mods::import<T>::operator()(args&&... a)
const
{
using R = decltype(get<T>()(a...));
return sym_ptr::operator()<T, R>(std::forward<args>(a)...);
return sym_ptr::operator()<T>(std::forward<args>(a)...);
}
template<class T>

View file

@ -14,6 +14,17 @@
namespace ircd::mods
{
struct sym_ptr;
template<class F,
class... args,
typename std::enable_if<!std::is_member_pointer<F>::value>::type * = nullptr>
decltype(auto) invoke(F *const &f, args&&... a);
template<class F,
class O,
class... args,
typename std::enable_if<std::is_member_pointer<F>::value>::type * = nullptr>
decltype(auto) invoke(F *const &f, O *const &o, args&&... a);
}
/// Representation of a symbol in a loaded library (non-template; low level).
@ -30,12 +41,12 @@ class ircd::mods::sym_ptr
template<class T> const T *get() const;
template<class T> const T *operator->() const;
template<class T> const T &operator*() const;
template<class T, class R, class... args> R operator()(args&&... a) const;
template<class T, class... args> decltype(auto) operator()(args&&... a) const;
void *&get();
template<class T> T *get();
template<class T> T *operator->();
template<class T> T &operator*();
template<class T, class R, class... args> R operator()(args&&... a);
explicit sym_ptr(mod &, const string_view &symname);
sym_ptr(module, const string_view &symname);
@ -43,15 +54,6 @@ class ircd::mods::sym_ptr
sym_ptr() = default;
};
template<class T,
class R,
class... args>
R
ircd::mods::sym_ptr::operator()(args&&... a)
{
return (operator*<T>())(std::forward<args>(a)...);
}
template<class T>
T &
ircd::mods::sym_ptr::operator*()
@ -80,14 +82,19 @@ ircd::mods::sym_ptr::get()
return reinterpret_cast<T *>(ptr);
}
inline void *&
ircd::mods::sym_ptr::get()
{
return ptr;
}
template<class T,
class R,
class... args>
R
decltype(auto)
ircd::mods::sym_ptr::operator()(args&&... a)
const
{
return (operator*<T>())(std::forward<args>(a)...);
return invoke(get<T>(), std::forward<args>(a)...);
}
template<class T>
@ -134,3 +141,28 @@ const
{
return !ptr || expired();
}
template<class F,
class O,
class... args,
typename std::enable_if<std::is_member_pointer<F>::value>::type *>
decltype(auto)
ircd::mods::invoke(F *const &f,
O *const &o,
args&&... a)
{
const void *const nv(f);
const F mfp(*reinterpret_cast<const F *>(&nv));
O *const volatile that(o);
return std::invoke(mfp, that, std::forward<args>(a)...);
}
template<class F,
class... args,
typename std::enable_if<!std::is_member_pointer<F>::value>::type *>
decltype(auto)
ircd::mods::invoke(F *const &f,
args&&... a)
{
return std::invoke(f, std::forward<args>(a)...);
}