summaryrefslogtreecommitdiff
path: root/zenXml/zenxml/cvrt_text.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2018-09-10 02:46:25 +0000
committerB Stack <bgstack15@gmail.com>2018-09-10 02:46:25 +0000
commit728d32e6da9ce66968f8eef47a59505d613e2c1b (patch)
tree0f0441755ff0e6d65e12222d4502c648bffd6a7c /zenXml/zenxml/cvrt_text.h
parent10.3 (diff)
parentpull in latest 10.4 from upstream (diff)
downloadFreeFileSync-728d32e6da9ce66968f8eef47a59505d613e2c1b.tar.gz
FreeFileSync-728d32e6da9ce66968f8eef47a59505d613e2c1b.tar.bz2
FreeFileSync-728d32e6da9ce66968f8eef47a59505d613e2c1b.zip
Merge branch '10.4' into 'master'10.4
pull in latest 10.4 from upstream See merge request opensource-tracking/FreeFileSync!1
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