Updates from BitShares FC #22
26 changed files with 158 additions and 181 deletions
|
|
@ -99,41 +99,48 @@ namespace fc {
|
|||
|
||||
|
||||
template<typename T>
|
||||
void to_variant( const flat_set<T>& var, variant& vo )
|
||||
void to_variant( const flat_set<T>& var, variant& vo, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
--_max_depth;
|
||||
std::vector<variant> vars(var.size());
|
||||
size_t i = 0;
|
||||
for( auto itr = var.begin(); itr != var.end(); ++itr, ++i )
|
||||
vars[i] = variant(*itr);
|
||||
for( const auto& item : var )
|
||||
vars[i++] = variant( item, _max_depth );
|
||||
vo = vars;
|
||||
}
|
||||
template<typename T>
|
||||
void from_variant( const variant& var, flat_set<T>& vo )
|
||||
void from_variant( const variant& var, flat_set<T>& vo, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
--_max_depth;
|
||||
const variants& vars = var.get_array();
|
||||
vo.clear();
|
||||
vo.reserve( vars.size() );
|
||||
for( auto itr = vars.begin(); itr != vars.end(); ++itr )
|
||||
vo.insert( itr->as<T>() );
|
||||
for( const auto& item : vars )
|
||||
vo.insert( item.as<T>(_max_depth) );
|
||||
}
|
||||
|
||||
template<typename K, typename... T>
|
||||
void to_variant( const flat_map<K, T...>& var, variant& vo )
|
||||
void to_variant( const flat_map<K, T...>& var, variant& vo, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
--_max_depth;
|
||||
std::vector< variant > vars(var.size());
|
||||
size_t i = 0;
|
||||
for( auto itr = var.begin(); itr != var.end(); ++itr, ++i )
|
||||
vars[i] = fc::variant(*itr);
|
||||
for( const auto& item : var )
|
||||
vars[i++] = variant( item, _max_depth );
|
||||
vo = vars;
|
||||
}
|
||||
template<typename K, typename T, typename... A>
|
||||
void from_variant( const variant& var, flat_map<K, T, A...>& vo )
|
||||
void from_variant( const variant& var, flat_map<K, T, A...>& vo, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
--_max_depth;
|
||||
const variants& vars = var.get_array();
|
||||
vo.clear();
|
||||
for( auto itr = vars.begin(); itr != vars.end(); ++itr )
|
||||
vo.insert( itr->as< std::pair<K,T> >() );
|
||||
|
||||
for( const auto& item : vars )
|
||||
vo.insert( item.as<std::pair<K,T>>(_max_depth) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ namespace fc {
|
|||
|
||||
class variant;
|
||||
/** encodes the big int as base64 string, or a number */
|
||||
void to_variant( const bigint& bi, variant& v );
|
||||
void to_variant( const bigint& bi, variant& v, uint32_t max_depth = 1 );
|
||||
/** decodes the big int as base64 string, or a number */
|
||||
void from_variant( const variant& v, bigint& bi );
|
||||
void from_variant( const variant& v, bigint& bi, uint32_t max_depth = 1 );
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -108,10 +108,10 @@ namespace fc {
|
|||
}
|
||||
}
|
||||
class variant;
|
||||
void to_variant( const public_key& bi, variant& v );
|
||||
void from_variant( const variant& v, public_key& bi );
|
||||
void to_variant( const private_key& bi, variant& v );
|
||||
void from_variant( const variant& v, private_key& bi );
|
||||
void to_variant( const public_key& bi, variant& v, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& v, public_key& bi, uint32_t max_depth = 1 );
|
||||
void to_variant( const private_key& bi, variant& v, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& v, private_key& bi, uint32_t max_depth = 1 );
|
||||
|
||||
} // fc
|
||||
|
||||
|
|
|
|||
|
|
@ -121,43 +121,23 @@ namespace fc {
|
|||
left -= 1024;
|
||||
}
|
||||
s.read( buf, left );
|
||||
|
||||
/*
|
||||
s.seekp( s.tellp() + (size.value - sizeof(Storage)) );
|
||||
char tmp;
|
||||
size.value -= sizeof(storage);
|
||||
while( size.value ){ s.read( &tmp, 1 ); --size.value; }
|
||||
*/
|
||||
// s.skip( size.value - sizeof(Storage) );
|
||||
} else {
|
||||
s.read( (char*)&u.data, size.value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
template<typename Stream, typename... Args>
|
||||
inline void pack( Stream& s, const boost::multiprecision::number<Args...>& d, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
|
||||
s.write( (const char*)&d, sizeof(d) );
|
||||
}
|
||||
|
||||
template<typename Stream, typename... Args>
|
||||
inline void unpack( Stream& s, boost::multiprecision::number<Args...>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
|
||||
s.read( (const char*)&u, sizeof(u) );
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#include <fc/variant.hpp>
|
||||
namespace fc {
|
||||
template<typename Storage>
|
||||
void to_variant( const fixed_string<Storage>& s, variant& v ) {
|
||||
void to_variant( const fixed_string<Storage>& s, variant& v, uint32_t max_depth = 1 ) {
|
||||
v = std::string(s);
|
||||
}
|
||||
|
||||
template<typename Storage>
|
||||
void from_variant( const variant& v, fixed_string<Storage>& s ) {
|
||||
void from_variant( const variant& v, fixed_string<Storage>& s, uint32_t max_depth = 1 ) {
|
||||
s = v.as_string();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <boost/interprocess/containers/set.hpp>
|
||||
#include <boost/interprocess/containers/deque.hpp>
|
||||
#include <fc/crypto/hex.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -16,87 +17,76 @@ namespace fc {
|
|||
namespace bip = boost::interprocess;
|
||||
|
||||
template<typename... T >
|
||||
void to_variant( const bip::deque< T... >& t, fc::variant& v ) {
|
||||
void to_variant( const bip::deque< T... >& t, fc::variant& v, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector<variant> vars(t.size());
|
||||
for( size_t i = 0; i < t.size(); ++i ) {
|
||||
vars[i] = t[i];
|
||||
to_variant( t[i], vars[i], max_depth );
|
||||
}
|
||||
v = std::move(vars);
|
||||
}
|
||||
|
||||
template<typename T, typename... A>
|
||||
void from_variant( const fc::variant& v, bip::deque< T, A... >& d ) {
|
||||
void from_variant( const fc::variant& v, bip::deque< T, A... >& d, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
const variants& vars = v.get_array();
|
||||
d.clear();
|
||||
d.resize( vars.size() );
|
||||
for( uint32_t i = 0; i < vars.size(); ++i ) {
|
||||
from_variant( vars[i], d[i] );
|
||||
from_variant( vars[i], d[i], max_depth );
|
||||
}
|
||||
}
|
||||
|
||||
//bip::map == boost::map
|
||||
template<typename K, typename V, typename... T >
|
||||
void to_variant( const bip::map< K, V, T... >& var, fc::variant& vo ) {
|
||||
void to_variant( const bip::map< K, V, T... >& var, fc::variant& vo, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector< variant > vars(var.size());
|
||||
size_t i = 0;
|
||||
for( auto itr = var.begin(); itr != var.end(); ++itr, ++i )
|
||||
vars[i] = fc::variant(*itr);
|
||||
vars[i] = fc::variant( *itr, max_depth );
|
||||
vo = vars;
|
||||
}
|
||||
/*
|
||||
template<typename K, typename V, typename... A>
|
||||
void from_variant( const variant& var, bip::map<K, V, A...>& vo )
|
||||
{
|
||||
const variants& vars = var.get_array();
|
||||
vo.clear();
|
||||
for( auto itr = vars.begin(); itr != vars.end(); ++itr )
|
||||
vo.insert( itr->as< std::pair<K,V> >() ); Not safe for interprocess. Needs allocator
|
||||
}
|
||||
*/
|
||||
|
||||
template<typename... T >
|
||||
void to_variant( const bip::vector< T... >& t, fc::variant& v ) {
|
||||
void to_variant( const bip::vector< T... >& t, fc::variant& v, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector<variant> vars(t.size());
|
||||
for( size_t i = 0; i < t.size(); ++i ) {
|
||||
vars[i] = t[i];
|
||||
to_variant( t[i], vars[i], max_depth );
|
||||
}
|
||||
v = std::move(vars);
|
||||
}
|
||||
|
||||
template<typename T, typename... A>
|
||||
void from_variant( const fc::variant& v, bip::vector< T, A... >& d ) {
|
||||
void from_variant( const fc::variant& v, bip::vector< T, A... >& d, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
const variants& vars = v.get_array();
|
||||
d.clear();
|
||||
d.resize( vars.size() );
|
||||
for( uint32_t i = 0; i < vars.size(); ++i ) {
|
||||
from_variant( vars[i], d[i] );
|
||||
from_variant( vars[i], d[i], max_depth );
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... T >
|
||||
void to_variant( const bip::set< T... >& t, fc::variant& v ) {
|
||||
void to_variant( const bip::set< T... >& t, fc::variant& v, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector<variant> vars;
|
||||
vars.reserve(t.size());
|
||||
for( const auto& item : t ) {
|
||||
vars.emplace_back( item );
|
||||
vars.emplace_back( variant( item, max_depth ) );
|
||||
}
|
||||
v = std::move(vars);
|
||||
}
|
||||
|
||||
/*
|
||||
template<typename T, typename... A>
|
||||
void from_variant( const fc::variant& v, bip::set< T, A... >& d ) {
|
||||
const variants& vars = v.get_array();
|
||||
d.clear();
|
||||
d.reserve( vars.size() );
|
||||
for( uint32_t i = 0; i < vars.size(); ++i ) {
|
||||
from_variant( vars[i], d[i] ); Not safe for interprocess. Needs allocator
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
template<typename... A>
|
||||
void to_variant( const bip::vector<char, A...>& t, fc::variant& v )
|
||||
void to_variant( const bip::vector<char, A...>& t, fc::variant& v, uint32_t max_depth = 1 )
|
||||
{
|
||||
if( t.size() )
|
||||
v = variant(fc::to_hex(t.data(), t.size()));
|
||||
|
|
@ -105,7 +95,7 @@ namespace fc {
|
|||
}
|
||||
|
||||
template<typename... A>
|
||||
void from_variant( const fc::variant& v, bip::vector<char, A...>& d )
|
||||
void from_variant( const fc::variant& v, bip::vector<char, A...>& d, uint32_t max_depth = 1 )
|
||||
{
|
||||
auto str = v.as_string();
|
||||
d.resize( str.size() / 2 );
|
||||
|
|
@ -114,8 +104,6 @@ namespace fc {
|
|||
size_t r = fc::from_hex( str, d.data(), d.size() );
|
||||
FC_ASSERT( r == d.size() );
|
||||
}
|
||||
// std::string b64 = base64_decode( var.as_string() );
|
||||
// vo = std::vector<char>( b64.c_str(), b64.c_str() + b64.size() );
|
||||
}
|
||||
|
||||
namespace raw {
|
||||
|
|
|
|||
|
|
@ -48,14 +48,14 @@ namespace fc
|
|||
|
||||
|
||||
template<typename IntType, typename EnumType>
|
||||
void to_variant( const enum_type<IntType,EnumType>& var, variant& vo )
|
||||
void to_variant( const enum_type<IntType,EnumType>& var, variant& vo, uint32_t max_depth = 1 )
|
||||
{
|
||||
vo = (EnumType)var.value;
|
||||
to_variant( var.value, vo, max_depth );
|
||||
}
|
||||
template<typename IntType, typename EnumType>
|
||||
void from_variant( const variant& var, enum_type<IntType,EnumType>& vo )
|
||||
void from_variant( const variant& var, enum_type<IntType,EnumType>& vo, uint32_t max_depth )
|
||||
{
|
||||
vo.value = var.as<EnumType>();
|
||||
vo.value = var.as<EnumType>(1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,10 +70,10 @@ struct signed_int {
|
|||
|
||||
class variant;
|
||||
|
||||
void to_variant( const signed_int& var, variant& vo );
|
||||
void from_variant( const variant& var, signed_int& vo );
|
||||
void to_variant( const unsigned_int& var, variant& vo );
|
||||
void from_variant( const variant& var, unsigned_int& vo );
|
||||
void to_variant( const signed_int& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, signed_int& vo, uint32_t max_depth = 1 );
|
||||
void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth = 1 );
|
||||
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ namespace fc {
|
|||
|
||||
}
|
||||
class variant;
|
||||
void to_variant( const ip::endpoint& var, variant& vo );
|
||||
void from_variant( const variant& var, ip::endpoint& vo );
|
||||
void to_variant( const ip::endpoint& var, variant& vo, uint32_t _max_depth = 2 );
|
||||
void from_variant( const variant& var, ip::endpoint& vo, uint32_t _max_depth = 2 );
|
||||
|
||||
void to_variant( const ip::address& var, variant& vo );
|
||||
void from_variant( const variant& var, ip::address& vo );
|
||||
void to_variant( const ip::address& var, variant& vo, uint32_t _max_depth = 1 );
|
||||
void from_variant( const variant& var, ip::address& vo, uint32_t _max_depth = 1 );
|
||||
|
||||
|
||||
namespace raw
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ namespace fc {
|
|||
std::shared_ptr<detail::url_impl> my;
|
||||
};
|
||||
|
||||
void to_variant( const url& u, fc::variant& v );
|
||||
void from_variant( const fc::variant& v, url& u );
|
||||
void to_variant( const url& u, fc::variant& v, uint32_t max_depth = 1 );
|
||||
void from_variant( const fc::variant& v, url& u, uint32_t max_depth = 1 );
|
||||
|
||||
/**
|
||||
* Used to create / manipulate a URL
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ namespace fc {
|
|||
uint128 fixed;
|
||||
};
|
||||
|
||||
void to_variant( const real128& var, variant& vo );
|
||||
void from_variant( const variant& var, real128& vo );
|
||||
void to_variant( const real128& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, real128& vo, uint32_t max_depth = 1 );
|
||||
|
||||
namespace raw
|
||||
{
|
||||
|
|
|
|||
|
|
@ -63,22 +63,22 @@ namespace fc
|
|||
const uint32_t _max_depth;
|
||||
};
|
||||
|
||||
template<typename IsReflected=fc::false_type>
|
||||
struct if_enum
|
||||
{
|
||||
template<typename T>
|
||||
static inline void to_variant( const T& v, fc::variant& vo, uint32_t max_depth )
|
||||
{
|
||||
template<typename IsEnum=fc::false_type>
|
||||
struct if_enum
|
||||
{
|
||||
template<typename T>
|
||||
static inline void to_variant( const T& v, fc::variant& vo, uint32_t max_depth )
|
||||
{
|
||||
mutable_variant_object mvo;
|
||||
fc::reflector<T>::visit( to_variant_visitor<T>( mvo, v, max_depth ) );
|
||||
vo = fc::move(mvo);
|
||||
}
|
||||
template<typename T>
|
||||
static inline void from_variant( const fc::variant& v, T& o, uint32_t max_depth )
|
||||
{
|
||||
}
|
||||
template<typename T>
|
||||
static inline void from_variant( const fc::variant& v, T& o, uint32_t max_depth )
|
||||
{
|
||||
const variant_object& vo = v.get_object();
|
||||
fc::reflector<T>::visit( from_variant_visitor<T>( vo, o, max_depth ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace fc { namespace rpc {
|
|||
class cli : public api_connection
|
||||
{
|
||||
public:
|
||||
cli( uint32_t max_depth ) : api_connection(max_depth) {}
|
||||
~cli();
|
||||
|
||||
virtual variant send_call( api_id_type api_id, string method_name, variants args = variants() );
|
||||
|
|
|
|||
|
|
@ -346,42 +346,45 @@ struct visitor {
|
|||
struct from_static_variant
|
||||
{
|
||||
variant& var;
|
||||
from_static_variant( variant& dv ):var(dv){}
|
||||
const uint32_t _max_depth;
|
||||
from_static_variant( variant& dv, uint32_t max_depth ):var(dv),_max_depth(max_depth){}
|
||||
|
||||
typedef void result_type;
|
||||
template<typename T> void operator()( const T& v )const
|
||||
{
|
||||
to_variant( v, var );
|
||||
to_variant( v, var, _max_depth );
|
||||
}
|
||||
};
|
||||
|
||||
struct to_static_variant
|
||||
{
|
||||
const variant& var;
|
||||
to_static_variant( const variant& dv ):var(dv){}
|
||||
const uint32_t _max_depth;
|
||||
to_static_variant( const variant& dv, uint32_t max_depth ):var(dv),_max_depth(max_depth){}
|
||||
|
||||
typedef void result_type;
|
||||
template<typename T> void operator()( T& v )const
|
||||
{
|
||||
from_variant( var, v );
|
||||
from_variant( var, v, _max_depth );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename... T> void to_variant( const fc::static_variant<T...>& s, fc::variant& v )
|
||||
template<typename... T> void to_variant( const fc::static_variant<T...>& s, fc::variant& v, uint32_t max_depth )
|
||||
{
|
||||
variant tmp;
|
||||
FC_ASSERT( max_depth > 0 );
|
||||
variants vars(2);
|
||||
vars[0] = s.which();
|
||||
s.visit( from_static_variant(vars[1]) );
|
||||
s.visit( from_static_variant(vars[1], max_depth - 1) );
|
||||
v = std::move(vars);
|
||||
}
|
||||
template<typename... T> void from_variant( const fc::variant& v, fc::static_variant<T...>& s )
|
||||
template<typename... T> void from_variant( const fc::variant& v, fc::static_variant<T...>& s, uint32_t max_depth )
|
||||
{
|
||||
FC_ASSERT( max_depth > 0 );
|
||||
auto ar = v.get_array();
|
||||
if( ar.size() < 2 ) return;
|
||||
s.set_which( ar[0].as_uint64() );
|
||||
s.visit( to_static_variant(ar[1]) );
|
||||
s.visit( to_static_variant(ar[1], max_depth - 1) );
|
||||
}
|
||||
|
||||
template<typename... T> struct get_typename { static const char* name() { return typeid(static_variant<T...>).name(); } };
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ namespace fc {
|
|||
inline microseconds days(int64_t d) { return hours(24*d); }
|
||||
|
||||
class variant;
|
||||
void to_variant( const fc::microseconds&, fc::variant& );
|
||||
void from_variant( const fc::variant& , fc::microseconds& );
|
||||
void to_variant( const fc::microseconds&, fc::variant&, uint32_t max_depth = 1 );
|
||||
void from_variant( const fc::variant&, fc::microseconds&, uint32_t max_depth = 1 );
|
||||
|
||||
class time_point {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ namespace fc
|
|||
|
||||
class variant;
|
||||
|
||||
void to_variant( const uint128& var, variant& vo );
|
||||
void from_variant( const variant& var, uint128& vo );
|
||||
void to_variant( const uint128& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, uint128& vo, uint32_t max_depth = 1 );
|
||||
|
||||
namespace raw
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ namespace fc
|
|||
* for your Serializable_type
|
||||
*
|
||||
* @code
|
||||
* void to_variant( const Serializable_type& e, variant& v );
|
||||
* void from_variant( const variant& e, Serializable_type& ll );
|
||||
* void to_variant( const Serializable_type& e, variant& v, uint32_t max_depth );
|
||||
* void from_variant( const variant& e, Serializable_type& ll, uint32_t max_depth );
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
|
|
@ -89,6 +89,9 @@ namespace fc
|
|||
/** @ingroup Serializable */
|
||||
void from_variant( const variant& var, int32_t& vo, uint32_t max_depth = 1 );
|
||||
|
||||
void to_variant( const uint64_t& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void to_variant( const int64_t& var, variant& vo, uint32_t max_depth = 1 );
|
||||
|
||||
void to_variant( const variant_object& var, variant& vo, uint32_t max_depth );
|
||||
void from_variant( const variant& var, variant_object& vo, uint32_t max_depth );
|
||||
void to_variant( const mutable_variant_object& var, variant& vo, uint32_t max_depth );
|
||||
|
|
@ -146,7 +149,7 @@ namespace fc
|
|||
void from_variant( const variant& input_variant, microseconds& output_microseconds, uint32_t max_depth );
|
||||
|
||||
#ifdef __APPLE__
|
||||
void to_variant( size_t s, variant& v );
|
||||
void to_variant( size_t s, variant& v, uint32_t max_depth = 1 );
|
||||
#elif !defined(_MSC_VER)
|
||||
void to_variant( long long int s, variant& v, uint32_t max_depth = 1 );
|
||||
void to_variant( unsigned long long int s, variant& v, uint32_t max_depth = 1 );
|
||||
|
|
@ -301,7 +304,7 @@ namespace fc
|
|||
* following method to implement conversion from variant to T.
|
||||
*
|
||||
* <code>
|
||||
* void from_variant( const Variant& var, T& val )
|
||||
* void from_variant( const Variant& var, T& val, uint32_t max_depth )
|
||||
* </code>
|
||||
*
|
||||
* The above form is not always convienant, so the this templated
|
||||
|
|
@ -558,7 +561,7 @@ namespace fc
|
|||
to_variant( val, *this, max_depth );
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
inline void to_variant( size_t s, variant& v ) { v = variant(uint64_t(s)); }
|
||||
inline void to_variant( size_t s, variant& v, uint32_t max_depth = 1 ) { v = variant(uint64_t(s)); }
|
||||
#endif
|
||||
template<typename T>
|
||||
void to_variant( const std::shared_ptr<T>& var, variant& vo, uint32_t max_depth )
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ namespace fc
|
|||
friend class mutable_variant_object;
|
||||
};
|
||||
/** @ingroup Serializable */
|
||||
void to_variant( const variant_object& var, variant& vo );
|
||||
void to_variant( const variant_object& var, variant& vo, uint32_t max_depth = 1 );
|
||||
/** @ingroup Serializable */
|
||||
void from_variant( const variant& var, variant_object& vo );
|
||||
void from_variant( const variant& var, variant_object& vo, uint32_t max_depth = 1 );
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -229,6 +229,7 @@ namespace fc
|
|||
set( std::move(key), variant( fc::forward<T>(var), _max_depth ) );
|
||||
return *this;
|
||||
}
|
||||
limited_mutable_variant_object& operator()( const variant_object& vo );
|
||||
|
||||
private:
|
||||
const uint32_t _max_depth;
|
||||
|
|
|
|||
|
|
@ -128,14 +128,14 @@ namespace fc {
|
|||
}
|
||||
bigint bigint::operator / ( const bigint& a ) const {
|
||||
BN_CTX* ctx = BN_CTX_new();
|
||||
bigint tmp;//(*this);
|
||||
bigint tmp;
|
||||
BN_div( tmp.n, NULL, n, a.n, ctx );
|
||||
BN_CTX_free(ctx);
|
||||
return tmp;
|
||||
}
|
||||
bigint bigint::operator % ( const bigint& a ) const {
|
||||
BN_CTX* ctx = BN_CTX_new();
|
||||
bigint tmp;//(*this);
|
||||
bigint tmp;
|
||||
BN_mod( tmp.n, n, a.n, ctx );
|
||||
BN_CTX_free(ctx);
|
||||
return tmp;
|
||||
|
|
@ -143,7 +143,7 @@ namespace fc {
|
|||
|
||||
bigint bigint::operator /= ( const bigint& a ) {
|
||||
BN_CTX* ctx = BN_CTX_new();
|
||||
bigint tmp;//*this);
|
||||
bigint tmp;
|
||||
BN_div( tmp.n, NULL, n, a.n, ctx );
|
||||
fc_swap( tmp.n, n );
|
||||
BN_CTX_free(ctx);
|
||||
|
|
@ -188,6 +188,8 @@ namespace fc {
|
|||
|
||||
|
||||
bigint& bigint::operator = ( bigint&& a ) {
|
||||
if( &a == this )
|
||||
return *this;
|
||||
fc_swap( a.n, n );
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -208,14 +210,14 @@ namespace fc {
|
|||
}
|
||||
|
||||
/** encodes the big int as base64 string, or a number */
|
||||
void to_variant( const bigint& bi, variant& v )
|
||||
void to_variant( const bigint& bi, variant& v, uint32_t max_depth )
|
||||
{
|
||||
std::vector<char> ve = bi;
|
||||
v = fc::variant(base64_encode((unsigned char*)ve.data(),ve.size()));
|
||||
}
|
||||
|
||||
/** decodes the big int as base64 string, or a number */
|
||||
void from_variant( const variant& v, bigint& bi )
|
||||
void from_variant( const variant& v, bigint& bi, uint32_t max_depth )
|
||||
{
|
||||
if( v.is_numeric() ) bi = bigint( static_cast<unsigned long>(v.as_uint64()) );
|
||||
else
|
||||
|
|
|
|||
|
|
@ -338,28 +338,28 @@ namespace fc {
|
|||
}
|
||||
|
||||
/** encodes the big int as base64 string, or a number */
|
||||
void to_variant( const public_key& bi, variant& v )
|
||||
void to_variant( const public_key& bi, variant& v, uint32_t max_depth )
|
||||
{
|
||||
v = bi.serialize();
|
||||
}
|
||||
|
||||
/** decodes the big int as base64 string, or a number */
|
||||
void from_variant( const variant& v, public_key& bi )
|
||||
void from_variant( const variant& v, public_key& bi, uint32_t max_depth )
|
||||
{
|
||||
bi = public_key( v.as<std::vector<char> >() );
|
||||
bi = public_key( v.as<std::vector<char> >(max_depth) );
|
||||
}
|
||||
|
||||
|
||||
/** encodes the big int as base64 string, or a number */
|
||||
void to_variant( const private_key& bi, variant& v )
|
||||
void to_variant( const private_key& bi, variant& v, uint32_t max_depth )
|
||||
{
|
||||
v = bi.serialize();
|
||||
}
|
||||
|
||||
/** decodes the big int as base64 string, or a number */
|
||||
void from_variant( const variant& v, private_key& bi )
|
||||
void from_variant( const variant& v, private_key& bi, uint32_t max_depth )
|
||||
{
|
||||
bi = private_key( v.as<std::vector<char> >() );
|
||||
bi = private_key( v.as<std::vector<char> >(max_depth) );
|
||||
}
|
||||
|
||||
} // fc
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
namespace fc
|
||||
{
|
||||
void to_variant( const signed_int& var, variant& vo ) { vo = var.value; }
|
||||
void from_variant( const variant& var, signed_int& vo ) { vo.value = static_cast<int32_t>(var.as_int64()); }
|
||||
void to_variant( const unsigned_int& var, variant& vo ) { vo = var.value; }
|
||||
void from_variant( const variant& var, unsigned_int& vo ) { vo.value = static_cast<uint32_t>(var.as_uint64()); }
|
||||
void to_variant( const signed_int& var, variant& vo, uint32_t max_depth ) { vo = var.value; }
|
||||
void from_variant( const variant& var, signed_int& vo, uint32_t max_depth ) { vo.value = static_cast<int32_t>(var.as_int64()); }
|
||||
void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth ) { vo = var.value; }
|
||||
void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth ) { vo.value = static_cast<uint32_t>(var.as_uint64()); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,20 +137,20 @@ namespace fc { namespace ip {
|
|||
|
||||
} // namespace ip
|
||||
|
||||
void to_variant( const ip::endpoint& var, variant& vo )
|
||||
void to_variant( const ip::endpoint& var, variant& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = fc::string(var);
|
||||
}
|
||||
void from_variant( const variant& var, ip::endpoint& vo )
|
||||
void from_variant( const variant& var, ip::endpoint& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = ip::endpoint::from_string(var.as_string());
|
||||
}
|
||||
|
||||
void to_variant( const ip::address& var, variant& vo )
|
||||
void to_variant( const ip::address& var, variant& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = fc::string(var);
|
||||
}
|
||||
void from_variant( const variant& var, ip::address& vo )
|
||||
void from_variant( const variant& var, ip::address& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = ip::address(var.as_string());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,11 +76,11 @@ namespace fc
|
|||
};
|
||||
}
|
||||
|
||||
void to_variant( const url& u, fc::variant& v )
|
||||
void to_variant( const url& u, fc::variant& v, uint32_t max_depth )
|
||||
{
|
||||
v = fc::string(u);
|
||||
}
|
||||
void from_variant( const fc::variant& v, url& u )
|
||||
void from_variant( const fc::variant& v, url& u, uint32_t max_depth )
|
||||
{
|
||||
u = url( v.as_string() );
|
||||
}
|
||||
|
|
@ -99,7 +99,6 @@ namespace fc
|
|||
if( my->_host.valid() ) ss<<*my->_host;
|
||||
if( my->_port.valid() ) ss<<":"<<*my->_port;
|
||||
if( my->_path.valid() ) ss<<my->_path->generic_string();
|
||||
// if( my->_args ) ss<<"?"<<*my->_args;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,11 +118,11 @@ namespace fc
|
|||
return result;
|
||||
}
|
||||
|
||||
void to_variant( const real128& var, variant& vo )
|
||||
void to_variant( const real128& var, variant& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = std::string(var);
|
||||
}
|
||||
void from_variant( const variant& var, real128& vo )
|
||||
void from_variant( const variant& var, real128& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = real128(var.as_string());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace fc
|
|||
template <typename T>
|
||||
static void divide(const T &numerator, const T &denominator, T "ient, T &remainder)
|
||||
{
|
||||
static const int bits = sizeof(T) * 8;//CHAR_BIT;
|
||||
static const int bits = sizeof(T) * 8;
|
||||
|
||||
if(denominator == 0) {
|
||||
throw std::domain_error("divide by zero");
|
||||
|
|
@ -228,22 +228,6 @@ namespace fc
|
|||
self /= other;
|
||||
hi = static_cast<uint64_t>(self >> 64);
|
||||
lo = static_cast<uint64_t>((self << 64 ) >> 64);
|
||||
|
||||
/*
|
||||
uint128 remainder;
|
||||
divide(*this, b, *this, remainder ); //, *this);
|
||||
if( tmp.hi != hi || tmp.lo != lo ) {
|
||||
std::cerr << tmp.hi << " " << hi <<"\n";
|
||||
std::cerr << tmp.lo << " " << lo << "\n";
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
const auto& b128 = std::reinterpret_cast<const m128&>(b);
|
||||
auto& this128 = std::reinterpret_cast<m128&>(*this);
|
||||
this128 /= b128;
|
||||
*/
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -344,8 +328,6 @@ namespace fc
|
|||
|
||||
result_hi = uint128( y[3], y[2] );
|
||||
result_lo = uint128( y[1], y[0] );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static uint8_t _popcount_64( uint64_t x )
|
||||
|
|
@ -374,8 +356,14 @@ namespace fc
|
|||
return _popcount_64( lo ) + _popcount_64( hi );
|
||||
}
|
||||
|
||||
void to_variant( const uint128& var, variant& vo ) { vo = std::string(var); }
|
||||
void from_variant( const variant& var, uint128& vo ){ vo = uint128(var.as_string()); }
|
||||
void to_variant( const uint128& var, variant& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = std::string(var);
|
||||
}
|
||||
void from_variant( const variant& var, uint128& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = uint128(var.as_string());
|
||||
}
|
||||
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -579,11 +579,6 @@ void from_variant( const variant& var, variants& vo, uint32_t max_depth )
|
|||
vo = var.get_array();
|
||||
}
|
||||
|
||||
//void from_variant( const variant& var, variant_object& vo )
|
||||
//{
|
||||
// vo = var.get_object();
|
||||
//}
|
||||
|
||||
void from_variant( const variant& var, variant& vo, uint32_t max_depth ) { vo = var; }
|
||||
|
||||
void to_variant( const uint8_t& var, variant& vo, uint32_t max_depth ) { vo = uint64_t(var); }
|
||||
|
|
@ -614,11 +609,13 @@ void from_variant( const variant& var,int32_t& vo, uint32_t max_depth )
|
|||
vo = static_cast<int32_t>(var.as_int64());
|
||||
}
|
||||
|
||||
void to_variant( const int64_t& var, variant& vo, uint32_t max_depth ) { vo = var; }
|
||||
void from_variant( const variant& var, int64_t& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = var.as_int64();
|
||||
}
|
||||
|
||||
void to_variant( const uint64_t& var, variant& vo, uint32_t max_depth ) { vo = var; }
|
||||
void from_variant( const variant& var, uint64_t& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = var.as_uint64();
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ namespace fc
|
|||
variant_object::variant_object( string key, variant val )
|
||||
: _key_value(std::make_shared<std::vector<entry>>())
|
||||
{
|
||||
//_key_value->push_back(entry(fc::move(key), fc::move(val)));
|
||||
_key_value->emplace_back(entry(fc::move(key), fc::move(val)));
|
||||
}
|
||||
|
||||
|
|
@ -367,14 +366,23 @@ namespace fc
|
|||
}
|
||||
|
||||
limited_mutable_variant_object::limited_mutable_variant_object( uint32_t m )
|
||||
: mutable_variant_object(), _max_depth(m) {}
|
||||
: mutable_variant_object(), _max_depth(m - 1)
|
||||
{
|
||||
FC_ASSERT( m > 0, "Recursion depth exceeded!" );
|
||||
}
|
||||
|
||||
void to_variant( const mutable_variant_object& var, variant& vo )
|
||||
limited_mutable_variant_object& limited_mutable_variant_object::operator()( const variant_object& vo )
|
||||
{
|
||||
mutable_variant_object::operator()( vo );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void to_variant( const mutable_variant_object& var, variant& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = variant(var);
|
||||
}
|
||||
|
||||
void from_variant( const variant& var, mutable_variant_object& vo )
|
||||
void from_variant( const variant& var, mutable_variant_object& vo, uint32_t max_depth )
|
||||
{
|
||||
vo = var.get_object();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue