source: NonGTP/Boost/boost/iostreams/device/null.hpp @ 857

Revision 857, 2.1 KB checked in by igarcia, 19 years ago (diff)
Line 
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
20namespace boost { namespace iostreams {
21
22template<typename Ch, typename Mode>
23class basic_null_device {
24public:
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
40template<typename Ch>
41struct 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
48typedef basic_null_source<char>     null_source;
49typedef basic_null_source<wchar_t>  wnull_source;
50
51template<typename Ch>
52struct 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
59typedef basic_null_sink<char>     null_sink;
60typedef basic_null_sink<wchar_t>  wnull_sink;
61
62} } // End namespaces iostreams, boost.
63
64#endif // #ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.