14 struct membuf:
public std::streambuf {
15 inline membuf(
char* begin,
size_t size) {
16 setg(begin, begin, begin + size);
22 inline membuf(
const membuf& other):
23 membuf(other.eback(), other.egptr() - other.eback()) {}
25 inline membuf(membuf&& other):
26 membuf(other.eback(), other.egptr() - other.eback()) {}
28 virtual inline std::streampos seekpos(std::streampos sp,
29 std::ios_base::openmode which)
override 31 DCHECK(which == (std::ios_base::in | std::ios_base::out));
35 if ((
size_t(begin) + sp) >
size_t(end)) {
36 return std::streampos(std::streamoff(-1));
38 auto current = begin + sp;
39 setg(begin, current, end);
43 virtual inline std::streampos seekoff(std::streamoff off,
44 std::ios_base::seekdir way,
45 std::ios_base::openmode which)
override 48 auto current = gptr();
50 auto size = end - begin;
52 std::streampos abs_pos = current - begin;
54 if (way == std::ios_base::beg) {
56 }
else if (way == std::ios_base::cur) {
61 return seekpos(abs_pos, which);
68 std::unique_ptr<membuf> m_mb;
69 std::unique_ptr<std::istream> m_stream;
72 inline ViewStream(
char* begin,
size_t size):
75 m_mb(
std::make_unique<membuf>(membuf { begin, size })),
76 m_stream(std::unique_ptr<std::istream>(
new std::istream(&*m_mb))) {}
78 inline ViewStream(
View view): ViewStream((char*) view.data(), view.size()) {}
80 inline ViewStream(
const ViewStream& other):
81 ViewStream(other.m_begin, other.m_size) {}
83 inline ViewStream(ViewStream&& other):
84 m_begin(other.m_begin),
86 m_mb(
std::move(other.m_mb)),
87 m_stream(
std::move(other.m_stream)) {}
89 inline std::istream& stream() {
Contains the text compression and encoding framework.