bug fixes
This commit is contained in:
parent
5499d5bb30
commit
9909ef83b5
5 changed files with 54 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ namespace fc {
|
|||
explicit microseconds( int64_t c = 0) :_count(c){}
|
||||
static microseconds max() { return microseconds(0x7fffffffffffffffll); }
|
||||
friend microseconds operator + (const microseconds& l, const microseconds& r ) { return microseconds(l._count+r._count); }
|
||||
friend microseconds operator - (const microseconds& l, const microseconds& r ) { return microseconds(l._count-r._count); }
|
||||
|
||||
bool operator==(const microseconds& c)const { return _count == c._count; }
|
||||
friend bool operator>(const microseconds& a, const microseconds& b){ return a._count > b._count; }
|
||||
|
|
@ -41,6 +42,7 @@ namespace fc {
|
|||
bool operator !=( const time_point& t )const { return elapsed._count !=t.elapsed._count; }
|
||||
time_point& operator += ( const microseconds& m ) { elapsed+=m; return *this; }
|
||||
friend time_point operator + ( const time_point& t, const microseconds& m ) { return time_point(t.elapsed+m); }
|
||||
friend time_point operator - ( const time_point& t, const microseconds& m ) { return time_point(t.elapsed-m); }
|
||||
friend microseconds operator - ( const time_point& t, const time_point& m ) { return microseconds(t.elapsed.count() - m.elapsed.count()); }
|
||||
private:
|
||||
microseconds elapsed;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <fc/vector.hpp>
|
||||
#include <fc/typename.hpp>
|
||||
#include <fc/error_report.hpp>
|
||||
#include <vector>
|
||||
|
||||
//#include <typeinfo>
|
||||
|
||||
|
|
@ -34,6 +35,28 @@ namespace fc {
|
|||
void cast_value( const value& v, T& t) {
|
||||
unpack(v,t);
|
||||
}
|
||||
template<typename T>
|
||||
void cast_value( const value& v, std::vector<T>& out ) {
|
||||
if( v.type() != value::array_type ) {
|
||||
FC_THROW_REPORT( "Error casting ${type} to array", fc::value("type", fc::reflector<value::value_type>::to_string(v.type()) ) );
|
||||
}
|
||||
out.resize(v.size());
|
||||
slog( "out .size %d", out.size() );
|
||||
const fc::vector<value>& val = v.as_array();
|
||||
auto oitr = out.begin();
|
||||
int idx = 0;
|
||||
for( auto itr = val.begin(); itr != val.end(); ++itr, ++oitr, ++idx ) {
|
||||
try {
|
||||
*oitr = itr->cast<T>(); //value_cast<T>(*itr);
|
||||
// value_cast( *itr, *oitr );
|
||||
} catch ( fc::error_report& er ) {
|
||||
throw FC_REPORT_PUSH( er, "Error casting value[${index}] to ${type}",
|
||||
fc::value("index",idx)
|
||||
("type", fc::get_typename<T>::name())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void cast_value( const value& v, fc::vector<T>& out ) {
|
||||
|
|
@ -41,12 +64,13 @@ namespace fc {
|
|||
FC_THROW_REPORT( "Error casting ${type} to array", fc::value("type", fc::reflector<value::value_type>::to_string(v.type()) ) );
|
||||
}
|
||||
out.resize(v.size());
|
||||
slog( "out .size %d", out.size() );
|
||||
const fc::vector<value>& val = v.as_array();
|
||||
auto oitr = out.begin();
|
||||
int idx = 0;
|
||||
for( auto itr = val.begin(); itr != val.end(); ++itr, ++oitr, ++idx ) {
|
||||
try {
|
||||
*oitr = value_cast<T>(*itr);
|
||||
*oitr = itr->cast<T>(); //value_cast<T>(*itr);
|
||||
// value_cast( *itr, *oitr );
|
||||
} catch ( fc::error_report& er ) {
|
||||
throw FC_REPORT_PUSH( er, "Error casting value[${index}] to ${type}",
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ namespace fc {
|
|||
void pack( fc::value& jsv, const fc::vector<char>& value );
|
||||
template<typename T>
|
||||
void pack( fc::value& jsv, const fc::vector<T>& value );
|
||||
template<typename T>
|
||||
void pack( fc::value& jsv, const std::vector<T>& value );
|
||||
|
||||
|
||||
inline void unpack( const fc::value& jsv, fc::value& v ) { v = jsv; }
|
||||
|
|
@ -82,6 +84,8 @@ namespace fc {
|
|||
void unpack( const fc::value& jsv, fc::vector<char>& value );
|
||||
template<typename T>
|
||||
void unpack( const fc::value& jsv, fc::vector<T>& value );
|
||||
template<typename T>
|
||||
void unpack( const fc::value& jsv, std::vector<T>& value );
|
||||
|
||||
namespace detail {
|
||||
template<typename Class>
|
||||
|
|
@ -249,6 +253,19 @@ namespace fc {
|
|||
++i;
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
inline void pack( fc::value& jsv, const std::vector<T>& value ) {
|
||||
jsv = fc::value::array();
|
||||
jsv.resize(value.size());
|
||||
auto itr = value.begin();
|
||||
auto end = value.end();
|
||||
uint32_t i = 0;
|
||||
while( itr != end ) {
|
||||
fc::pack( jsv[i], *itr );
|
||||
++itr;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
struct tuple_to_value_visitor {
|
||||
tuple_to_value_visitor( value& v ):_val(v),_count(0) { }
|
||||
template<typename T>
|
||||
|
|
@ -291,6 +308,14 @@ namespace fc {
|
|||
unpack( jsv[i], val[i] );
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
inline void unpack( const fc::value& jsv, std::vector<T>& val ) {
|
||||
val.resize( jsv.size() );
|
||||
uint32_t s = jsv.size();
|
||||
for( uint32_t i = 0; i < s; ++i ) {
|
||||
unpack( jsv[i], val[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// default case
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/log.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace fc {
|
||||
|
|
|
|||
|
|
@ -202,6 +202,7 @@ namespace fc {
|
|||
|
||||
void cast_value( const value& v, int64_t& out ){
|
||||
v.visit( cast_visitor<int64_t>(out) );
|
||||
slog( "cast_value( v, int64: %lld )", out );
|
||||
}
|
||||
|
||||
void cast_value( const value& v, uint8_t& out ){
|
||||
|
|
|
|||
Loading…
Reference in a new issue