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

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

#include "std/cstdint.hpp"
#include "std/iostream.hpp"
#include "std/unique_ptr.hpp"

class Reader;
class Writer;


class BaseStreamBuf : public std::streambuf
{
public:
  typedef std::streambuf::traits_type traits_type;
  typedef std::streambuf::char_type char_type;
  typedef std::streambuf::int_type int_type;
};

class ReaderStreamBuf : public BaseStreamBuf
{
  unique_ptr<Reader> m_p;
  uint64_t m_pos, m_size;

public:
  ReaderStreamBuf(unique_ptr<Reader> && p);
  virtual ~ReaderStreamBuf();

private:
  virtual std::streamsize xsgetn(char_type * s, std::streamsize n);
  virtual int_type underflow();

  char m_buf[1];
};

class WriterStreamBuf : public BaseStreamBuf
{
  Writer * m_writer;

public:
  /// Takes the ownership of p. Writer should be allocated in dynamic memory.
  WriterStreamBuf(Writer * p) : m_writer(p) {}
  virtual ~WriterStreamBuf();

private:
  virtual std::streamsize xsputn(char_type const * s, std::streamsize n);
  virtual int_type overflow(int_type c);
  virtual int sync();
};