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
|
||||
|
||||
namespace fc {
|
||||
class microseconds {
|
||||
class microseconds {
|
||||
public:
|
||||
explicit microseconds( int64_t c = 0) :_count(c){}
|
||||
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; }
|
||||
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; }
|
||||
private:
|
||||
friend class time_point;
|
||||
int64_t _count;
|
||||
int64_t _count;
|
||||
};
|
||||
inline microseconds seconds( int64_t s ) { return microseconds( s * 1000000 ); }
|
||||
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 days(int64_t d) { return hours(24*d); }
|
||||
|
||||
class time_point {
|
||||
class time_point {
|
||||
public:
|
||||
explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
|
||||
static time_point now();
|
||||
static time_point maximum() { return time_point( microseconds::maximum() ); }
|
||||
static time_point min() { return time_point(); }
|
||||
operator fc::string()const;
|
||||
|
||||
|
||||
static time_point from_iso_string( const fc::string& s );
|
||||
|
||||
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; }
|
||||
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); }
|
||||
microseconds operator - (const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
|
||||
private:
|
||||
microseconds elapsed;
|
||||
microseconds elapsed;
|
||||
};
|
||||
|
||||
/**
|
||||
* A lower resolution time_point accurate only to seconds from 1970
|
||||
*/
|
||||
class time_point_sec
|
||||
class time_point_sec
|
||||
{
|
||||
public:
|
||||
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; }
|
||||
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 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 '\\'" );
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void skip_white_space( T& in )
|
||||
void skip_white_space( T& in )
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
|
|
@ -67,18 +66,18 @@ namespace fc
|
|||
fc::string stringFromStream( T& in )
|
||||
{
|
||||
fc::stringstream token;
|
||||
try
|
||||
try
|
||||
{
|
||||
char c = in.peek();
|
||||
|
||||
if( c != '"' )
|
||||
FC_THROW_EXCEPTION( parse_error_exception,
|
||||
"Expected '\"' but read '${char}'",
|
||||
FC_THROW_EXCEPTION( parse_error_exception,
|
||||
"Expected '\"' but read '${char}'",
|
||||
("char", string(&c, (&c) + 1) ) );
|
||||
in.get();
|
||||
while( true )
|
||||
{
|
||||
|
||||
|
||||
switch( c = in.peek() )
|
||||
{
|
||||
case '\\':
|
||||
|
|
@ -94,14 +93,14 @@ namespace fc
|
|||
}
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "EOF before closing '\"' in string '${token}'",
|
||||
("token", token.str() ) );
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||
("token", token.str() ) );
|
||||
}
|
||||
template<typename T>
|
||||
fc::string stringFromToken( T& in )
|
||||
{
|
||||
fc::stringstream token;
|
||||
try
|
||||
try
|
||||
{
|
||||
char c = in.peek();
|
||||
|
||||
|
|
@ -128,12 +127,12 @@ namespace fc
|
|||
}
|
||||
}
|
||||
return token.str();
|
||||
}
|
||||
}
|
||||
catch( const fc::eof_exception& eof )
|
||||
{
|
||||
return token.str();
|
||||
}
|
||||
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||
("token", token.str() ) );
|
||||
}
|
||||
|
||||
|
|
@ -143,10 +142,10 @@ namespace fc
|
|||
mutable_variant_object obj;
|
||||
try
|
||||
{
|
||||
char c = in.peek();
|
||||
char c = in.peek();
|
||||
if( c != '{' )
|
||||
FC_THROW_EXCEPTION( parse_error_exception,
|
||||
"Expected '{', but read '${char}'",
|
||||
FC_THROW_EXCEPTION( parse_error_exception,
|
||||
"Expected '{', but read '${char}'",
|
||||
("char",string(&c, &c + 1)) );
|
||||
in.get();
|
||||
skip_white_space(in);
|
||||
|
|
@ -176,8 +175,10 @@ namespace fc
|
|||
return 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" );
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +195,7 @@ namespace fc
|
|||
|
||||
while( in.peek() != ']' )
|
||||
{
|
||||
while( in.peek() == ',' )
|
||||
while( in.peek() == ',' )
|
||||
in.get();
|
||||
ar.push_back( variant_from_stream(in) );
|
||||
skip_white_space(in);
|
||||
|
|
@ -204,7 +205,7 @@ namespace fc
|
|||
("variant", ar) );
|
||||
|
||||
in.get();
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "Attempting to parse array ${array}",
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "Attempting to parse array ${array}",
|
||||
("array", ar ) );
|
||||
return ar;
|
||||
}
|
||||
|
|
@ -228,11 +229,11 @@ namespace fc
|
|||
char c;
|
||||
while((c = in.peek()) && !done)
|
||||
{
|
||||
|
||||
|
||||
switch( c )
|
||||
{
|
||||
case '.':
|
||||
if (dot)
|
||||
if (dot)
|
||||
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places");
|
||||
dot = true;
|
||||
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));
|
||||
if( dot )
|
||||
return to_double(str);
|
||||
if( neg )
|
||||
if( neg )
|
||||
return to_int64(str);
|
||||
return to_uint64(str);
|
||||
}
|
||||
|
|
@ -309,7 +310,7 @@ namespace fc
|
|||
if( str == "null" ) return variant();
|
||||
if( str == "true" ) return true;
|
||||
if( str == "false" ) return false;
|
||||
else
|
||||
else
|
||||
{
|
||||
if (received_eof)
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF" );
|
||||
|
|
@ -372,7 +373,7 @@ namespace fc
|
|||
default:
|
||||
// ilog( "unhandled char '${c}' int ${int}", ("c", fc::string( &c, 1 ) )("int", int(c)) );
|
||||
return stringFromToken(in);
|
||||
in.get(); //
|
||||
in.get(); //
|
||||
ilog( "unhandled char '${c}' int ${int}", ("c", fc::string( &c, 1 ) )("int", int(c)) );
|
||||
return variant();
|
||||
}
|
||||
|
|
@ -395,7 +396,7 @@ namespace fc
|
|||
|
||||
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 << '{';
|
||||
auto itr = o.begin();
|
||||
|
||||
|
||||
while( itr != o.end() )
|
||||
{
|
||||
escape_string( itr->key(), os );
|
||||
|
|
@ -480,13 +481,13 @@ namespace fc
|
|||
{
|
||||
switch( v.get_type() )
|
||||
{
|
||||
case variant::null_type:
|
||||
case variant::null_type:
|
||||
os << "null";
|
||||
return;
|
||||
case variant::int64_type:
|
||||
case variant::int64_type:
|
||||
os << v.as_int64();
|
||||
return;
|
||||
case variant::uint64_type:
|
||||
case variant::uint64_type:
|
||||
os << v.as_uint64();
|
||||
return;
|
||||
case variant::double_type:
|
||||
|
|
@ -531,7 +532,7 @@ namespace fc
|
|||
switch( v[i] ) {
|
||||
case '\\':
|
||||
if( !escape ) {
|
||||
if( quote )
|
||||
if( quote )
|
||||
escape = true;
|
||||
} else { escape = false; }
|
||||
ss<<v[i];
|
||||
|
|
@ -551,7 +552,7 @@ namespace fc
|
|||
}
|
||||
if( !escape ) {
|
||||
quote = !quote;
|
||||
}
|
||||
}
|
||||
escape = false;
|
||||
ss<<'"';
|
||||
break;
|
||||
|
|
@ -629,7 +630,7 @@ namespace fc
|
|||
{
|
||||
//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 );
|
||||
//buffered_istream bi( tmp );
|
||||
//buffered_istream bi( tmp );
|
||||
std::ifstream bi( p.generic_string().c_str(), std::ios::binary );
|
||||
return variant_from_stream( bi );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue