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> template<typename IntType, typename EnumType>
struct reflector< enum_type<IntType,EnumType> > void to_variant( const enum_type<IntType,EnumType>& var, variant& vo )
{ {
typedef EnumType type; vo = var.value;
typedef fc::true_type is_defined; }
typedef fc::true_type is_enum; template<typename IntType, typename EnumType>
void from_variant( const variant& var, enum_type<IntType,EnumType>& vo )
template<typename Visitor> {
static inline void visit( const Visitor& v ) vo.value = var.as<EnumType>();
{ }
reflector<EnumType>::visit(v);
}
static const char* to_string(int64_t i)
{
return reflector<EnumType>::to_string(i);
}
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