From 3ab59b8840936724e808b9a23f04458483e033e6 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 16 Oct 2014 14:59:17 +0300 Subject: [linux] Added get_time function. --- std/iomanip.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'std') diff --git a/std/iomanip.hpp b/std/iomanip.hpp index b24867e6f0..d62fdb85d8 100644 --- a/std/iomanip.hpp +++ b/std/iomanip.hpp @@ -1,5 +1,6 @@ #pragma once #include "common_defines.hpp" +#include "target_os.hpp" #ifdef new #undef new @@ -11,8 +12,64 @@ using std::setfill; using std::hex; using std::fixed; using std::setprecision; + + +#ifndef OMIM_OS_LINUX using std::get_time; +#else +#include + +namespace detail +{ + template struct get_time_manip + { + tm* __tm_; + const _CharT* __fmt_; + + get_time_manip(tm* __tm, const _CharT* __fmt) + : __tm_(__tm), __fmt_(__fmt) {} + }; + + template + 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 + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, const get_time_manip<_CharT>& __x) + { + if (!reinterpret_cast*>(__is.rdbuf())->parse(__x)) + __is.setstate(std::ios_base::failbit); + return __is; + } +} + +template +detail::get_time_manip<_CharT> get_time(tm* __tm, const _CharT* __fmt) +{ + return detail::get_time_manip<_CharT>(__tm, __fmt); +} + +#endif + #ifdef DEBUG_NEW #define new DEBUG_NEW #endif -- cgit v1.2.3