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_DETAIL_PUSH_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED
10 
11 #if defined(_MSC_VER)
12 # pragma once
13 #endif
14 
15 #include <boost/config.hpp> // BOOST_MSVC.
16 #include <boost/detail/workaround.hpp>
17 #include <boost/iostreams/categories.hpp>
18 #include <boost/iostreams/categories.hpp>
19 #include <boost/iostreams/detail/adapter/range_adapter.hpp>
20 #include <boost/iostreams/detail/config/wide_streams.hpp>
21 #include <boost/iostreams/detail/enable_if_stream.hpp>
22 #include <boost/iostreams/pipeline.hpp>
23 #include <boost/iostreams/detail/push_params.hpp>
24 #include <boost/iostreams/detail/resolve.hpp>
25 #include <boost/mpl/bool.hpp>
26 #include <boost/preprocessor/cat.hpp>
27 #include <boost/preprocessor/control/iif.hpp>
28 #include <boost/static_assert.hpp>
29 #include <boost/type_traits/is_convertible.hpp>
30 
31 //
32 // Macro: BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name, mode, ch, helper).
33 // Description: Defines overloads with name 'name' which forward to a function
34 //      'helper' which takes a filter or devide by const reference.
35 //
36 #define BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name, mode, ch, helper) \
37     BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 0, ?) \
38     /**/
39 
40 //
41 // Macro: BOOST_IOSTREAMS_DEFINE_PUSH(name, mode, ch, helper).
42 // Description: Defines constructors which forward to a function
43 //      'helper' which takes a filter or device by const reference.
44 //
45 #define BOOST_IOSTREAMS_DEFINE_PUSH(name, mode, ch, helper) \
46     BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 1, void) \
47     /**/
48 
49 //--------------------Definition of BOOST_IOSTREAMS_DEFINE_PUSH_IMPL----------//
50 
51 #define BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, arg, helper, has_return) \
52     this->helper( ::boost::iostreams::detail::resolve<mode, ch>(arg) \
53                   BOOST_IOSTREAMS_PUSH_ARGS() ); \
54     /**/
55 
56 #if !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
154