Ugly, not-to-be-pushed sucking in of all of Boost to get windows to work.
[dyninst.git] / external / boost / iostreams / filtering_stream.hpp
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 #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
8 #define BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
9
10 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 # pragma once
12 #endif              
13
14 #include <memory>                                     // allocator.
15 #include <boost/iostreams/detail/access_control.hpp>
16 #include <boost/iostreams/detail/char_traits.hpp>
17 #include <boost/iostreams/detail/iostream.hpp>        // standard streams.
18 #include <boost/iostreams/detail/push.hpp>
19 #include <boost/iostreams/detail/select.hpp>
20 #include <boost/iostreams/detail/streambuf.hpp>       // pubsync.
21 #include <boost/iostreams/filtering_streambuf.hpp>
22 #include <boost/mpl/and.hpp>
23 #include <boost/mpl/bool.hpp>
24 #include <boost/static_assert.hpp>
25 #include <boost/type_traits/is_convertible.hpp>
26
27 // Must come last.
28 #include <boost/iostreams/detail/config/disable_warnings.hpp>  // MSVC.
29
30 namespace boost { namespace iostreams {
31
32 //--------------Definition of filtered_istream--------------------------------//
33
34 namespace detail {
35
36 template<typename Mode, typename Ch, typename Tr>
37 struct filtering_stream_traits {
38     typedef typename 
39             iostreams::select<  // Disambiguation for Tru64  
40                 mpl::and_< 
41                     is_convertible<Mode, input>, 
42                     is_convertible<Mode, output> 
43                 >,          
44                 BOOST_IOSTREAMS_BASIC_IOSTREAM(Ch, Tr),
45                 is_convertible<Mode, input>, 
46                 BOOST_IOSTREAMS_BASIC_ISTREAM(Ch, Tr),
47                 else_,        
48                 BOOST_IOSTREAMS_BASIC_OSTREAM(Ch, Tr)
49             >::type type;
50 };
51
52 template<typename Chain, typename Access>
53 class filtering_stream_base 
54     : public access_control<
55                  boost::iostreams::detail::chain_client<Chain>,
56                  Access
57              >,
58       public filtering_stream_traits<
59                  typename Chain::mode, 
60                  typename Chain::char_type, 
61                  typename Chain::traits_type
62              >::type
63 {
64 public:
65     typedef Chain                                         chain_type;
66     typedef access_control<
67                  boost::iostreams::detail::chain_client<Chain>,
68                  Access
69              >                                            client_type;
70 protected:
71     typedef typename 
72             filtering_stream_traits<
73                  typename Chain::mode, 
74                  typename Chain::char_type, 
75                  typename Chain::traits_type
76             >::type                                       stream_type;
77     filtering_stream_base() : stream_type(0) { this->set_chain(&chain_); }
78 private:
79     void notify() { this->rdbuf(chain_.empty() ? 0 : &chain_.front()); }
80     Chain chain_;
81 };
82
83 } // End namespace detail.
84
85 //
86 // Macro: BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_)
87 // Description: Defines a template derived from std::basic_streambuf which uses
88 //      a chain to perform i/o. The template has the following parameters:
89 //      Mode - the i/o mode.
90 //      Ch - The character type.
91 //      Tr - The character traits type.
92 //      Alloc - The allocator type.
93 //      Access - Indicates accessibility of the chain interface; must be either
94 //          public_ or protected_; defaults to public_.
95 // Macro parameters:
96 //      name_ - The name of the template to be defined.
97 //      chain_type_ - The name of the chain template.
98 //      default_char_ - The default value for the char template parameter.
99 //
100 #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_) \
101     template< typename Mode, \
102               typename Ch = default_char_, \
103               typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
104               typename Alloc = std::allocator<Ch>, \
105               typename Access = public_ > \
106     class name_ \
107         : public boost::iostreams::detail::filtering_stream_base< \
108                      chain_type_<Mode, Ch, Tr, Alloc>, Access \
109                  > \
110     { \
111     public: \
112         typedef Ch                                char_type; \
113         BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
114         typedef Mode                              mode; \
115         typedef chain_type_<Mode, Ch, Tr, Alloc>  chain_type; \
116         name_() { } \
117         BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
118         ~name_() { \
119             if (this->is_complete()) \
120                  this->rdbuf()->BOOST_IOSTREAMS_PUBSYNC(); \
121         } \
122     private: \
123         typedef access_control< \
124                     boost::iostreams::detail::chain_client< \
125                         chain_type_<Mode, Ch, Tr, Alloc> \
126                     >, \
127                     Access \
128                 > client_type; \
129         template<typename T> \
130         void push_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \
131         { client_type::push(t BOOST_IOSTREAMS_PUSH_ARGS()); } \
132     }; \
133     /**/    
134 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(filtering_stream, boost::iostreams::chain, char)
135 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(wfiltering_stream, boost::iostreams::chain, wchar_t)  
136
137 typedef filtering_stream<input>    filtering_istream;
138 typedef filtering_stream<output>   filtering_ostream;
139 typedef wfiltering_stream<input>   filtering_wistream;
140 typedef wfiltering_stream<output>  filtering_wostream;
141
142 //----------------------------------------------------------------------------//
143
144 } } // End namespace iostreams, boost
145
146 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
147
148 #endif // #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED