1 | // |
2 | // NullStream.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Streams |
6 | // Module: NullStream |
7 | // |
8 | // Definition of the NullStreamBuf, NullInputStream and NullOutputStream classes. |
9 | // |
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_NullStream_INCLUDED |
18 | #define Foundation_NullStream_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/UnbufferedStreamBuf.h" |
23 | #include <istream> |
24 | #include <ostream> |
25 | |
26 | |
27 | namespace Poco { |
28 | |
29 | |
30 | class Foundation_API NullStreamBuf: public UnbufferedStreamBuf |
31 | /// This stream buffer discards all characters written to it. |
32 | /// Any read operation immediately yields EOF. |
33 | { |
34 | public: |
35 | NullStreamBuf(); |
36 | /// Creates a NullStreamBuf. |
37 | |
38 | ~NullStreamBuf(); |
39 | /// Destroys the NullStreamBuf. |
40 | |
41 | protected: |
42 | int readFromDevice(); |
43 | int writeToDevice(char c); |
44 | }; |
45 | |
46 | |
47 | class Foundation_API NullIOS: public virtual std::ios |
48 | /// The base class for NullInputStream and NullOutputStream. |
49 | /// |
50 | /// This class is needed to ensure the correct initialization |
51 | /// order of the stream buffer and base classes. |
52 | { |
53 | public: |
54 | NullIOS(); |
55 | ~NullIOS(); |
56 | |
57 | protected: |
58 | NullStreamBuf _buf; |
59 | }; |
60 | |
61 | |
62 | class Foundation_API NullInputStream: public NullIOS, public std::istream |
63 | /// Any read operation from this stream immediately |
64 | /// yields EOF. |
65 | { |
66 | public: |
67 | NullInputStream(); |
68 | /// Creates the NullInputStream. |
69 | |
70 | ~NullInputStream(); |
71 | /// Destroys the NullInputStream. |
72 | }; |
73 | |
74 | |
75 | class Foundation_API NullOutputStream: public NullIOS, public std::ostream |
76 | /// This stream discards all characters written to it. |
77 | { |
78 | public: |
79 | NullOutputStream(); |
80 | /// Creates the NullOutputStream. |
81 | |
82 | ~NullOutputStream(); |
83 | /// Destroys the NullOutputStream. |
84 | }; |
85 | |
86 | |
87 | } // namespace Poco |
88 | |
89 | |
90 | #endif // Foundation_NullStream_INCLUDED |
91 | |