#pragma once #include namespace fc { template class api_client : public api { public: api_client( fc::api server, uint64_t api_id = 0 ) { (*this)->visit( api_visitor(this, api_id, std::make_shared>(server)) ); } private: struct api_visitor { api_client* _client = nullptr; uint32_t _api_id; std::shared_ptr> _server; api_visitor( api_client* c, uint32_t api_id, std::shared_ptr> serv ) :_client(c),_api_id(api_id),_server(std::move(serv)) { wdump((int64_t(c))); } api_visitor() = delete; template static Result from_variant( const variant& v, Result&&, const std::shared_ptr>& ) { return v.as(); } template static fc::api from_variant( const variant& v, fc::api&&, const std::shared_ptr>& serv ) { return api_client( serv, v.as_uint64() ); } template void operator()( const char* name, std::function& memb )const { auto serv = _server; auto api_id = _api_id; memb = [serv,api_id,name]( Args... args ) { vtable test; auto var_result = (*serv)->call( api_id, name, {args...} ); return from_variant( var_result, Result(), serv ); }; } }; }; }