- removed polymorphic reflection, made static_reflect default because there are cases such as deserializing an array that you need more information than the runtime reflection can provide such as the ability to resize arrays and know the array content type. - refactored iostream, sstream, fstream to be much simpler, fewer indirections, and fixed getline. - json parsing works using code from mace. - value is reimplemented based upon mace::rpc::value and no longer uses the runtime reflection that was removed. - moved the typename utility to its own header
87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
#pragma once
|
|
#include <fc/string.hpp>
|
|
|
|
namespace fc {
|
|
|
|
namespace detail {
|
|
template<typename T, typename R>
|
|
struct lexical_cast { };
|
|
|
|
double to_double( const fc::string& s );
|
|
inline double to_double( double d ) { return d; }
|
|
|
|
int64_t to_int64( const fc::string& s );
|
|
inline int64_t to_int64( double d ) { return d; }
|
|
inline int64_t to_int64( int64_t d ) { return d; }
|
|
|
|
uint64_t to_uint64( const fc::string& s );
|
|
inline uint64_t to_uint64( double d ) { return d; }
|
|
inline uint64_t to_uint64( uint64_t d ) { return d; }
|
|
|
|
fc::string to_string( double d );
|
|
fc::string to_string( uint64_t d );
|
|
fc::string to_string( uint32_t d );
|
|
fc::string to_string( uint16_t d );
|
|
fc::string to_string( uint8_t d );
|
|
fc::string to_string( int64_t d );
|
|
fc::string to_string( int32_t d );
|
|
fc::string to_string( int16_t d );
|
|
fc::string to_string( int8_t d );
|
|
fc::string to_string( char d );
|
|
|
|
template<typename R>
|
|
struct lexical_cast<double, R> {
|
|
static double cast( const R& v ) { return to_double( v ); }
|
|
};
|
|
|
|
template<typename R>
|
|
struct lexical_cast<fc::string, R> {
|
|
static fc::string cast( const R& v ) { return to_string( v ); }
|
|
};
|
|
|
|
template<typename R>
|
|
struct lexical_cast<uint64_t, R> {
|
|
static uint64_t cast( const R& v ) { return to_uint64( v ); }
|
|
};
|
|
|
|
template<typename R>
|
|
struct lexical_cast<int64_t, R> { static uint64_t cast( const R& v ) { return to_int64( v ); } };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<int32_t, R> { static uint32_t cast( const R& v ) { return to_int64( v ); } };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<int16_t, R> { static uint16_t cast( const R& v ) { return to_int64( v ); } };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<int8_t, R> { static uint8_t cast( const R& v ) { return to_int64( v ); } };
|
|
|
|
|
|
template<typename R>
|
|
struct lexical_cast<uint32_t, R> { static uint32_t cast( const R& v ) { return to_uint64( v ); } };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<uint16_t, R> { static uint16_t cast( const R& v ) { return to_uint64( v ); } };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<uint8_t, R> { static uint8_t cast( const R& v ) { return to_uint64( v ); } };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<bool, R> { static bool cast( const R& v ) { return v; } };
|
|
|
|
template<>
|
|
struct lexical_cast<bool, fc::string> { static bool cast( const fc::string& v ) { return v == "true"; } };
|
|
|
|
template<>
|
|
struct lexical_cast<fc::string,bool> { static fc::string cast( const bool& v ) { return v ? "true" : "false";} };
|
|
|
|
template<typename R>
|
|
struct lexical_cast<float, R> { static float cast( const R& v ) { return to_double( v ); } };
|
|
}
|
|
|
|
|
|
template<typename T, typename R>
|
|
T lexical_cast( const R& v ) {
|
|
return detail::lexical_cast<T,R>::cast(v);
|
|
}
|
|
}
|