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

get_time.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0fa0f5a4ef31f5e31c5c767834a3d22b6beecc17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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