Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
FakeStream.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
23#pragma once
24
25#include "sese/Config.h"
26#include "sese/io/Closeable.h"
28#include "sese/io/Stream.h"
29
30#include <istream>
31#include <ostream>
32
33namespace sese::io {
34
35// GCOVR_EXCL_START
36
39template<typename T>
40class FakeStream : public Stream {
41public:
42 explicit FakeStream(T *t) : t(t) {}
43
44 int64_t read(void *buffer, size_t length) override { return t->read(buffer, length); }
45 int64_t write(const void *buffer, size_t length) override { return t->write(buffer, length); };
46
47protected:
48 T *t;
49};
50
53template<typename T>
55public:
56 explicit ClosableFakeStream(T *t) : FakeStream<T>(t) {}
57 void close() override { this->t->close(); }
58};
59
62 : public InputStream,
63 public PeekableStream {
64public:
65 explicit StdInputStreamWrapper(std::istream &stream);
66
67 int64_t read(void *buffer, size_t length) override;
68
75 int64_t peek(void *buffer, size_t length) override;
76
82 int64_t trunc(size_t length) override;
83
84private:
85 std::istream &stream;
86};
87
90 : public OutputStream {
91public:
92 explicit StdOutputStreamWrapper(std::ostream &stream);
93
99 int64_t write(const void *buffer, size_t length) override;
100
101private:
102 std::ostream &stream;
103 std::streamoff latest;
104};
105
106// GCOVR_EXCL_STOP
107
108} // namespace sese::io