1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2004-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 // Inspired by Daryle Walker's nullbuf from his More I/O submission.
10 #ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED
11 #define BOOST_IOSTREAMS_NULL_HPP_INCLUDED
17 #include <boost/iostreams/categories.hpp>
18 #include <boost/iostreams/detail/ios.hpp> // openmode, streamsize.
19 #include <boost/iostreams/positioning.hpp>
21 namespace boost { namespace iostreams {
23 template<typename Ch, typename Mode>
24 class basic_null_device {
32 std::streamsize read(Ch*, std::streamsize) { return 0; }
33 std::streamsize write(const Ch*, std::streamsize n) { return n; }
34 std::streampos seek( stream_offset, BOOST_IOS::seekdir,
36 BOOST_IOS::in | BOOST_IOS::out )
39 void close(BOOST_IOS::openmode) { }
43 struct basic_null_source : private basic_null_device<Ch, input> {
45 typedef source_tag category;
46 using basic_null_device<Ch, input>::read;
47 using basic_null_device<Ch, input>::close;
50 typedef basic_null_source<char> null_source;
51 typedef basic_null_source<wchar_t> wnull_source;
54 struct basic_null_sink : private basic_null_device<Ch, output> {
56 typedef sink_tag category;
57 using basic_null_device<Ch, output>::write;
58 using basic_null_device<Ch, output>::close;
61 typedef basic_null_sink<char> null_sink;
62 typedef basic_null_sink<wchar_t> wnull_sink;
64 } } // End namespaces iostreams, boost.
66 #endif // #ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED