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
"
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
// GCOVR_EXCL_START
36
39
template
<
typename
T>
40
class
FakeStream
:
public
Stream
{
41
public
:
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
47
protected
:
48
T *
t
;
49
};
50
53
template
<
typename
T>
54
class
ClosableFakeStream
:
public
FakeStream
<T>,
public
sese::io::Closeable
{
55
public
:
56
explicit
ClosableFakeStream
(T *
t
) :
FakeStream
<T>(
t
) {}
57
void
close
()
override
{ this->
t
->close(); }
58
};
59
61
class
StdInputStreamWrapper
final
62
:
public
InputStream
,
63
public
PeekableStream
{
64
public
:
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
84
private
:
85
std::istream &
stream
;
86
};
87
89
class
StdOutputStreamWrapper
final
90
:
public
OutputStream
{
91
public
:
92
explicit
StdOutputStreamWrapper
(std::ostream &
stream
);
93
99
int64_t
write
(
const
void
*buffer,
size_t
length)
override
;
100
101
private
:
102
std::ostream &
stream
;
103
std::streamoff
latest
;
104
};
105
106
// GCOVR_EXCL_STOP
107
108
}
// namespace sese::io
sese
io
FakeStream.h
Generated on Tue Jan 7 2025 15:49:05 for Sese Framework by
1.11.0