• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-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 #ifndef BOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED
10 
11 #if defined(_MSC_VER)
12 # pragma once
13 #endif
14 
15 #include <exception>
16 #include <memory>                               // allocator.
17 #include <boost/iostreams/chain.hpp>
18 #include <boost/iostreams/detail/access_control.hpp>
19 #include <boost/iostreams/detail/char_traits.hpp>
20 #include <boost/iostreams/detail/push.hpp>
21 #include <boost/iostreams/detail/streambuf.hpp> // pubsync.
22 #include <boost/iostreams/detail/streambuf/chainbuf.hpp>
23 #include <boost/mpl/if.hpp>
24 
25 namespace boost { namespace iostreams {
26 
27 //
28 // Macro: BOOST_IOSTREAMS_DEFINE_FILTERBUF(name_, chain_type_, default_char_)
29 // Description: Defines a template derived from std::basic_streambuf which uses
30 //      a chain to perform i/o. The template has the following parameters:
31 //      Ch - The character type.
32 //      Tr - The character traits type.
33 //      Alloc - The allocator type.
34 //      Access - Indicates accessibility of the chain interface; must be either
35 //          public_ or protected_; defaults to public_.
36 //
37 #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(name_, chain_type_, default_char_) \
38     template< typename Mode, \
39               typename Ch = default_char_, \
40               typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
41               typename Alloc = std::allocator<Ch>, \
42               typename Access = public_ > \
43     class name_ : public boost::iostreams::detail::chainbuf< \
44                              chain_type_<Mode, Ch, Tr, Alloc>, Mode, Access \
45                          > \
46     { \
47     public: \
48         typedef Ch                                             char_type; \
49         struct category \
50             : Mode, closable_tag, streambuf_tag \
51             { }; \
52         BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
53         typedef Mode                                           mode; \
54         typedef chain_type_<Mode, Ch, Tr, Alloc>               chain_type; \
55         name_() { } \
56         BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
57         ~name_() { if (this->is_complete()) this->BOOST_IOSTREAMS_PUBSYNC(); } \
58     }; \
59     /**/
60 BOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(filtering_streambuf, boost::iostreams::chain, char)
61 BOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(filtering_wstreambuf, boost::iostreams::chain, wchar_t)
62 
63 typedef filtering_streambuf<input>    filtering_istreambuf;
64 typedef filtering_streambuf<output>   filtering_ostreambuf;
65 typedef filtering_wstreambuf<input>   filtering_wistreambuf;
66 typedef filtering_wstreambuf<output>  filtering_wostreambuf;
67 
68 } } // End namespaces iostreams, boost.
69 
70 #endif // #ifndef BOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED
71