diff options
author | B Stack <bgstack15@gmail.com> | 2018-09-09 18:53:23 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2018-09-09 18:53:23 -0400 |
commit | eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba (patch) | |
tree | 0f0441755ff0e6d65e12222d4502c648bffd6a7c /zenXml/zenxml/cvrt_text.h | |
parent | 10.3 (diff) | |
download | FreeFileSync-eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba.tar.gz FreeFileSync-eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba.tar.bz2 FreeFileSync-eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba.zip |
pull in latest 10.4 from upstream
Diffstat (limited to 'zenXml/zenxml/cvrt_text.h')
-rwxr-xr-x | zenXml/zenxml/cvrt_text.h | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/zenXml/zenxml/cvrt_text.h b/zenXml/zenxml/cvrt_text.h index 32a961b2..c6dab8c2 100755 --- a/zenXml/zenxml/cvrt_text.h +++ b/zenXml/zenxml/cvrt_text.h @@ -7,6 +7,7 @@ #ifndef CVRT_TEXT_H_018727339083427097434 #define CVRT_TEXT_H_018727339083427097434 +#include <chrono> #include <zen/utf.h> #include <zen/string_tools.h> @@ -101,21 +102,37 @@ template <class T> void writeText(const T& value, std::string& output); //------------------------------ implementation ------------------------------------- +template <class T> +struct IsChronoDuration +{ +private: + using Yes = char[1]; + using No = char[2]; + + template <class Rep, class Period> + static Yes& isDuration(std::chrono::duration<Rep, Period>); + static No& isDuration(...); +public: + enum { value = sizeof(isDuration(std::declval<T>())) == sizeof(Yes) }; +}; + //Conversion from arbitrary types to text (for use with XML elements and attributes) enum TextType { TEXT_TYPE_BOOL, TEXT_TYPE_NUMBER, + TEXT_TYPE_CHRONO, TEXT_TYPE_STRING, TEXT_TYPE_OTHER, }; template <class T> struct GetTextType : std::integral_constant<TextType, - std::is_same_v<T, bool> ? TEXT_TYPE_BOOL : - IsStringLikeV<T> ? TEXT_TYPE_STRING : //string before number to correctly handle char/wchar_t -> this was an issue with Loki only! - IsArithmetic<T>::value ? TEXT_TYPE_NUMBER : // + std::is_same_v<T, bool> ? TEXT_TYPE_BOOL : + IsStringLikeV<T> ? TEXT_TYPE_STRING : //string before number to correctly handle char/wchar_t -> this was an issue with Loki only! + IsArithmetic<T>::value ? TEXT_TYPE_NUMBER : // + IsChronoDuration<T>::value ? TEXT_TYPE_CHRONO : TEXT_TYPE_OTHER> {}; //###################################################################################### @@ -165,6 +182,20 @@ struct ConvertText<T, TEXT_TYPE_NUMBER> } }; +template <class T> +struct ConvertText<T, TEXT_TYPE_CHRONO> +{ + void writeText(const T& value, std::string& output) const + { + output = numberTo<std::string>(value.count()); + } + bool readText(const std::string& input, T& value) const + { + value = T(stringTo<typename T::rep>(input)); + return true; + } +}; + //partial specialization: handle conversion for all string-like types! template <class T> struct ConvertText<T, TEXT_TYPE_STRING> |