aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/null.h
blob: bb97148ac61080cf06e49ac00aface87176c4ca3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include "zerocopy.h" 
#include "output.h" 

/** 
 * @addtogroup Streams 
 * @{ 
 */ 
 
/** 
 * Null input stream. Does nothing, contains no data. 
 */ 
class TNullInput: public IZeroCopyInput {
public:
    TNullInput() noexcept;
    ~TNullInput() override;

private:
    size_t DoRead(void* buf, size_t len) override;
    size_t DoSkip(size_t len) override;
    size_t DoNext(const void** ptr, size_t len) override;
};

/** 
 * Null output stream. Just ignores whatever is written into it. 
 */ 
class TNullOutput: public IOutputStream {
public:
    TNullOutput() noexcept;
    ~TNullOutput() override;

    TNullOutput(TNullOutput&&) noexcept = default;
    TNullOutput& operator=(TNullOutput&&) noexcept = default;

private:
    void DoWrite(const void* buf, size_t len) override;
};

/** 
 * Null input-output stream. 
 * 
 * @see TNullInput 
 * @see TNullOutput 
 */ 
class TNullIO: public TNullInput, public TNullOutput {
public:
    TNullIO() noexcept;
    ~TNullIO() override;
};

namespace NPrivate { 
    TNullIO& StdNullStream() noexcept;
} 

/** 
 * Standard null stream. 
 */ 
#define Cnull (::NPrivate::StdNullStream()) 

/** @} */