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

streams_sink.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0bdacc1cc1c50568578a6123ddcd4528a418ca2d (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once

#include "coding/streams_common.hpp"
#include "coding/reader.hpp"
#include "coding/write_to_sink.hpp"

#include "std/type_traits.hpp"


namespace stream
{
  template <class TReader> class SinkReaderStream
  {
    TReader & m_reader;

  public:
    SinkReaderStream(TReader & reader) : m_reader(reader) {}

    template <typename T>
    typename enable_if<is_integral<T>::value, SinkReaderStream &>::type
    operator >> (T & t)
    {
      t = ReadPrimitiveFromSource<T>(m_reader);
      return (*this);
    }

    SinkReaderStream & operator >> (bool & t)
    {
      detail::ReadBool(*this, t);
      return *this;
    }

    SinkReaderStream & operator >> (string & t)
    {
      detail::ReadString(*this, t);
      return *this;
    }

    SinkReaderStream & operator >> (double & t)
    {
      static_assert(sizeof(double) == sizeof(int64_t), "");
      int64_t * tInt = reinterpret_cast<int64_t *>(&t);
      operator >> (*tInt);
      return *this;
    }
  };

  template <class TWriter> class SinkWriterStream
  {
    TWriter & m_writer;

  public:
    SinkWriterStream(TWriter & writer) : m_writer(writer) {}

    template <typename T>
    typename enable_if<is_integral<T>::value, SinkWriterStream &>::type
    operator << (T const & t)
    {
      WriteToSink(m_writer, t);
      return (*this);
    }

    SinkWriterStream & operator << (bool t)
    {
      detail::WriteBool(*this, t);
      return (*this);
    }

    SinkWriterStream & operator << (string const & t)
    {
      detail::WriteString(*this, m_writer, t);
      return *this;
    }

    SinkWriterStream & operator << (double t)
    {
      static_assert(sizeof(double) == sizeof(int64_t), "");
      int64_t const tInt = *reinterpret_cast<int64_t const *>(&t);
      operator << (tInt);
      return (*this);
    }
  };
}