Chris@16
|
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
|
Chris@16
|
2 // (C) Copyright 2003-2007 Jonathan Turkanis
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
Chris@16
|
5
|
Chris@16
|
6 // See http://www.boost.org/libs/iostreams for documentation.
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED
|
Chris@16
|
9 #define BOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED
|
Chris@16
|
10
|
Chris@16
|
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
Chris@16
|
12 # pragma once
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/config.hpp> // BOOST_MSVC, BOOST_NO_SFINAE
|
Chris@16
|
16 #include <boost/detail/workaround.hpp>
|
Chris@16
|
17 #include <boost/iostreams/detail/config/limits.hpp>
|
Chris@16
|
18 #include <boost/iostreams/detail/push_params.hpp>
|
Chris@16
|
19 #include <boost/preprocessor/arithmetic/dec.hpp>
|
Chris@16
|
20 #include <boost/preprocessor/arithmetic/inc.hpp>
|
Chris@16
|
21 #include <boost/preprocessor/punctuation/comma_if.hpp>
|
Chris@16
|
22 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
Chris@16
|
23 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
24 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
Chris@16
|
25 #include <boost/preprocessor/tuple/elem.hpp>
|
Chris@16
|
26 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 //------Macros for defining forwarding constructors and open overloads--------//
|
Chris@16
|
29
|
Chris@16
|
30 //
|
Chris@16
|
31 // Macro: BOOST_IOSTREAMS_FORWARD(class, impl, device, params, args)
|
Chris@16
|
32 // Description: Defines constructors and overloads of 'open' which construct
|
Chris@16
|
33 // a device using the specified argument list and pass it to the specified
|
Chris@16
|
34 // helper function
|
Chris@16
|
35 // class - The class name
|
Chris@16
|
36 // impl - The helper function
|
Chris@16
|
37 // device - The device type
|
Chris@16
|
38 // params - The list of formal parameters trailing the device parameter in
|
Chris@16
|
39 // the helper function's signature
|
Chris@16
|
40 // params - The list of arguments passed to the helper function, following the
|
Chris@16
|
41 // device argument
|
Chris@16
|
42 //
|
Chris@16
|
43 #define BOOST_IOSTREAMS_FORWARD(class, impl, device, params, args) \
|
Chris@16
|
44 class(const device& t params()) \
|
Chris@16
|
45 { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
|
Chris@16
|
46 class(device& t params()) \
|
Chris@16
|
47 { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
|
Chris@16
|
48 class(const ::boost::reference_wrapper<device>& ref params()) \
|
Chris@16
|
49 { this->impl(ref args()); } \
|
Chris@16
|
50 void open(const device& t params()) \
|
Chris@16
|
51 { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
|
Chris@16
|
52 void open(device& t params()) \
|
Chris@16
|
53 { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
|
Chris@16
|
54 void open(const ::boost::reference_wrapper<device>& ref params()) \
|
Chris@16
|
55 { this->impl(ref args()); } \
|
Chris@16
|
56 BOOST_PP_REPEAT_FROM_TO( \
|
Chris@16
|
57 1, BOOST_PP_INC(BOOST_IOSTREAMS_MAX_FORWARDING_ARITY), \
|
Chris@16
|
58 BOOST_IOSTREAMS_FORWARDING_CTOR, (class, impl, device) \
|
Chris@16
|
59 ) \
|
Chris@16
|
60 BOOST_PP_REPEAT_FROM_TO( \
|
Chris@16
|
61 1, BOOST_PP_INC(BOOST_IOSTREAMS_MAX_FORWARDING_ARITY), \
|
Chris@16
|
62 BOOST_IOSTREAMS_FORWARDING_FN, (class, impl, device) \
|
Chris@16
|
63 ) \
|
Chris@16
|
64 /**/
|
Chris@16
|
65 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
Chris@16
|
66 # define BOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) \
|
Chris@16
|
67 template< typename U100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
|
Chris@16
|
68 BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), typename U) > \
|
Chris@16
|
69 BOOST_PP_TUPLE_ELEM(3, 0, tuple) \
|
Chris@16
|
70 ( U100& u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
|
Chris@16
|
71 BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_DEC(n), const U, &u) \
|
Chris@16
|
72 BOOST_IOSTREAMS_DISABLE_IF_SAME(U100, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
|
Chris@16
|
73 { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
|
Chris@16
|
74 ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
|
Chris@16
|
75 ( u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
|
Chris@16
|
76 BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), u)) ); } \
|
Chris@16
|
77 /**/
|
Chris@16
|
78 # define BOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) \
|
Chris@16
|
79 template< typename U100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
|
Chris@16
|
80 BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), typename U) > \
|
Chris@16
|
81 void open \
|
Chris@16
|
82 ( U100& u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
|
Chris@16
|
83 BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_DEC(n), const U, &u) \
|
Chris@16
|
84 BOOST_IOSTREAMS_DISABLE_IF_SAME(U100, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
|
Chris@16
|
85 { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
|
Chris@16
|
86 ( u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
|
Chris@16
|
87 BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), u) ); } \
|
Chris@16
|
88 /**/
|
Chris@16
|
89 #else
|
Chris@16
|
90 # define BOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple)
|
Chris@16
|
91 # define BOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple)
|
Chris@16
|
92 #endif
|
Chris@16
|
93 #define BOOST_IOSTREAMS_FORWARDING_CTOR(z, n, tuple) \
|
Chris@16
|
94 template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \
|
Chris@16
|
95 BOOST_PP_TUPLE_ELEM(3, 0, tuple) \
|
Chris@16
|
96 (BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \
|
Chris@16
|
97 BOOST_IOSTREAMS_DISABLE_IF_SAME(U0, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
|
Chris@16
|
98 { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
|
Chris@16
|
99 ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
|
Chris@16
|
100 (BOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \
|
Chris@16
|
101 BOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) \
|
Chris@16
|
102 /**/
|
Chris@16
|
103 #define BOOST_IOSTREAMS_FORWARDING_FN(z, n, tuple) \
|
Chris@16
|
104 template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \
|
Chris@16
|
105 void open(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \
|
Chris@16
|
106 BOOST_IOSTREAMS_DISABLE_IF_SAME(U0, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
|
Chris@16
|
107 { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
|
Chris@16
|
108 ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
|
Chris@16
|
109 (BOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \
|
Chris@16
|
110 BOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) \
|
Chris@16
|
111 /**/
|
Chris@16
|
112
|
Chris@16
|
113 // Disable forwarding constructors if first parameter type is the same
|
Chris@16
|
114 // as the device type
|
Chris@16
|
115 #if !defined(BOOST_NO_SFINAE) && \
|
Chris@16
|
116 !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
Chris@16
|
117 # define BOOST_IOSTREAMS_DISABLE_IF_SAME(device, param) \
|
Chris@16
|
118 , typename boost::disable_if< boost::is_same<device, param> >::type* = 0 \
|
Chris@16
|
119 /**/
|
Chris@16
|
120 #else
|
Chris@16
|
121 # define BOOST_IOSTREAMS_DISABLE_IF_SAME(device, param)
|
Chris@16
|
122 #endif
|
Chris@16
|
123
|
Chris@16
|
124 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED
|