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
"
27
#include "
sese/io/PeekableStream.h
"
28
#include "
sese/io/Stream.h
"
29
30
#include <istream>
31
#include <ostream>
32
33
namespace
sese::io
{
34
35
// 此处已经过单测,不存在分支和未测函数
36
// GCOVR_EXCL_START
37
40
template
<
typename
T>
41
class
FakeStream
:
public
Stream
{
42
public
:
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
48
protected
:
49
T *
t
;
50
};
51
54
template
<
typename
T>
55
class
ClosableFakeStream
:
public
FakeStream
<T>,
public
sese::io::Closeable
{
56
public
:
57
explicit
ClosableFakeStream
(T *
t
) :
FakeStream
<T>(
t
) {}
58
void
close
()
override
{ this->
t
->close(); }
59
};
60
62
class
StdInputStreamWrapper
final
63
:
public
InputStream
,
64
public
PeekableStream
{
65
public
:
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
85
private
:
86
std::istream &
stream
;
87
};
88
90
class
StdOutputStreamWrapper
final
91
:
public
OutputStream
{
92
public
:
93
explicit
StdOutputStreamWrapper
(std::ostream &
stream
);
94
100
int64_t
write
(
const
void
*buffer,
size_t
length)
override
;
101
102
private
:
103
std::ostream &
stream
;
104
std::streamoff
latest
;
105
};
106
107
// GCOVR_EXCL_STOP
108
109
}
// namespace sese::io
sese
io
FakeStream.h
生成于 2024年 十一月 4日 星期一 09:58:00 , 为 Sese Framework使用
1.11.0