7 #ifndef ZEN_XML_CONVERT_TEXT_HEADER_018727339083427097434
8 #define ZEN_XML_CONVERT_TEXT_HEADER_018727339083427097434
11 #include <zen/string_tools.h>
67 template <
class T>
bool readText(
const std::string& input, T& value);
73 template <
class T>
void writeText(
const T& value, std::string& output);
115 struct GetTextType : StaticEnum<TextType,
116 IsSameType<T, bool>::value ? TEXT_TYPE_BOOL :
117 IsStringLike<T>::value ? TEXT_TYPE_STRING :
118 IsArithmetic<T>::value ? TEXT_TYPE_NUMBER :
123 template <
class T, TextType type>
134 struct ConvertText<T, TEXT_TYPE_BOOL>
136 void writeText(
bool value, std::string& output)
const
138 output = value ?
"true" :
"false";
140 bool readText(
const std::string& input,
bool& value)
const
142 std::string tmp = input;
146 else if (tmp ==
"false")
156 struct ConvertText<T, TEXT_TYPE_NUMBER>
158 void writeText(
const T& value, std::string& output)
const
160 output = numberTo<std::string>(value);
162 bool readText(
const std::string& input, T& value)
const
164 value = stringTo<T>(input);
171 struct ConvertText<T, TEXT_TYPE_STRING>
173 void writeText(
const T& value, std::string& output)
const
175 output = utfCvrtTo<std::string>(value);
177 bool readText(
const std::string& input, T& value)
const
179 value = utfCvrtTo<T>(input);
187 struct ConvertText<T, TEXT_TYPE_OTHER>
190 assert_static(
sizeof(T) == -1);
208 template <
class T>
inline
211 ConvertText<T, GetTextType<T>::value>().
writeText(value, output);
215 template <
class T>
inline
218 return ConvertText<T, GetTextType<T>::value>().
readText(input, value);
222 #endif //ZEN_XML_CONVERT_TEXT_HEADER_018727339083427097434
bool readText(const std::string &input, T &value)
Convert text to user data - used by XML elements and attributes.
Definition: cvrt_text.h:216
void writeText(const T &value, std::string &output)
Convert user data into text - used by XML elements and attributes.
Definition: cvrt_text.h:209