Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 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.) |
| 5 | |
| 6 | // See http://www.boost.org/libs/iostreams for documentation. |
| 7 | |
| 8 | // Inspired by Daryle Walker's nullbuf from his More I/O submission. |
| 9 | |
| 10 | #ifndef NDNBOOST_IOSTREAMS_NULL_HPP_INCLUDED |
| 11 | #define NDNBOOST_IOSTREAMS_NULL_HPP_INCLUDED |
| 12 | |
| 13 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 14 | # pragma once |
| 15 | #endif |
| 16 | |
| 17 | #include <ndnboost/iostreams/categories.hpp> |
| 18 | #include <ndnboost/iostreams/detail/ios.hpp> // openmode, streamsize. |
| 19 | #include <ndnboost/iostreams/positioning.hpp> |
| 20 | |
| 21 | namespace ndnboost { namespace iostreams { |
| 22 | |
| 23 | template<typename Ch, typename Mode> |
| 24 | class basic_null_device { |
| 25 | public: |
| 26 | typedef Ch char_type; |
| 27 | struct category |
| 28 | : public Mode, |
| 29 | public device_tag, |
| 30 | public closable_tag |
| 31 | { }; |
| 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, NDNBOOST_IOS::seekdir, |
| 35 | NDNBOOST_IOS::openmode = |
| 36 | NDNBOOST_IOS::in | NDNBOOST_IOS::out ) |
| 37 | { return -1; } |
| 38 | void close() { } |
| 39 | void close(NDNBOOST_IOS::openmode) { } |
| 40 | }; |
| 41 | |
| 42 | template<typename Ch> |
| 43 | struct basic_null_source : private basic_null_device<Ch, input> { |
| 44 | typedef Ch char_type; |
| 45 | typedef source_tag category; |
| 46 | using basic_null_device<Ch, input>::read; |
| 47 | using basic_null_device<Ch, input>::close; |
| 48 | }; |
| 49 | |
| 50 | typedef basic_null_source<char> null_source; |
| 51 | typedef basic_null_source<wchar_t> wnull_source; |
| 52 | |
| 53 | template<typename Ch> |
| 54 | struct basic_null_sink : private basic_null_device<Ch, output> { |
| 55 | typedef Ch char_type; |
| 56 | typedef sink_tag category; |
| 57 | using basic_null_device<Ch, output>::write; |
| 58 | using basic_null_device<Ch, output>::close; |
| 59 | }; |
| 60 | |
| 61 | typedef basic_null_sink<char> null_sink; |
| 62 | typedef basic_null_sink<wchar_t> wnull_sink; |
| 63 | |
| 64 | } } // End namespaces iostreams, boost. |
| 65 | |
| 66 | #endif // #ifndef NDNBOOST_IOSTREAMS_NULL_HPP_INCLUDED |