1 // Copyright 2017-2019 VMware, Inc.
2 // SPDX-License-Identifier: BSD-2-Clause
3 //
4 // The BSD-2 license (the License) set forth below applies to all parts of the
5 // Cascade project.  You may not use this file except in compliance with the
6 // License.
7 //
8 // BSD-2 License
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this
14 // list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright notice,
17 // this list of conditions and the following disclaimer in the documentation
18 // and/or other materials provided with the distribution.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
21 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef CASCADE_SRC_RUNTIME_NULLBUF_H
32 #define CASCADE_SRC_RUNTIME_NULLBUF_H
33 
34 #include <streambuf>
35 
36 namespace cascade {
37 
38 class nullbuf : public std::streambuf {
39   public:
40     // Typedefs:
41     typedef std::streambuf::char_type char_type;
42     typedef std::streambuf::traits_type traits_type;
43     typedef std::streambuf::int_type int_type;
44     typedef std::streambuf::pos_type pos_type;
45     typedef std::streambuf::off_type off_type;
46 
47     // Constructors:
48     ~nullbuf() override = default;
49 
50   private:
51     std::streamsize xsputn(const char_type* s, std::streamsize count) override;
52     int_type overflow(int_type c = traits_type::eof()) override;
53 
54     int_type underflow() override;
55     int_type uflow() override;
56     std::streamsize xsgetn(char_type* s, std::streamsize count) override;
57 };
58 
xsputn(const char_type * s,std::streamsize count)59 inline std::streamsize nullbuf::xsputn(const char_type* s, std::streamsize count) {
60   (void) s;
61   return count;
62 }
63 
overflow(int_type c)64 inline nullbuf::int_type nullbuf::overflow(int_type c) {
65   return c;
66 }
67 
underflow()68 inline nullbuf::int_type nullbuf::underflow() {
69   return traits_type::eof();
70 }
71 
uflow()72 inline nullbuf::int_type nullbuf::uflow() {
73   return traits_type::eof();
74 }
75 
xsgetn(char_type * s,std::streamsize count)76 inline std::streamsize nullbuf::xsgetn(char_type* s, std::streamsize count) {
77   (void) s;
78   (void) count;
79   return 0;
80 }
81 
82 } // namespace
83 
84 #endif
85