tudocomp
– The TU Dortmund Compression Framework
BackInsertStream.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <memory>
5 #include <sstream>
6 #include <utility>
7 
9 
10 namespace tdc {
11 namespace io {
12 
14 
15 class BackInsertStream {
16  std::vector<uint8_t>* buffer;
17  std::unique_ptr<VectorStreamBuffer<uint8_t>> outBuf;
18  std::unique_ptr<std::stringstream> ss;
19  std::ostream* o;
20 
21 public:
22  BackInsertStream(const BackInsertStream& other): BackInsertStream(*other.buffer) {
23  }
24 
25  BackInsertStream(BackInsertStream&& other) {
26  buffer = other.buffer;
27  outBuf = std::move(other.outBuf);
28  ss = std::move(other.ss);
29  o = other.o;
30 
31  other.buffer = nullptr;
32  other.o = nullptr;
33  }
34 
35  BackInsertStream(std::vector<uint8_t>& buf) {
36  buffer = &buf;
37  outBuf = std::unique_ptr<VectorStreamBuffer<uint8_t>>(
38  new VectorStreamBuffer<uint8_t>(buf));
39 
40  ss = std::unique_ptr<std::stringstream> {
41  new std::stringstream()
42  };
43  o = &*ss;
44  o->rdbuf(&*outBuf);
45  }
46 
47  std::ostream& stream() {
48  return *o;
49  }
50 
51  size_t size() const {
52  return buffer->size();
53  }
54 };
55 
57 
58 }}
59 
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11