14 template<
typename SrcType >
15 static inline std::string
EnumToString ( SrcType defaultVal );
17 template<
typename SrcType >
18 static inline SrcType
StringToEnum (
const std::string& value, SrcType defaultValue );
22 template<
typename SrcType >
23 static inline typename std::enable_if< std::is_enum< SrcType >::value, std::string >::type
24 ToString (
const SrcType& val );
26 template<
typename SrcType >
27 static inline typename std::enable_if< std::is_enum< SrcType >::value, SrcType >::type
28 FromString (
const std::string& val,
const SrcType& defaultValue );
30 template<
typename SrcType >
31 static inline typename std::enable_if< !std::is_enum< SrcType >::value, std::string >::type
32 ToString (
const SrcType& val );
34 template<
typename SrcType >
35 static inline typename std::enable_if< !std::is_enum< SrcType >::value, SrcType >::type
36 FromString (
const std::string& val,
const SrcType& defaultValue );
41 static inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::string >::type
42 ToString< std::wstring > (
const std::wstring& value );
45 static inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::wstring >::type
46 FromString< std::wstring > (
const std::string& value,
const std::wstring& defaultValue );
51 template<
typename SrcType >
52 inline typename std::enable_if< !std::is_enum< SrcType >::value, std::string >::type
53 Convert::ToString (
const SrcType& val )
55 return std::to_string( val );
58 template<
typename SrcType >
59 inline typename std::enable_if< !std::is_enum< SrcType >::value, SrcType >::type
60 Convert::FromString (
const std::string& val,
const SrcType& defaultValue )
62 static_assert(
false,
"Specialize template" );
72 template<
typename SrcType >
73 inline typename std::enable_if< std::is_enum< SrcType >::value, std::string >::type
74 Convert::ToString (
const SrcType& val )
80 template<
typename SrcType >
81 inline typename std::enable_if< std::is_enum< SrcType >::value, SrcType >::type
82 Convert::FromString (
const std::string& val,
const SrcType& defaultValue )
92 inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::string >::type
93 Convert::ToString< std::wstring > (
const std::wstring& value )
95 typedef std::codecvt_utf8<wchar_t> convert_type;
96 std::wstring_convert<convert_type, wchar_t> converter;
97 return converter.to_bytes( value );
101 inline typename std::enable_if< !std::is_enum< std::wstring >::value, std::wstring >::type
102 Convert::FromString< std::wstring > (
const std::string& value,
const std::wstring& defaultValue )
104 typedef std::codecvt_utf8<wchar_t> convert_type;
105 std::wstring_convert<convert_type, wchar_t> converter;
106 return converter.from_bytes( value );
114 template<
typename SrcType >
117 static_assert( std::is_enum< SrcType >::value,
"Type is not enum" );
119 auto type = rttr::type::get< SrcType >();
121 assert( type.is_valid() );
122 assert( type.is_enumeration() );
124 rttr::enumeration enumVal = type.get_enumeration();
126 return enumVal.value_to_name( value );
130 template<
typename SrcType >
133 static_assert( std::is_enum< SrcType >::value,
"Type is not enum" );
135 auto type = rttr::type::get< SrcType >();
137 assert( type.is_valid() );
138 assert( type.is_enumeration() );
140 rttr::enumeration enumVal = type.get_enumeration();
142 rttr::variant result = enumVal.value_to_name( value );
143 if( !result.is_valid() )
146 return result.get_value< SrcType >();
static std::string EnumToString(SrcType defaultVal)
Definition: Converters.h:115
static SrcType StringToEnum(const std::string &value, SrcType defaultValue)
Definition: Converters.h:131
Definition: Converters.h:10