Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
FakeStream.h
浏览该文件的文档.
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// 此处已经过单测,不存在分支和未测函数
36// GCOVR_EXCL_START
37
40template<typename T>
41class FakeStream : public Stream {
42public:
43 explicit FakeStream(T *t) : t(t) {}
44
45 int64_t read(void *buffer, size_t length) override { return t->read(buffer, length); }
46 int64_t write(const void *buffer, size_t length) override { return t->write(buffer, length); };
47
48protected:
49 T *t;
50};
51
54template<typename T>
56public:
57 explicit ClosableFakeStream(T *t) : FakeStream<T>(t) {}
58 void close() override { this->t->close(); }
59};
60
63 : public InputStream,
64 public PeekableStream {
65public:
66 explicit StdInputStreamWrapper(std::istream &stream);
67
68 int64_t read(void *buffer, size_t length) override;
69
76 int64_t peek(void *buffer, size_t length) override;
77
83 int64_t trunc(size_t length) override;
84
85private:
86 std::istream &stream;
87};
88
91 : public OutputStream {
92public:
93 explicit StdOutputStreamWrapper(std::ostream &stream);
94
100 int64_t write(const void *buffer, size_t length) override;
101
102private:
103 std::ostream &stream;
104 std::streamoff latest;
105};
106
107// GCOVR_EXCL_STOP
108
109} // namespace sese::io