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

streams_common.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94f45ab7d476e7c343bb2118978c7fc930e1ed0c (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
#pragma once

#include "base/base.hpp"
#include "base/assert.hpp"

#include "std/string.hpp"

namespace stream
{
  namespace detail
  {
    template <class TStream>
    void ReadString(TStream & s, string & t)
    {
      uint32_t count;
      s >> count;
      t.reserve(count);

      while (count > 0)
      {
        char c;
        s >> c;
        t.push_back(c);
        --count;
      }
    }

    template <class TStream, class TWriter>
    void WriteString(TStream & s, TWriter & w, string const & t)
    {
      uint32_t const count = static_cast<uint32_t>(t.size());
      s << count;
      if (count > 0)
        w.Write(t.c_str(), count);
    }

    template <class TStream>
    void ReadBool(TStream & s, bool & t)
    {
      char tt;
      s >> tt;
      ASSERT(tt == 0 || tt == 1, (tt));
      t = (tt != 0);
    }

    template <class TStream>
    void WriteBool(TStream & s, bool t)
    {
      s << char(t ? 1 : 0);
    }
  }
}