#pragma once #include #include namespace fc { namespace detail { struct actor_member { // TODO: expand for all method arity and constness.... template static std::function(A1)> functor( P&& p, R (C::*mem_func)(A1), fc::thread* t = nullptr) { return [=](A1 a1){ return t->async( [=](){ return (p->*mem_func)(a1); } ); }; } }; template struct actor_vtable_visitor { template actor_vtable_visitor( fc::thread* t, U&& u ):_thread(t),_this( fc::forward(u) ){} template void operator()( const char* name, Function& memb, MemberPtr m )const { memb = actor_member::functor( _this, m, _thread ); } fc::thread* _thread; ThisPtr _this; }; } /** * Posts all method calls to another thread and * returns a future. */ template class actor : public ptr { public: template actor( InterfaceType* p, fc::thread* t = &fc::thread::current() ) { this->_vtable.reset(new detail::vtable() ); this->_vtable->template visit( detail::actor_vtable_visitor(t, p) ); } }; } // namespace fc