2#include <fc/thread/future.hpp>
5#include <boost/config.hpp>
10# define FC_CALL_MEMBER_TEMPLATE_KEYWORD
12# define FC_CALL_MEMBER_TEMPLATE_KEYWORD template
17 template<
typename R,
typename C,
typename P,
typename... Args>
18 static std::function<
R(Args...)>
functor(
P&&
p,
R (C::*mem_func)(Args...) );
19 template<
typename R,
typename C,
typename P,
typename... Args>
20 static std::function<
R(Args...)>
functor(
P&&
p,
R (C::*mem_func)(Args...)const );
23 template<
typename Interface,
typename Transform >
24 struct vtable :
public std::enable_shared_from_this<vtable<Interface,Transform>>
27 template<
typename OtherType>
33 template<
typename R,
typename MemberPtr,
typename... Args>
34 void operator()(
const char*
name, std::function<
R(Args...)>& memb, MemberPtr m )
const {
36 memb = [src,m]( Args... args ){
return (src->*m)(args...); };
41 template<
typename Interface,
typename Transform >
59 template<
typename T >
62 typedef std::shared_ptr< api_base >
api_ptr;
66 template<
typename Interface,
typename Transform =
identity_member >
78 _data = std::make_shared<fc::any>(
p);
79 T& ptr = boost::any_cast<T&>(*
_data);
80 auto& pointed_at = *ptr;
81 typedef typename std::remove_reference<
decltype(pointed_at)>::type source_vtable_type;
103#include <boost/preprocessor/repeat.hpp>
104#include <boost/preprocessor/repetition/enum_binary_params.hpp>
105#include <boost/preprocessor/repetition/enum_params.hpp>
106#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
107#include <boost/preprocessor/facilities/empty.hpp>
108#include <boost/preprocessor/seq/for_each.hpp>
109#include <boost/preprocessor/stringize.hpp>
111#define FC_API_VTABLE_DEFINE_MEMBER( r, data, elem ) \
112 decltype(Transform::functor( (data*)nullptr, &data::elem)) elem;
113#define FC_API_VTABLE_DEFINE_VISIT_OTHER( r, data, elem ) \
114 { typedef typename Visitor::other_type OtherType; \
115 v( BOOST_PP_STRINGIZE(elem), elem, &OtherType::elem ); }
116#define FC_API_VTABLE_DEFINE_VISIT( r, data, elem ) \
117 v( BOOST_PP_STRINGIZE(elem), elem );
119#define FC_API( CLASS, METHODS ) \
121 template<typename Transform> \
122 struct vtable<CLASS,Transform> : public std::enable_shared_from_this<vtable<CLASS,Transform>> { \
123 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_MEMBER, CLASS, METHODS ) \
124 template<typename Visitor> \
125 void visit_other( Visitor&& v ){ \
126 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_VISIT_OTHER, CLASS, METHODS ) \
128 template<typename Visitor> \
129 void visit( Visitor&& v ){ \
130 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_VISIT, CLASS, METHODS ) \
virtual uint64_t get_handle() const =0
api< T, identity_member > as()
virtual api_id_type register_api(api_connection &conn) const =0
virtual api_id_type register_api(api_connection &conn) const override
vtable_type & operator*() const
friend bool operator==(const api &a, const api &b)
virtual uint64_t get_handle() const override
vtable< Interface, Transform > vtable_type
vtable_type * operator->() const
std::shared_ptr< fc::any > _data
friend bool operator!=(const api &a, const api &b)
std::shared_ptr< vtable_type > _vtable
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
std::shared_ptr< api_base > api_ptr
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)
unsigned __int64 uint64_t
static std::function< R(Args...)> functor(P &&p, R(C::*mem_func)(Args...))
static std::function< R(Args...)> functor(P &&p, R(C::*mem_func)(Args...) const)
vtable_copy_visitor(OtherType &s)
void operator()(const char *name, std::function< R(Args...)> &memb, MemberPtr m) const