updates to stream, optional, string, and actor
This commit is contained in:
parent
ba4eb96d88
commit
2311a1f476
6 changed files with 47 additions and 17 deletions
|
|
@ -6,11 +6,29 @@ namespace fc {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct actor_member {
|
struct actor_member {
|
||||||
// TODO: expand for all method arity and constness....
|
#if 1 // BOOST_NO_VARIADIC_TEMPLATES
|
||||||
template<typename R, typename C, typename A1, typename P>
|
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
||||||
static std::function<fc::future<R>(A1)> functor( P&& p, R (C::*mem_func)(A1), fc::thread* t = nullptr) {
|
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
|
||||||
return [=](A1 a1){ return t->async( [=](){ return (p->*mem_func)(a1); } ); };
|
static std::function<fc::future<R>( BOOST_PP_ENUM_PARAMS(n,A) ) > \
|
||||||
|
functor( P p, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, fc::thread* c = 0) { \
|
||||||
|
return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a))->fc::future<R>{ \
|
||||||
|
return c->async( [=](){ return (p->*mem_func)(BOOST_PP_ENUM_PARAMS(n,a)); } ); }; \
|
||||||
}
|
}
|
||||||
|
BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const )
|
||||||
|
BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() )
|
||||||
|
#undef RPC_MEMBER_FUNCTOR
|
||||||
|
|
||||||
|
#else // g++ has a bug that prevents lambdas and varidic templates from working together (G++ Bug 41933)
|
||||||
|
|
||||||
|
template<typename R, typename C, typename P, typename... Args>
|
||||||
|
static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...), fc::thread* c ) {
|
||||||
|
return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
|
||||||
|
}
|
||||||
|
template<typename R, typename C, typename P, typename... Args>
|
||||||
|
static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const, fc::thread* c ){
|
||||||
|
return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ThisPtr>
|
template<typename ThisPtr>
|
||||||
|
|
@ -34,13 +52,14 @@ namespace fc {
|
||||||
template<typename Interface>
|
template<typename Interface>
|
||||||
class actor : public ptr<Interface, detail::actor_member> {
|
class actor : public ptr<Interface, detail::actor_member> {
|
||||||
public:
|
public:
|
||||||
|
actor(){}
|
||||||
|
|
||||||
template<typename InterfaceType>
|
template<typename InterfaceType>
|
||||||
actor( InterfaceType* p, fc::thread* t = &fc::thread::current() )
|
actor( InterfaceType* p, fc::thread* t = &fc::thread::current() )
|
||||||
{
|
{
|
||||||
this->_vtable.reset(new detail::vtable<Interface,detail::actor_member>() );
|
this->_vtable.reset(new detail::vtable<Interface,detail::actor_member>() );
|
||||||
this->_vtable->template visit<InterfaceType>( detail::actor_vtable_visitor<InterfaceType*>(t, p) );
|
this->_vtable->template visit<InterfaceType>( detail::actor_vtable_visitor<InterfaceType*>(t, p) );
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace fc
|
} // namespace fc
|
||||||
|
|
|
||||||
|
|
@ -54,25 +54,20 @@ namespace fc { namespace json {
|
||||||
|
|
||||||
|
|
||||||
template<typename InterfaceType>
|
template<typename InterfaceType>
|
||||||
class rpc_client : public ptr<InterfaceType,fc::json::detail::rpc_member> {
|
class rpc_client : public actor<InterfaceType> { //ptr<InterfaceType,fc::json::detail::rpc_member> {
|
||||||
public:
|
public:
|
||||||
rpc_client(){}
|
rpc_client(){}
|
||||||
rpc_client( const rpc_connection::ptr& c ):_con(c){
|
rpc_client( const rpc_connection::ptr& c ){ set_connection(c); }
|
||||||
init();
|
//rpc_client( const rpc_client& c ):_con(c._con){}
|
||||||
}
|
|
||||||
rpc_client( const rpc_client& c ):_con(c._con){}
|
|
||||||
|
|
||||||
void set_connection( const rpc_connection::ptr& c ) {
|
void set_connection( const rpc_connection::ptr& c ) {
|
||||||
_con = c;
|
_con = c;
|
||||||
init();
|
this->_vtable.reset(new fc::detail::vtable<InterfaceType,fc::detail::actor_member>() );
|
||||||
|
this->_vtable->template visit_other<InterfaceType>( fc::json::detail::vtable_visitor(_con) );
|
||||||
}
|
}
|
||||||
const rpc_connection& connection()const { return _con; }
|
const rpc_connection& connection()const { return _con; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init() {
|
|
||||||
this->_vtable.reset(new fc::detail::vtable<InterfaceType,fc::json::detail::rpc_member>() );
|
|
||||||
this->_vtable->template visit_other<InterfaceType>( fc::json::detail::vtable_visitor(_con) );
|
|
||||||
}
|
|
||||||
rpc_connection::ptr _con;
|
rpc_connection::ptr _con;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,16 @@ namespace fc {
|
||||||
} // else !_valid && !o._valid == same!
|
} // else !_valid && !o._valid == same!
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
optional& operator=( optional&& o ) {
|
||||||
|
if( _valid && o._valid ) { **this = fc::move(*o); }
|
||||||
|
else if( !_valid && o._valid ) {
|
||||||
|
*this = fc::move(*o);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator!()const { return !_valid; }
|
bool operator!()const { return !_valid; }
|
||||||
|
operator bool()const { return _valid; }
|
||||||
|
|
||||||
T& operator*() { void* v = &_value[0]; return *static_cast<T*>(v); }
|
T& operator*() { void* v = &_value[0]; return *static_cast<T*>(v); }
|
||||||
const T& operator*()const { const void* v = &_value[0]; return *static_cast<const T*>(v); }
|
const T& operator*()const { const void* v = &_value[0]; return *static_cast<const T*>(v); }
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ namespace fc {
|
||||||
public:
|
public:
|
||||||
stringstream();
|
stringstream();
|
||||||
stringstream( fc::string& s);
|
stringstream( fc::string& s);
|
||||||
|
stringstream( const fc::string& s);
|
||||||
~stringstream();
|
~stringstream();
|
||||||
|
|
||||||
fc::string str();
|
fc::string str();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef _FC_STRING_HPP_
|
#ifndef _FC_STRING_HPP_
|
||||||
#define _FC_STRING_HPP_
|
#define _FC_STRING_HPP_
|
||||||
#include <stdint.h>
|
#include <fc/utility.hpp>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,6 +34,7 @@ namespace fc {
|
||||||
public:
|
public:
|
||||||
typedef char* iterator;
|
typedef char* iterator;
|
||||||
typedef const char* const_iterator;
|
typedef const char* const_iterator;
|
||||||
|
static const size_t npos = -1;
|
||||||
|
|
||||||
string();
|
string();
|
||||||
string( const std::string& s );
|
string( const std::string& s );
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ namespace fc {
|
||||||
impl( fc::string&s )
|
impl( fc::string&s )
|
||||||
:ss( s )
|
:ss( s )
|
||||||
{ }
|
{ }
|
||||||
|
impl( const fc::string&s )
|
||||||
|
:ss( s )
|
||||||
|
{ }
|
||||||
impl(){}
|
impl(){}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
@ -17,6 +20,9 @@ namespace fc {
|
||||||
stringstream::stringstream( fc::string& s )
|
stringstream::stringstream( fc::string& s )
|
||||||
:my(s) {
|
:my(s) {
|
||||||
}
|
}
|
||||||
|
stringstream::stringstream( const fc::string& s )
|
||||||
|
:my(s) {
|
||||||
|
}
|
||||||
stringstream::stringstream(){}
|
stringstream::stringstream(){}
|
||||||
stringstream::~stringstream(){}
|
stringstream::~stringstream(){}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue