Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
actor.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/api.hpp>
3#include <fc/thread/thread.hpp>
4
5namespace fc {
6
7 namespace detail {
8 struct actor_member {
9 #if 1 // BOOST_NO_VARIADIC_TEMPLATES
10 #define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
11 template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
12 static std::function<fc::future<R>( BOOST_PP_ENUM_PARAMS(n,A) ) > \
13 functor( P p, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, fc::thread* c = 0) { \
14 return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a))->fc::future<R>{ \
15 return c->async( [=](){ return (p->*mem_func)(BOOST_PP_ENUM_PARAMS(n,a)); } ); }; \
16 }
17 BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const )
18 BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() )
19 #undef RPC_MEMBER_FUNCTOR
20
21 #else // g++ has a bug that prevents lambdas and varidic templates from working together (G++ Bug 41933)
22
23 template<typename R, typename C, typename P, typename... Args>
24 static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...), fc::thread* c ) {
25 return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
26 }
27 template<typename R, typename C, typename P, typename... Args>
28 static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const, fc::thread* c ){
29 return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
30 }
31 #endif
32 };
33
34 template<typename ThisPtr>
36 template<typename U>
37 actor_vtable_visitor( fc::thread* t, U&& u ):_thread(t),_this( fc::forward<U>(u) ){}
38
39 template<typename Function, typename MemberPtr>
40 void operator()( const char* name, Function& memb, MemberPtr m )const {
41 memb = actor_member::functor( _this, m, _thread );
42 }
43 fc::thread* _thread;
44 ThisPtr _this;
45 };
46 }
47
52 template<typename Interface>
53 class actor : public api<Interface, detail::actor_member> {
54 public:
56
57 template<typename InterfaceType>
58 actor( InterfaceType* p, fc::thread* t = &fc::thread::current() )
59 {
60 this->_vtable.reset(new detail::vtable<Interface,detail::actor_member>() );
61 this->_vtable->template visit<InterfaceType>( detail::actor_vtable_visitor<InterfaceType*>(t, p) );
62 }
63 };
64
65} // namespace fc
#define RPC_MEMBER_FUNCTOR(z, n, IS_CONST)
Definition actor.hpp:10
const mie::Vuint & p
Definition bn.cpp:27
std::string name
actor(InterfaceType *p, fc::thread *t=&fc::thread::current())
Definition actor.hpp:58
std::shared_ptr< vtable_type > _vtable
Definition api.hpp:97
#define P
Definition dtoa.c:437
namespace sysio::chain
Definition authority.cpp:3
void operator()(const char *name, Function &memb, MemberPtr m) const
Definition actor.hpp:40
actor_vtable_visitor(fc::thread *t, U &&u)
Definition actor.hpp:37
#define R
Definition dtoa.c:306