Bash++
Bash++ compiler internal documentation
NullStream.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <streambuf>
9#include <ostream>
10#include <sstream>
11
12class NullBuffer : public std::streambuf {
13 protected:
14 int overflow(int c) override {
15 return traits_type::not_eof(c); // Indicate success, but discard the character
16 }
17};
18
19class NullOStream : public std::ostream {
20 private:
22 public:
23 NullOStream() : std::ostream(&null_buffer) {}
24};
25
26class NullOStringStream : public std::ostringstream {
27 public:
28 NullOStringStream() = default;
29
30 template <typename T>
31 NullOStringStream& operator<<(const T& value) {
32 // Do nothing, effectively discarding the output
33 return *this;
34 }
35
36 NullOStringStream& write(const char* s, std::streamsize n) {
37 // Do nothing, effectively discarding the output
38 return *this;
39 }
40
41 // Override str() to return an empty string
42 inline std::string str() const {
43 return ""; // Always return an empty string
44 }
45};
46
Definition NullStream.h:12
int overflow(int c) override
Definition NullStream.h:14
Definition NullStream.h:19
NullBuffer null_buffer
Definition NullStream.h:21
NullOStream()
Definition NullStream.h:23
Definition NullStream.h:26
NullOStringStream()=default
NullOStringStream & write(const char *s, std::streamsize n)
Definition NullStream.h:36
NullOStringStream & operator<<(const T &value)
Definition NullStream.h:31
std::string str() const
Definition NullStream.h:42