This commit is contained in:
Daniel Larimer 2016-09-28 11:55:58 -04:00
commit 5da49e5413
2 changed files with 14 additions and 8 deletions

View file

@ -7,7 +7,7 @@ namespace fc {
/** /**
* This class is designed to offer in-place memory allocation of a string up to Length equal to * This class is designed to offer in-place memory allocation of a string up to Length equal to
* sizeof(Storage). * sizeof(Storage).
* *
* The string will serialize the same way as std::string for variant and raw formats * The string will serialize the same way as std::string for variant and raw formats
* The string will sort according to the comparison operators defined for Storage, this enables effecient * The string will sort according to the comparison operators defined for Storage, this enables effecient
@ -27,7 +27,7 @@ namespace fc {
} }
} }
fixed_string( const char* str ) { fixed_string( const char* str ) {
int l = strlen(str); auto l = strlen(str);
if( l <= sizeof(data) ) if( l <= sizeof(data) )
memcpy( (char*)&data, str, l ); memcpy( (char*)&data, str, l );
else { else {
@ -35,7 +35,7 @@ namespace fc {
} }
} }
operator std::string()const { operator std::string()const {
const char* self = (const char*)&data; const char* self = (const char*)&data;
return std::string( self, self + size() ); return std::string( self, self + size() );
} }
@ -98,15 +98,15 @@ namespace fc {
namespace raw namespace raw
{ {
template<typename Stream, typename Storage> template<typename Stream, typename Storage>
inline void pack( Stream& s, const fc::fixed_string<Storage>& u ) { inline void pack( Stream& s, const fc::fixed_string<Storage>& u ) {
unsigned_int size = u.size(); unsigned_int size = u.size();
pack( s, size ); pack( s, size );
s.write( (const char*)&u.data, size ); s.write( (const char*)&u.data, size );
} }
template<typename Stream, typename Storage> template<typename Stream, typename Storage>
inline void unpack( Stream& s, fc::fixed_string<Storage>& u ) { inline void unpack( Stream& s, fc::fixed_string<Storage>& u ) {
unsigned_int size; unsigned_int size;
fc::raw::unpack( s, size ); fc::raw::unpack( s, size );
if( size.value > 0 ) { if( size.value > 0 ) {
if( size.value > sizeof(Storage) ) { if( size.value > sizeof(Storage) ) {
@ -133,7 +133,7 @@ namespace fc {
} }
template<typename Stream, typename... Args> template<typename Stream, typename... Args>
inline void unpack( Stream& s, boost::multiprecision::number<Args...>& u ) { inline void unpack( Stream& s, boost::multiprecision::number<Args...>& u ) {
s.read( (const char*)&u, sizeof(u) ); s.read( (const char*)&u, sizeof(u) );
} }
*/ */

View file

@ -112,7 +112,7 @@ void fc::reflector<TYPE>::visit( const Visitor& v ) { \
#define FC_REFLECT_VISIT_ENUM( r, enum_type, elem ) \ #define FC_REFLECT_VISIT_ENUM( r, enum_type, elem ) \
v.TEMPLATE operator()<enum_type::elem>(BOOST_PP_STRINGIZE(elem)); v.operator()(BOOST_PP_STRINGIZE(elem), int64_t(enum_type::elem) );
#define FC_REFLECT_ENUM_TO_STRING( r, enum_type, elem ) \ #define FC_REFLECT_ENUM_TO_STRING( r, enum_type, elem ) \
case enum_type::elem: return BOOST_PP_STRINGIZE(elem); case enum_type::elem: return BOOST_PP_STRINGIZE(elem);
#define FC_REFLECT_ENUM_TO_FC_STRING( r, enum_type, elem ) \ #define FC_REFLECT_ENUM_TO_FC_STRING( r, enum_type, elem ) \
@ -172,7 +172,13 @@ template<> struct reflector<ENUM> { \
} \ } \
return from_int(i); \ return from_int(i); \
} \ } \
template< typename Visitor > \
static void visit( Visitor& v ) \
{ \
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_ENUM, ENUM, FIELDS ) \
} \
}; \ }; \
template<> struct get_typename<ENUM> { static const char* name() { return BOOST_PP_STRINGIZE(ENUM); } }; \
} }
/* Note: FC_REFLECT_ENUM previously defined this function, but I don't think it ever /* Note: FC_REFLECT_ENUM previously defined this function, but I don't think it ever