15 template<
typename SrcType >
16 static inline std::string
EnumToString ( SrcType defaultVal );
18 template<
typename SrcType >
19 static inline SrcType
StringToEnum (
const std::string& value, SrcType defaultValue );
23 template<
typename SrcType >
24 static inline typename std::enable_if< std::is_enum< SrcType >::value, std::string >::type
27 template<
typename SrcType >
28 static inline typename std::enable_if< std::is_enum< SrcType >::value, SrcType >::type
29 FromString (
const std::string& val,
const SrcType& defaultValue );
31 template<
typename SrcType >
32 static inline typename std::enable_if< !std::is_enum< SrcType >::value, std::string >::type
35 template<
typename SrcType >
36 static inline typename std::enable_if< !std::is_enum< SrcType >::value, SrcType >::type
37 FromString (
const std::string& val,
const SrcType& defaultValue );
42 static inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::string >::type
43 ToString< std::wstring > (
const std::wstring& value );
46 static inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::wstring >::type
47 FromString< std::wstring > (
const std::string& value,
const std::wstring& defaultValue );
52 template<
typename SrcType >
53 inline typename std::enable_if< !std::is_enum< SrcType >::value, std::string >::type
56 return std::to_string( val );
59 template<
typename SrcType >
60 inline typename std::enable_if< !std::is_enum< SrcType >::value, SrcType >::type
63 static_assert(
false,
"Specialize template" );
73 template<
typename SrcType >
74 inline typename std::enable_if< std::is_enum< SrcType >::value, std::string >::type
81 template<
typename SrcType >
82 inline typename std::enable_if< std::is_enum< SrcType >::value, SrcType >::type
93 inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::string >::type
96 typedef std::codecvt_utf8<wchar_t> convert_type;
97 std::wstring_convert<convert_type, wchar_t> converter;
98 return converter.to_bytes( value );
102 inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::wstring >::type
105 typedef std::codecvt_utf8<wchar_t> convert_type;
106 std::wstring_convert<convert_type, wchar_t> converter;
107 return converter.from_bytes( value );
115 template<
typename SrcType >
118 static_assert( std::is_enum< SrcType >::value,
"Type is not enum" );
120 auto type = rttr::type::get< SrcType >();
122 assert( type.is_valid() );
123 assert( type.is_enumeration() );
125 rttr::enumeration enumVal = type.get_enumeration();
127 return enumVal.value_to_name( value );
131 template<
typename SrcType >
134 static_assert( std::is_enum< SrcType >::value,
"Type is not enum" );
136 auto type = rttr::type::get< SrcType >();
138 assert( type.is_valid() );
139 assert( type.is_enumeration() );
141 rttr::enumeration enumVal = type.get_enumeration();
143 rttr::variant result = enumVal.value_to_name( value );
144 if( !result.is_valid() )
147 return result.get_value< SrcType >();
static std::enable_if< std::is_enum< SrcType >::value, std::string >::type ToString(const SrcType &val)
std::enable_if< !std::is_enum< std::wstring >::value, std::wstring >::type Convert::FromString< std::wstring >(const std::string &value, const std::wstring &defaultValue)
Definition: Converters.h:103
std::enable_if< !std::is_enum< std::wstring >::value, std::string >::type Convert::ToString< std::wstring >(const std::wstring &value)
Definition: Converters.h:94
static std::string EnumToString(SrcType defaultVal)
Definition: Converters.h:116
static SrcType StringToEnum(const std::string &value, SrcType defaultValue)
Definition: Converters.h:132
Definition: Converters.h:11
static std::enable_if< std::is_enum< SrcType >::value, SrcType >::type FromString(const std::string &val, const SrcType &defaultValue)