-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathnullstream.hpp
60 lines (50 loc) · 1.55 KB
/
nullstream.hpp
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
//
// Copyright (c) 2006 - 2010
// Seweryn Habdank-Wojewodzki
//
// Distributed under the Boost Software License, Version 1.0.
// ( copy at http://www.boost.org/LICENSE_1_0.txt )
//
// Copyright Maciej Sobczak, 2002
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
#ifndef NULLSTREAM_HPP_INCLUDED
#define NULLSTREAM_HPP_INCLUDED 1
#include <streambuf>
#include <ostream>
// null stream buffer class
template <class charT, class traits = ::std::char_traits<charT> >
class null_buffer : public ::std::basic_streambuf<charT, traits>
{
public:
typedef typename ::std::basic_streambuf<charT, traits>::int_type int_type;
null_buffer() {}
private:
virtual int_type overflow(int_type c)
{
// just ignore the character
return traits::not_eof(c);
}
};
// generic null output stream class
template <class charT, class traits = ::std::char_traits<charT> >
class basic_null_stream
: private null_buffer<charT, traits>,
public ::std::basic_ostream<charT, traits>
{
public:
basic_null_stream()
// C++98 standard allows that construction
// 12.6.2/7
: ::std::basic_ostream<charT, traits>(this)
{
}
};
// helper declarations for narrow and wide streams
typedef basic_null_stream<char> null_stream;
typedef basic_null_stream<wchar_t> null_wstream;
#endif // NULLSTREAM_HPP_INCLUDED