1 | // (C) Copyright Jonathan Turkanis 2003. |
---|
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_DETAIL_PUSH_HPP_INCLUDED |
---|
8 | #define BOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED |
---|
9 | |
---|
10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
11 | # pragma once |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <boost/config.hpp> // BOOST_MSVC. |
---|
15 | #include <boost/detail/workaround.hpp> |
---|
16 | #include <boost/iostreams/categories.hpp> |
---|
17 | #include <boost/iostreams/categories.hpp> |
---|
18 | #include <boost/iostreams/detail/adapter/range_adapter.hpp> |
---|
19 | #include <boost/iostreams/detail/config/wide_streams.hpp> |
---|
20 | #include <boost/iostreams/detail/enable_if_stream.hpp> |
---|
21 | #include <boost/iostreams/pipeline.hpp> |
---|
22 | #include <boost/iostreams/detail/push_params.hpp> |
---|
23 | #include <boost/iostreams/detail/resolve.hpp> |
---|
24 | #include <boost/mpl/bool.hpp> |
---|
25 | #include <boost/preprocessor/cat.hpp> |
---|
26 | #include <boost/preprocessor/control/iif.hpp> |
---|
27 | #include <boost/static_assert.hpp> |
---|
28 | #include <boost/type_traits/is_convertible.hpp> |
---|
29 | |
---|
30 | // |
---|
31 | // Macro: BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(mode, name, helper). |
---|
32 | // Description: Defines overloads with name 'name' which forward to a function |
---|
33 | // 'helper' which takes a filter or devide by const reference. |
---|
34 | // |
---|
35 | #define BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name, mode, ch, helper) \ |
---|
36 | BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 0, ?) \ |
---|
37 | /**/ |
---|
38 | |
---|
39 | // |
---|
40 | // Macro: BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(mode, name, helper). |
---|
41 | // Description: Defines constructors which forward to a function |
---|
42 | // 'helper' which takes a filter or device by const reference. |
---|
43 | // |
---|
44 | #define BOOST_IOSTREAMS_DEFINE_PUSH(name, mode, ch, helper) \ |
---|
45 | BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 1, void) \ |
---|
46 | /**/ |
---|
47 | |
---|
48 | //--------------------Definition of BOOST_IOSTREAMS_DEFINE_PUSH_IMPL----------// |
---|
49 | |
---|
50 | #define BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, arg, helper, has_return) \ |
---|
51 | this->helper( ::boost::iostreams::detail::resolve<mode, ch>(arg) \ |
---|
52 | BOOST_IOSTREAMS_PUSH_ARGS() ); \ |
---|
53 | /**/ |
---|
54 | |
---|
55 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \ |
---|
56 | !BOOST_WORKAROUND(__BORLANDC__, < 0x600) \ |
---|
57 | /**/ |
---|
58 | # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES |
---|
59 | # define BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \ |
---|
60 | template<typename CharType, typename TraitsType> \ |
---|
61 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
62 | name(::std::basic_streambuf<CharType, TraitsType>& sb BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
63 | { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, sb, helper, has_return); } \ |
---|
64 | template<typename CharType, typename TraitsType> \ |
---|
65 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
66 | name(::std::basic_istream<CharType, TraitsType>& is BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
67 | { BOOST_STATIC_ASSERT((!is_convertible<mode, output>::value)); \ |
---|
68 | BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, is, helper, has_return); } \ |
---|
69 | template<typename CharType, typename TraitsType> \ |
---|
70 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
71 | name(::std::basic_ostream<CharType, TraitsType>& os BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
72 | { BOOST_STATIC_ASSERT((!is_convertible<mode, input>::value)); \ |
---|
73 | BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, os, helper, has_return); } \ |
---|
74 | template<typename CharType, typename TraitsType> \ |
---|
75 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
76 | name(::std::basic_iostream<CharType, TraitsType>& io BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
77 | { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, io, helper, has_return); } \ |
---|
78 | template<typename Iter> \ |
---|
79 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
80 | name(const iterator_range<Iter>& rng BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
81 | { BOOST_PP_EXPR_IF(has_return, return) \ |
---|
82 | this->helper( ::boost::iostreams::detail::range_adapter< \ |
---|
83 | mode, iterator_range<Iter> \ |
---|
84 | >(rng) \ |
---|
85 | BOOST_IOSTREAMS_PUSH_ARGS() ); } \ |
---|
86 | template<typename Pipeline, typename Concept> \ |
---|
87 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
88 | name(const ::boost::iostreams::pipeline<Pipeline, Concept>& p) \ |
---|
89 | { p.push(*this); } \ |
---|
90 | template<typename T> \ |
---|
91 | BOOST_PP_IIF(has_return, result, explicit) \ |
---|
92 | name(const T& t BOOST_IOSTREAMS_PUSH_PARAMS() BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) \ |
---|
93 | { this->helper( ::boost::iostreams::detail::resolve<mode, ch>(t) \ |
---|
94 | BOOST_IOSTREAMS_PUSH_ARGS() ); } \ |
---|
95 | /**/ |
---|
96 | # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES |
---|
97 | # define BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \ |
---|
98 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
99 | name(::std::streambuf& sb BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
100 | { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, sb, helper, has_return); } \ |
---|
101 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
102 | name(::std::istream& is BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
103 | { BOOST_STATIC_ASSERT((!is_convertible<mode, output>::value)); \ |
---|
104 | BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, is, helper, has_return); } \ |
---|
105 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
106 | name(::std::ostream& os BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
107 | { BOOST_STATIC_ASSERT((!is_convertible<mode, input>::value)); \ |
---|
108 | BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, os, helper, has_return); } \ |
---|
109 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
110 | name(::std::iostream& io BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
111 | { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, io, helper, has_return); } \ |
---|
112 | template<typename Iter> \ |
---|
113 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
114 | name(const iterator_range<Iter>& rng BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
115 | { BOOST_PP_EXPR_IF(has_return, return) \ |
---|
116 | this->helper( ::boost::iostreams::detail::range_adapter< \ |
---|
117 | mode, iterator_range<Iter> \ |
---|
118 | >(rng) \ |
---|
119 | BOOST_IOSTREAMS_PUSH_ARGS() ); } \ |
---|
120 | template<typename Pipeline, typename Concept> \ |
---|
121 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
122 | name(const ::boost::iostreams::pipeline<Pipeline, Concept>& p) \ |
---|
123 | { p.push(*this); } \ |
---|
124 | template<typename T> \ |
---|
125 | BOOST_PP_EXPR_IF(has_return, result) \ |
---|
126 | name(const T& t BOOST_IOSTREAMS_PUSH_PARAMS() BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) \ |
---|
127 | { this->helper( ::boost::iostreams::detail::resolve<mode, ch>(t) \ |
---|
128 | BOOST_IOSTREAMS_PUSH_ARGS() ); } \ |
---|
129 | /**/ |
---|
130 | # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES |
---|
131 | #else // #if VC6, VC7.0, Borland 5.x |
---|
132 | # define BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \ |
---|
133 | template<typename T> \ |
---|
134 | void BOOST_PP_CAT(name, _msvc_impl) \ |
---|
135 | ( ::boost::mpl::true_, const T& t BOOST_IOSTREAMS_PUSH_PARAMS() ) \ |
---|
136 | { t.push(*this); } \ |
---|
137 | template<typename T> \ |
---|
138 | void BOOST_PP_CAT(name, _msvc_impl) \ |
---|
139 | ( ::boost::mpl::false_, const T& t BOOST_IOSTREAMS_PUSH_PARAMS() ) \ |
---|
140 | { this->helper( ::boost::iostreams::detail::resolve<mode, ch>(t) \ |
---|
141 | BOOST_IOSTREAMS_PUSH_ARGS() ); } \ |
---|
142 | template<typename T> \ |
---|
143 | BOOST_PP_IF(has_return, result, explicit) \ |
---|
144 | name(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \ |
---|
145 | { \ |
---|
146 | this->BOOST_PP_CAT(name, _msvc_impl) \ |
---|
147 | ( ::boost::iostreams::detail::is_pipeline<T>(), \ |
---|
148 | t BOOST_IOSTREAMS_PUSH_ARGS() ); \ |
---|
149 | } \ |
---|
150 | /**/ |
---|
151 | #endif // #if VC6, VC7.0, Borland 5.x |
---|
152 | |
---|
153 | #endif // #ifndef BOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED |
---|