Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-04-20 14:03:49 +0300
committerSergey Yershov <syershov@maps.me>2017-04-20 14:40:54 +0300
commit58cb1b7e99947a66d6d4a56260e45898b6ed6e61 (patch)
tree439e24f572298514af6af7f174bec5e467434a6c /base
parentd4164733a10132c219809f85de393f38bacdbe41 (diff)
[build] Fixed get_time/put_time on Linux.
Diffstat (limited to 'base')
-rw-r--r--base/CMakeLists.txt1
-rw-r--r--base/base.pro1
-rw-r--r--base/get_time.hpp69
-rw-r--r--base/timer.cpp63
4 files changed, 74 insertions, 60 deletions
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt
index 4c5e22d650..e4d124537a 100644
--- a/base/CMakeLists.txt
+++ b/base/CMakeLists.txt
@@ -19,6 +19,7 @@ set(
dfa_helpers.hpp
exception.cpp
exception.hpp
+ get_time.hpp
gmtime.cpp
gmtime.hpp
levenshtein_dfa.cpp
diff --git a/base/base.pro b/base/base.pro
index bac5b15d47..b9bf3d586e 100644
--- a/base/base.pro
+++ b/base/base.pro
@@ -49,6 +49,7 @@ HEADERS += \
deferred_task.hpp \
dfa_helpers.hpp \
exception.hpp \
+ get_time.hpp \
gmtime.hpp \
internal/message.hpp \
levenshtein_dfa.hpp \
diff --git a/base/get_time.hpp b/base/get_time.hpp
new file mode 100644
index 0000000000..0fa0f5a4ef
--- /dev/null
+++ b/base/get_time.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include "std/target_os.hpp"
+
+#if defined(OMIM_OS_LINUX)
+#include <cassert>
+#endif
+
+#include <iomanip>
+
+namespace base
+{
+#if defined(OMIM_OS_LINUX)
+
+namespace detail
+{
+template <class _CharT>
+struct get_time_manip
+{
+ tm * __tm_;
+ const _CharT * __fmt_;
+
+ get_time_manip(tm * __tm, const _CharT * __fmt) : __tm_(__tm), __fmt_(__fmt) {}
+};
+
+template <class _CharT, class _Traits>
+class stream_buf_impl : public std::basic_streambuf<_CharT, _Traits>
+{
+ typedef std::basic_streambuf<_CharT, _Traits> base_t;
+
+public:
+ bool parse(const get_time_manip<_CharT> & __x)
+ {
+ // Workaround works only for a stream buffer under null-terminated string.
+ assert(*base_t::egptr() == 0);
+
+ char * res = ::strptime(base_t::gptr(), __x.__fmt_, __x.__tm_);
+ if (res == 0)
+ return false;
+ else
+ {
+ base_t::setg(base_t::eback(), res, base_t::egptr());
+ return true;
+ }
+ }
+};
+
+template <class _CharT, class _Traits>
+std::basic_istream<_CharT, _Traits> & operator>>(std::basic_istream<_CharT, _Traits> & __is,
+ const get_time_manip<_CharT> & __x)
+{
+ if (!reinterpret_cast<stream_buf_impl<_CharT, _Traits> *>(__is.rdbuf())->parse(__x))
+ __is.setstate(std::ios_base::failbit);
+ return __is;
+}
+} // namespace detail
+
+template <class _CharT>
+detail::get_time_manip<_CharT> get_time(tm * __tm, const _CharT * __fmt)
+{
+ return detail::get_time_manip<_CharT>(__tm, __fmt);
+}
+
+#else
+
+using std::get_time;
+
+#endif
+} // namespace base
diff --git a/base/timer.cpp b/base/timer.cpp
index cf69719581..56b0d63811 100644
--- a/base/timer.cpp
+++ b/base/timer.cpp
@@ -1,4 +1,5 @@
#include "base/assert.hpp"
+#include "base/get_time.hpp"
#include "base/macros.hpp"
#include "base/timegm.hpp"
#include "base/timer.hpp"
@@ -13,64 +14,6 @@
#include <sys/time.h>
-#ifndef OMIM_OS_LINUX
-using std::get_time;
-using std::put_time;
-#else
-#include <cassert>
-
-namespace detail
-{
- template <class _CharT> struct get_time_manip
- {
- tm* __tm_;
- const _CharT* __fmt_;
-
- get_time_manip(tm* __tm, const _CharT* __fmt)
- : __tm_(__tm), __fmt_(__fmt) {}
- };
-
- template <class _CharT, class _Traits>
- class stream_buf_impl : public std::basic_streambuf<_CharT, _Traits>
- {
- typedef std::basic_streambuf<_CharT, _Traits> base_t;
- public:
- bool parse(const get_time_manip<_CharT>& __x)
- {
- // Workaround works only for a stream buffer under null-terminated string.
- assert(*base_t::egptr() == 0);
-
- char * res = ::strptime(base_t::gptr(), __x.__fmt_, __x.__tm_);
- if (res == 0)
- return false;
- else
- {
- base_t::setg(base_t::eback(), res, base_t::egptr());
- return true;
- }
- }
- };
-
- template <class _CharT, class _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is, const get_time_manip<_CharT>& __x)
- {
- if (!reinterpret_cast<stream_buf_impl<_CharT, _Traits>*>(__is.rdbuf())->parse(__x))
- __is.setstate(std::ios_base::failbit);
- return __is;
- }
-}
-
-template <class _CharT>
-detail::get_time_manip<_CharT> get_time(tm* __tm, const _CharT* __fmt)
-{
- return detail::get_time_manip<_CharT>(__tm, __fmt);
-}
-
-#endif
-
-
-
namespace my
{
@@ -162,7 +105,7 @@ time_t StringToTimestamp(std::string const & s)
// Parse UTC format: 1970-01-01T00:00:00Z
tm t{};
std::istringstream ss(s);
- ss >> get_time(&t, "%Y-%m-%dT%H:%M:%SZ");
+ ss >> base::get_time(&t, "%Y-%m-%dT%H:%M:%SZ");
if (!ss.fail() && IsValid(t))
res = base::TimeGM(t);
@@ -173,7 +116,7 @@ time_t StringToTimestamp(std::string const & s)
tm t1{}, t2{};
char sign;
std::istringstream ss(s);
- ss >> get_time(&t1, "%Y-%m-%dT%H:%M:%S") >> sign >> get_time(&t2, "%H:%M");
+ ss >> base::get_time(&t1, "%Y-%m-%dT%H:%M:%S") >> sign >> base::get_time(&t2, "%H:%M");
if (!ss.fail() && IsValid(t1))
{