Merge branch 'master' of github.com:bytemaster/fc
This commit is contained in:
commit
34a723cf7a
4 changed files with 53 additions and 19 deletions
|
|
@ -57,20 +57,13 @@ namespace fc { namespace json {
|
||||||
template<typename X> \
|
template<typename X> \
|
||||||
static value to_value( X&& x ) { return value( x.a0 ); }\
|
static value to_value( X&& x ) { return value( x.a0 ); }\
|
||||||
}; \
|
}; \
|
||||||
template<> \
|
|
||||||
struct named_param< fc::tuple<T&> > { \
|
|
||||||
typedef fc::true_type type; \
|
|
||||||
static tuple<T> cast( const value& v ) { return make_tuple(fc::value_cast<T>(v)); } \
|
|
||||||
template<typename X> \
|
|
||||||
static value to_value( X&& x ) { return value( x.a0 ); }\
|
|
||||||
}; \
|
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
template<typename R, typename ArgsTuple, typename Signature>
|
template<typename R, typename ArgsTuple, typename Signature>
|
||||||
struct rpc_server_method_impl : public rpc_server_method {
|
struct rpc_server_method_impl : public rpc_server_method {
|
||||||
rpc_server_method_impl( const std::function<Signature>& f ):func(f){}
|
rpc_server_method_impl( const std::function<Signature>& f ):func(f){}
|
||||||
virtual value call( const value& v ) {
|
virtual value call( const value& v ) {
|
||||||
return value( call_fused(func, named_param<ArgsTuple>::cast(v) ) );
|
return value( fc::call_fused(func, named_param<typename deduce<ArgsTuple>::type>::cast(v) ) );
|
||||||
}
|
}
|
||||||
std::function<Signature> func;
|
std::function<Signature> func;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,10 @@ namespace fc {
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void visit( V&& v)const{};
|
void visit( V&& v)const{};
|
||||||
};
|
};
|
||||||
|
template<typename Functor, typename Tuple>
|
||||||
|
auto call_fused( Functor f, Tuple&& t ) -> decltype( f( ) ) {
|
||||||
|
return f();
|
||||||
|
}
|
||||||
|
|
||||||
inline tuple<> make_tuple(){ return tuple<>(); }
|
inline tuple<> make_tuple(){ return tuple<>(); }
|
||||||
|
|
||||||
|
|
@ -73,6 +77,7 @@ namespace fc {
|
||||||
#define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) )
|
#define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) )
|
||||||
#define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n));
|
#define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n));
|
||||||
#define LIST_MEMBERS_ON(z,n,data) data.BOOST_PP_CAT(a,n)
|
#define LIST_MEMBERS_ON(z,n,data) data.BOOST_PP_CAT(a,n)
|
||||||
|
#define DEDUCE_MEMBERS(z,n,data) typename fc::deduce<BOOST_PP_CAT(AA,n)>::type
|
||||||
#define FORWARD_PARAMS(z,n,data) fc::forward<BOOST_PP_CAT(AA,n)>(BOOST_PP_CAT(a,n))
|
#define FORWARD_PARAMS(z,n,data) fc::forward<BOOST_PP_CAT(AA,n)>(BOOST_PP_CAT(a,n))
|
||||||
#define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n);
|
#define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n);
|
||||||
#define TUPLE(z,n,unused) \
|
#define TUPLE(z,n,unused) \
|
||||||
|
|
@ -102,12 +107,17 @@ namespace fc {
|
||||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||||
struct is_tuple<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
|
struct is_tuple<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
|
||||||
typedef fc::true_type type; \
|
typedef fc::true_type type; \
|
||||||
};
|
}; \
|
||||||
|
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||||
|
struct deduce<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
|
||||||
|
typedef fc::tuple<BOOST_PP_ENUM( n, DEDUCE_MEMBERS,unused)> type; \
|
||||||
|
};
|
||||||
|
|
||||||
BOOST_PP_REPEAT_FROM_TO( 1, 8, TUPLE, unused )
|
BOOST_PP_REPEAT_FROM_TO( 1, 8, TUPLE, unused )
|
||||||
|
|
||||||
|
|
||||||
#undef FORWARD_PARAMS
|
#undef FORWARD_PARAMS
|
||||||
|
#undef DEDUCE_MEMBERS
|
||||||
#undef RREF_PARAMS
|
#undef RREF_PARAMS
|
||||||
#undef LIST_MEMBERS_ON
|
#undef LIST_MEMBERS_ON
|
||||||
#undef ILIST_PARAMS
|
#undef ILIST_PARAMS
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <fc/numeric_cast.hpp>
|
#include <fc/numeric_cast.hpp>
|
||||||
#include <fc/value_io.hpp>
|
#include <fc/value_io.hpp>
|
||||||
#include <fc/tuple.hpp>
|
#include <fc/tuple.hpp>
|
||||||
|
#include <fc/vector.hpp>
|
||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
|
|
@ -107,6 +108,40 @@ namespace fc {
|
||||||
private:
|
private:
|
||||||
value::object& m_out;
|
value::object& m_out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct cast_visitor<fc::vector<T>> : value::const_visitor {
|
||||||
|
cast_visitor( fc::vector<T>& out )
|
||||||
|
:m_out(out){}
|
||||||
|
virtual void operator()( const int8_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const int16_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const int32_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const int64_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const uint8_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const uint16_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const uint32_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const uint64_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const float& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const double& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const bool& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const fc::string& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const value::object& a ) { FC_THROW_MSG("bad cast");}
|
||||||
|
virtual void operator()( const value::array& a ) {
|
||||||
|
m_out.resize(0);
|
||||||
|
m_out.reserve( a.fields.size() );
|
||||||
|
for( auto i = a.fields.begin(); i != a.fields.end(); ++i ) {
|
||||||
|
m_out.push_back( value_cast<T>( *i ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void operator()( ) { FC_THROW_MSG("bad cast");}
|
||||||
|
|
||||||
|
private:
|
||||||
|
fc::vector<T>& m_out;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct cast_visitor<void> : value::value::const_visitor {
|
struct cast_visitor<void> : value::value::const_visitor {
|
||||||
virtual void operator()( const int8_t& v ) { FC_THROW_MSG("bad cast");}
|
virtual void operator()( const int8_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
|
@ -130,8 +165,8 @@ namespace fc {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static T cast( const value& v ) {
|
static T cast( const value& v ) {
|
||||||
slog( "cast non tuple %s", typeid(T).name() );
|
slog( "cast non tuple %s", typeid(T).name() );
|
||||||
T out;
|
typename fc::deduce<T>::type out;
|
||||||
v.visit(cast_visitor<T>(out));
|
v.visit(cast_visitor<decltype(out)>(out));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -149,12 +184,10 @@ namespace fc {
|
||||||
int idx;
|
int idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename Tuple>
|
||||||
static T cast( const value& v ) {
|
static Tuple cast( const value& v ) {
|
||||||
T out;
|
typename fc::deduce<Tuple>::type out;
|
||||||
out.visit( member_visitor(v) );
|
out.visit( member_visitor(v) );
|
||||||
slog( "cast tuple" );
|
|
||||||
// v.visit(cast_visitor<T>(out));
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -219,7 +252,7 @@ namespace fc {
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T value_cast( const value& v ) {
|
T value_cast( const value& v ) {
|
||||||
return detail::cast_if_reflected<typename fc::reflector<T>::is_defined>::template cast<T>(v);
|
return detail::cast_if_reflected<typename fc::reflector<typename fc::deduce<T>::type>::is_defined>::template cast< typename fc::deduce<T>::type >(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@
|
||||||
#else
|
#else
|
||||||
namespace fc {
|
namespace fc {
|
||||||
template<typename T> class vector;
|
template<typename T> class vector;
|
||||||
template<typename T> struct reflector;
|
|
||||||
template<typename T> struct reflector< fc::vector<T> >;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue