fix enum_type to variant

This commit is contained in:
Daniel Larimer 2013-07-29 00:25:16 -04:00
parent 8a9d0c9e13
commit e2e1d43dd4

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <fc/reflect/reflect.hpp> #include <fc/reflect/reflect.hpp>
#include <fc/io/raw_fwd.hpp> #include <fc/io/raw_fwd.hpp>
#include <fc/variant.hpp>
namespace fc namespace fc
@ -26,28 +27,18 @@ namespace fc
EnumType value; EnumType value;
}; };
/** reflects like an enum */
template<typename IntType, typename EnumType>
struct reflector< enum_type<IntType,EnumType> >
{
typedef EnumType type;
typedef fc::true_type is_defined;
typedef fc::true_type is_enum;
template<typename Visitor> template<typename IntType, typename EnumType>
static inline void visit( const Visitor& v ) void to_variant( const enum_type<IntType,EnumType>& var, variant& vo )
{ {
reflector<EnumType>::visit(v); vo = var.value;
} }
static const char* to_string(int64_t i) template<typename IntType, typename EnumType>
{ void from_variant( const variant& var, enum_type<IntType,EnumType>& vo )
return reflector<EnumType>::to_string(i); {
} vo.value = var.as<EnumType>();
static EnumType from_string(const char* s) }
{
return reflector<EnumType>::from_string(s);
}
};
/** serializes like an IntType */ /** serializes like an IntType */
namespace raw namespace raw