Merge pull request #23 from vikramrajkumar/phoenix
Updates needed for bitshares_toolkit bugfixes
This commit is contained in:
commit
5586b63fa2
2 changed files with 40 additions and 36 deletions
|
|
@ -9,7 +9,7 @@
|
||||||
#endif //// _MSC_VER
|
#endif //// _MSC_VER
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
class microseconds {
|
class microseconds {
|
||||||
public:
|
public:
|
||||||
explicit microseconds( int64_t c = 0) :_count(c){}
|
explicit microseconds( int64_t c = 0) :_count(c){}
|
||||||
static microseconds maximum() { return microseconds(0x7fffffffffffffffll); }
|
static microseconds maximum() { return microseconds(0x7fffffffffffffffll); }
|
||||||
|
|
@ -23,10 +23,11 @@ namespace fc {
|
||||||
friend bool operator<(const microseconds& a, const microseconds& b){ return a._count < b._count; }
|
friend bool operator<(const microseconds& a, const microseconds& b){ return a._count < b._count; }
|
||||||
friend bool operator<=(const microseconds& a, const microseconds& b){ return a._count <= b._count; }
|
friend bool operator<=(const microseconds& a, const microseconds& b){ return a._count <= b._count; }
|
||||||
microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; }
|
microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; }
|
||||||
|
microseconds& operator-=(const microseconds& c) { _count -= c._count; return *this; }
|
||||||
int64_t count()const { return _count; }
|
int64_t count()const { return _count; }
|
||||||
private:
|
private:
|
||||||
friend class time_point;
|
friend class time_point;
|
||||||
int64_t _count;
|
int64_t _count;
|
||||||
};
|
};
|
||||||
inline microseconds seconds( int64_t s ) { return microseconds( s * 1000000 ); }
|
inline microseconds seconds( int64_t s ) { return microseconds( s * 1000000 ); }
|
||||||
inline microseconds milliseconds( int64_t s ) { return microseconds( s * 1000 ); }
|
inline microseconds milliseconds( int64_t s ) { return microseconds( s * 1000 ); }
|
||||||
|
|
@ -34,14 +35,14 @@ namespace fc {
|
||||||
inline microseconds hours(int64_t h) { return minutes(60*h); }
|
inline microseconds hours(int64_t h) { return minutes(60*h); }
|
||||||
inline microseconds days(int64_t d) { return hours(24*d); }
|
inline microseconds days(int64_t d) { return hours(24*d); }
|
||||||
|
|
||||||
class time_point {
|
class time_point {
|
||||||
public:
|
public:
|
||||||
explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
|
explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
|
||||||
static time_point now();
|
static time_point now();
|
||||||
static time_point maximum() { return time_point( microseconds::maximum() ); }
|
static time_point maximum() { return time_point( microseconds::maximum() ); }
|
||||||
static time_point min() { return time_point(); }
|
static time_point min() { return time_point(); }
|
||||||
operator fc::string()const;
|
operator fc::string()const;
|
||||||
|
|
||||||
static time_point from_iso_string( const fc::string& s );
|
static time_point from_iso_string( const fc::string& s );
|
||||||
|
|
||||||
const microseconds& time_since_epoch()const { return elapsed; }
|
const microseconds& time_since_epoch()const { return elapsed; }
|
||||||
|
|
@ -53,17 +54,18 @@ namespace fc {
|
||||||
bool operator ==( const time_point& t )const { return elapsed._count ==t.elapsed._count; }
|
bool operator ==( const time_point& t )const { return elapsed._count ==t.elapsed._count; }
|
||||||
bool operator !=( const time_point& t )const { return elapsed._count !=t.elapsed._count; }
|
bool operator !=( const time_point& t )const { return elapsed._count !=t.elapsed._count; }
|
||||||
time_point& operator += ( const microseconds& m) { elapsed+=m; return *this; }
|
time_point& operator += ( const microseconds& m) { elapsed+=m; return *this; }
|
||||||
|
time_point& operator -= ( const microseconds& m) { elapsed-=m; return *this; }
|
||||||
time_point operator + (const microseconds& m) const { return time_point(elapsed+m); }
|
time_point operator + (const microseconds& m) const { return time_point(elapsed+m); }
|
||||||
time_point operator - (const microseconds& m) const { return time_point(elapsed-m); }
|
time_point operator - (const microseconds& m) const { return time_point(elapsed-m); }
|
||||||
microseconds operator - (const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
|
microseconds operator - (const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
|
||||||
private:
|
private:
|
||||||
microseconds elapsed;
|
microseconds elapsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lower resolution time_point accurate only to seconds from 1970
|
* A lower resolution time_point accurate only to seconds from 1970
|
||||||
*/
|
*/
|
||||||
class time_point_sec
|
class time_point_sec
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
time_point_sec()
|
time_point_sec()
|
||||||
|
|
@ -90,6 +92,7 @@ namespace fc {
|
||||||
friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; }
|
friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; }
|
||||||
friend bool operator != ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds != b.utc_seconds; }
|
friend bool operator != ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds != b.utc_seconds; }
|
||||||
time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; }
|
time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; }
|
||||||
|
time_point_sec& operator -= ( uint32_t m ) { utc_seconds-=m; return *this; }
|
||||||
|
|
||||||
friend time_point operator - ( const time_point_sec& t, const microseconds& m ) { return time_point(t) - m; }
|
friend time_point operator - ( const time_point_sec& t, const microseconds& m ) { return time_point(t) - m; }
|
||||||
friend microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
|
friend microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,8 @@ namespace fc
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Expected '\\'" );
|
FC_THROW_EXCEPTION( parse_error_exception, "Expected '\\'" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void skip_white_space( T& in )
|
void skip_white_space( T& in )
|
||||||
{
|
{
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
|
|
@ -67,18 +66,18 @@ namespace fc
|
||||||
fc::string stringFromStream( T& in )
|
fc::string stringFromStream( T& in )
|
||||||
{
|
{
|
||||||
fc::stringstream token;
|
fc::stringstream token;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
char c = in.peek();
|
char c = in.peek();
|
||||||
|
|
||||||
if( c != '"' )
|
if( c != '"' )
|
||||||
FC_THROW_EXCEPTION( parse_error_exception,
|
FC_THROW_EXCEPTION( parse_error_exception,
|
||||||
"Expected '\"' but read '${char}'",
|
"Expected '\"' but read '${char}'",
|
||||||
("char", string(&c, (&c) + 1) ) );
|
("char", string(&c, (&c) + 1) ) );
|
||||||
in.get();
|
in.get();
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( c = in.peek() )
|
switch( c = in.peek() )
|
||||||
{
|
{
|
||||||
case '\\':
|
case '\\':
|
||||||
|
|
@ -94,14 +93,14 @@ namespace fc
|
||||||
}
|
}
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "EOF before closing '\"' in string '${token}'",
|
FC_THROW_EXCEPTION( parse_error_exception, "EOF before closing '\"' in string '${token}'",
|
||||||
("token", token.str() ) );
|
("token", token.str() ) );
|
||||||
} FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
} FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||||
("token", token.str() ) );
|
("token", token.str() ) );
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
fc::string stringFromToken( T& in )
|
fc::string stringFromToken( T& in )
|
||||||
{
|
{
|
||||||
fc::stringstream token;
|
fc::stringstream token;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
char c = in.peek();
|
char c = in.peek();
|
||||||
|
|
||||||
|
|
@ -128,12 +127,12 @@ namespace fc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return token.str();
|
return token.str();
|
||||||
}
|
}
|
||||||
catch( const fc::eof_exception& eof )
|
catch( const fc::eof_exception& eof )
|
||||||
{
|
{
|
||||||
return token.str();
|
return token.str();
|
||||||
}
|
}
|
||||||
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||||
("token", token.str() ) );
|
("token", token.str() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,10 +142,10 @@ namespace fc
|
||||||
mutable_variant_object obj;
|
mutable_variant_object obj;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
char c = in.peek();
|
char c = in.peek();
|
||||||
if( c != '{' )
|
if( c != '{' )
|
||||||
FC_THROW_EXCEPTION( parse_error_exception,
|
FC_THROW_EXCEPTION( parse_error_exception,
|
||||||
"Expected '{', but read '${char}'",
|
"Expected '{', but read '${char}'",
|
||||||
("char",string(&c, &c + 1)) );
|
("char",string(&c, &c + 1)) );
|
||||||
in.get();
|
in.get();
|
||||||
skip_white_space(in);
|
skip_white_space(in);
|
||||||
|
|
@ -176,8 +175,10 @@ namespace fc
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Expected '}' after ${variant}", ("variant", obj ) );
|
FC_THROW_EXCEPTION( parse_error_exception, "Expected '}' after ${variant}", ("variant", obj ) );
|
||||||
|
}
|
||||||
|
catch( const fc::eof_exception& e )
|
||||||
|
{
|
||||||
|
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.to_detail_string() ) );
|
||||||
} FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" );
|
} FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,7 +195,7 @@ namespace fc
|
||||||
|
|
||||||
while( in.peek() != ']' )
|
while( in.peek() != ']' )
|
||||||
{
|
{
|
||||||
while( in.peek() == ',' )
|
while( in.peek() == ',' )
|
||||||
in.get();
|
in.get();
|
||||||
ar.push_back( variant_from_stream(in) );
|
ar.push_back( variant_from_stream(in) );
|
||||||
skip_white_space(in);
|
skip_white_space(in);
|
||||||
|
|
@ -204,7 +205,7 @@ namespace fc
|
||||||
("variant", ar) );
|
("variant", ar) );
|
||||||
|
|
||||||
in.get();
|
in.get();
|
||||||
} FC_RETHROW_EXCEPTIONS( warn, "Attempting to parse array ${array}",
|
} FC_RETHROW_EXCEPTIONS( warn, "Attempting to parse array ${array}",
|
||||||
("array", ar ) );
|
("array", ar ) );
|
||||||
return ar;
|
return ar;
|
||||||
}
|
}
|
||||||
|
|
@ -228,11 +229,11 @@ namespace fc
|
||||||
char c;
|
char c;
|
||||||
while((c = in.peek()) && !done)
|
while((c = in.peek()) && !done)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( c )
|
switch( c )
|
||||||
{
|
{
|
||||||
case '.':
|
case '.':
|
||||||
if (dot)
|
if (dot)
|
||||||
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places");
|
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places");
|
||||||
dot = true;
|
dot = true;
|
||||||
case '0':
|
case '0':
|
||||||
|
|
@ -265,7 +266,7 @@ namespace fc
|
||||||
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
|
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
|
||||||
if( dot )
|
if( dot )
|
||||||
return to_double(str);
|
return to_double(str);
|
||||||
if( neg )
|
if( neg )
|
||||||
return to_int64(str);
|
return to_int64(str);
|
||||||
return to_uint64(str);
|
return to_uint64(str);
|
||||||
}
|
}
|
||||||
|
|
@ -309,7 +310,7 @@ namespace fc
|
||||||
if( str == "null" ) return variant();
|
if( str == "null" ) return variant();
|
||||||
if( str == "true" ) return true;
|
if( str == "true" ) return true;
|
||||||
if( str == "false" ) return false;
|
if( str == "false" ) return false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (received_eof)
|
if (received_eof)
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF" );
|
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF" );
|
||||||
|
|
@ -372,7 +373,7 @@ namespace fc
|
||||||
default:
|
default:
|
||||||
// ilog( "unhandled char '${c}' int ${int}", ("c", fc::string( &c, 1 ) )("int", int(c)) );
|
// ilog( "unhandled char '${c}' int ${int}", ("c", fc::string( &c, 1 ) )("int", int(c)) );
|
||||||
return stringFromToken(in);
|
return stringFromToken(in);
|
||||||
in.get(); //
|
in.get(); //
|
||||||
ilog( "unhandled char '${c}' int ${int}", ("c", fc::string( &c, 1 ) )("int", int(c)) );
|
ilog( "unhandled char '${c}' int ${int}", ("c", fc::string( &c, 1 ) )("int", int(c)) );
|
||||||
return variant();
|
return variant();
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +396,7 @@ namespace fc
|
||||||
|
|
||||||
void toUTF8( const wchar_t c, ostream& os )
|
void toUTF8( const wchar_t c, ostream& os )
|
||||||
{
|
{
|
||||||
utf8::utf16to8( &c, (&c)+1, ostream_iterator<char>(os) );
|
utf8::utf16to8( &c, (&c)+1, ostream_iterator<char>(os) );
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -462,7 +463,7 @@ namespace fc
|
||||||
{
|
{
|
||||||
os << '{';
|
os << '{';
|
||||||
auto itr = o.begin();
|
auto itr = o.begin();
|
||||||
|
|
||||||
while( itr != o.end() )
|
while( itr != o.end() )
|
||||||
{
|
{
|
||||||
escape_string( itr->key(), os );
|
escape_string( itr->key(), os );
|
||||||
|
|
@ -480,13 +481,13 @@ namespace fc
|
||||||
{
|
{
|
||||||
switch( v.get_type() )
|
switch( v.get_type() )
|
||||||
{
|
{
|
||||||
case variant::null_type:
|
case variant::null_type:
|
||||||
os << "null";
|
os << "null";
|
||||||
return;
|
return;
|
||||||
case variant::int64_type:
|
case variant::int64_type:
|
||||||
os << v.as_int64();
|
os << v.as_int64();
|
||||||
return;
|
return;
|
||||||
case variant::uint64_type:
|
case variant::uint64_type:
|
||||||
os << v.as_uint64();
|
os << v.as_uint64();
|
||||||
return;
|
return;
|
||||||
case variant::double_type:
|
case variant::double_type:
|
||||||
|
|
@ -531,7 +532,7 @@ namespace fc
|
||||||
switch( v[i] ) {
|
switch( v[i] ) {
|
||||||
case '\\':
|
case '\\':
|
||||||
if( !escape ) {
|
if( !escape ) {
|
||||||
if( quote )
|
if( quote )
|
||||||
escape = true;
|
escape = true;
|
||||||
} else { escape = false; }
|
} else { escape = false; }
|
||||||
ss<<v[i];
|
ss<<v[i];
|
||||||
|
|
@ -551,7 +552,7 @@ namespace fc
|
||||||
}
|
}
|
||||||
if( !escape ) {
|
if( !escape ) {
|
||||||
quote = !quote;
|
quote = !quote;
|
||||||
}
|
}
|
||||||
escape = false;
|
escape = false;
|
||||||
ss<<'"';
|
ss<<'"';
|
||||||
break;
|
break;
|
||||||
|
|
@ -629,7 +630,7 @@ namespace fc
|
||||||
{
|
{
|
||||||
//auto tmp = std::make_shared<fc::ifstream>( p, ifstream::binary );
|
//auto tmp = std::make_shared<fc::ifstream>( p, ifstream::binary );
|
||||||
//auto tmp = std::make_shared<std::ifstream>( p.generic_string().c_str(), std::ios::binary );
|
//auto tmp = std::make_shared<std::ifstream>( p.generic_string().c_str(), std::ios::binary );
|
||||||
//buffered_istream bi( tmp );
|
//buffered_istream bi( tmp );
|
||||||
std::ifstream bi( p.generic_string().c_str(), std::ios::binary );
|
std::ifstream bi( p.generic_string().c_str(), std::ios::binary );
|
||||||
return variant_from_stream( bi );
|
return variant_from_stream( bi );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue