| [29] | 1 | // (C) Copyright Jonathan Turkanis 2004. |
|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
|---|
| 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) |
|---|
| 4 | |
|---|
| 5 | // See http://www.boost.org/libs/iostreams for documentation. |
|---|
| 6 | |
|---|
| 7 | // Inspired by Daryle Walker's nullbuf from his More I/O submission. |
|---|
| 8 | |
|---|
| 9 | #ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED |
|---|
| 10 | #define BOOST_IOSTREAMS_NULL_HPP_INCLUDED |
|---|
| 11 | |
|---|
| 12 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
|---|
| 13 | # pragma once |
|---|
| 14 | #endif |
|---|
| 15 | |
|---|
| 16 | #include <boost/iostreams/categories.hpp> |
|---|
| 17 | #include <boost/iostreams/detail/ios.hpp> // openmode, streamsize. |
|---|
| 18 | #include <boost/iostreams/positioning.hpp> |
|---|
| 19 | |
|---|
| 20 | namespace boost { namespace iostreams { |
|---|
| 21 | |
|---|
| 22 | template<typename Ch, typename Mode> |
|---|
| 23 | class basic_null_device { |
|---|
| 24 | public: |
|---|
| 25 | typedef Ch char_type; |
|---|
| 26 | struct category |
|---|
| 27 | : public Mode, |
|---|
| 28 | public device_tag, |
|---|
| 29 | public closable_tag |
|---|
| 30 | { }; |
|---|
| 31 | std::streamsize read(Ch*, std::streamsize) { return 0; } |
|---|
| 32 | std::streamsize write(const Ch*, std::streamsize n) { return n; } |
|---|
| 33 | std::streampos seek( stream_offset, BOOST_IOS::seekdir, |
|---|
| 34 | BOOST_IOS::openmode = |
|---|
| 35 | BOOST_IOS::in | BOOST_IOS::out ) |
|---|
| 36 | { return -1; } |
|---|
| 37 | void close(BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out) { } |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | template<typename Ch> |
|---|
| 41 | struct basic_null_source : private basic_null_device<Ch, input> { |
|---|
| 42 | typedef Ch char_type; |
|---|
| 43 | typedef source_tag category; |
|---|
| 44 | using basic_null_device<Ch, input>::read; |
|---|
| 45 | using basic_null_device<Ch, input>::close; |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | typedef basic_null_source<char> null_source; |
|---|
| 49 | typedef basic_null_source<wchar_t> wnull_source; |
|---|
| 50 | |
|---|
| 51 | template<typename Ch> |
|---|
| 52 | struct basic_null_sink : private basic_null_device<Ch, output> { |
|---|
| 53 | typedef Ch char_type; |
|---|
| 54 | typedef sink_tag category; |
|---|
| 55 | using basic_null_device<Ch, output>::write; |
|---|
| 56 | using basic_null_device<Ch, output>::close; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | typedef basic_null_sink<char> null_sink; |
|---|
| 60 | typedef basic_null_sink<wchar_t> wnull_sink; |
|---|
| 61 | |
|---|
| 62 | } } // End namespaces iostreams, boost. |
|---|
| 63 | |
|---|
| 64 | #endif // #ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED |
|---|