summaryrefslogtreecommitdiff
path: root/zenXml/zenxml/cvrt_text.h
diff options
context:
space:
mode:
Diffstat (limited to 'zenXml/zenxml/cvrt_text.h')
-rwxr-xr-xzenXml/zenxml/cvrt_text.h37
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>
bgstack15