Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 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 NDNBOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED |
| 9 | #define NDNBOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED |
| 10 | |
| 11 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 12 | # pragma once |
| 13 | #endif |
| 14 | |
| 15 | #include <ndnboost/config.hpp> // NDNBOOST_MSVC, NDNBOOST_NO_SFINAE |
| 16 | #include <ndnboost/detail/workaround.hpp> |
| 17 | #include <ndnboost/iostreams/detail/config/limits.hpp> |
| 18 | #include <ndnboost/iostreams/detail/push_params.hpp> |
| 19 | #include <ndnboost/preprocessor/arithmetic/dec.hpp> |
| 20 | #include <ndnboost/preprocessor/arithmetic/inc.hpp> |
| 21 | #include <ndnboost/preprocessor/punctuation/comma_if.hpp> |
| 22 | #include <ndnboost/preprocessor/repetition/enum_binary_params.hpp> |
| 23 | #include <ndnboost/preprocessor/repetition/enum_params.hpp> |
| 24 | #include <ndnboost/preprocessor/repetition/repeat_from_to.hpp> |
| 25 | #include <ndnboost/preprocessor/tuple/elem.hpp> |
| 26 | #include <ndnboost/type_traits/is_same.hpp> |
| 27 | |
| 28 | //------Macros for defining forwarding constructors and open overloads--------// |
| 29 | |
| 30 | // |
| 31 | // Macro: NDNBOOST_IOSTREAMS_FORWARD(class, impl, device, params, args) |
| 32 | // Description: Defines constructors and overloads of 'open' which construct |
| 33 | // a device using the specified argument list and pass it to the specified |
| 34 | // helper function |
| 35 | // class - The class name |
| 36 | // impl - The helper function |
| 37 | // device - The device type |
| 38 | // params - The list of formal parameters trailing the device parameter in |
| 39 | // the helper function's signature |
| 40 | // params - The list of arguments passed to the helper function, following the |
| 41 | // device argument |
| 42 | // |
| 43 | #define NDNBOOST_IOSTREAMS_FORWARD(class, impl, device, params, args) \ |
| 44 | class(const device& t params()) \ |
| 45 | { this->impl(::ndnboost::iostreams::detail::wrap(t) args()); } \ |
| 46 | class(device& t params()) \ |
| 47 | { this->impl(::ndnboost::iostreams::detail::wrap(t) args()); } \ |
| 48 | class(const ::ndnboost::reference_wrapper<device>& ref params()) \ |
| 49 | { this->impl(ref args()); } \ |
| 50 | void open(const device& t params()) \ |
| 51 | { this->impl(::ndnboost::iostreams::detail::wrap(t) args()); } \ |
| 52 | void open(device& t params()) \ |
| 53 | { this->impl(::ndnboost::iostreams::detail::wrap(t) args()); } \ |
| 54 | void open(const ::ndnboost::reference_wrapper<device>& ref params()) \ |
| 55 | { this->impl(ref args()); } \ |
| 56 | NDNBOOST_PP_REPEAT_FROM_TO( \ |
| 57 | 1, NDNBOOST_PP_INC(NDNBOOST_IOSTREAMS_MAX_FORWARDING_ARITY), \ |
| 58 | NDNBOOST_IOSTREAMS_FORWARDING_CTOR, (class, impl, device) \ |
| 59 | ) \ |
| 60 | NDNBOOST_PP_REPEAT_FROM_TO( \ |
| 61 | 1, NDNBOOST_PP_INC(NDNBOOST_IOSTREAMS_MAX_FORWARDING_ARITY), \ |
| 62 | NDNBOOST_IOSTREAMS_FORWARDING_FN, (class, impl, device) \ |
| 63 | ) \ |
| 64 | /**/ |
| 65 | #if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300) |
| 66 | # define NDNBOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) \ |
| 67 | template< typename U100 NDNBOOST_PP_COMMA_IF(NDNBOOST_PP_DEC(n)) \ |
| 68 | NDNBOOST_PP_ENUM_PARAMS_Z(z, NDNBOOST_PP_DEC(n), typename U) > \ |
| 69 | NDNBOOST_PP_TUPLE_ELEM(3, 0, tuple) \ |
| 70 | ( U100& u100 NDNBOOST_PP_COMMA_IF(NDNBOOST_PP_DEC(n)) \ |
| 71 | NDNBOOST_PP_ENUM_BINARY_PARAMS_Z(z, NDNBOOST_PP_DEC(n), const U, &u) \ |
| 72 | NDNBOOST_IOSTREAMS_DISABLE_IF_SAME(U100, NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple))) \ |
| 73 | { this->NDNBOOST_PP_TUPLE_ELEM(3, 1, tuple) \ |
| 74 | ( NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple) \ |
| 75 | ( u100 NDNBOOST_PP_COMMA_IF(NDNBOOST_PP_DEC(n)) \ |
| 76 | NDNBOOST_PP_ENUM_PARAMS_Z(z, NDNBOOST_PP_DEC(n), u)) ); } \ |
| 77 | /**/ |
| 78 | # define NDNBOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) \ |
| 79 | template< typename U100 NDNBOOST_PP_COMMA_IF(NDNBOOST_PP_DEC(n)) \ |
| 80 | NDNBOOST_PP_ENUM_PARAMS_Z(z, NDNBOOST_PP_DEC(n), typename U) > \ |
| 81 | void open \ |
| 82 | ( U100& u100 NDNBOOST_PP_COMMA_IF(NDNBOOST_PP_DEC(n)) \ |
| 83 | NDNBOOST_PP_ENUM_BINARY_PARAMS_Z(z, NDNBOOST_PP_DEC(n), const U, &u) \ |
| 84 | NDNBOOST_IOSTREAMS_DISABLE_IF_SAME(U100, NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple))) \ |
| 85 | { this->NDNBOOST_PP_TUPLE_ELEM(3, 1, tuple) \ |
| 86 | ( u100 NDNBOOST_PP_COMMA_IF(NDNBOOST_PP_DEC(n)) \ |
| 87 | NDNBOOST_PP_ENUM_PARAMS_Z(z, NDNBOOST_PP_DEC(n), u) ); } \ |
| 88 | /**/ |
| 89 | #else |
| 90 | # define NDNBOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) |
| 91 | # define NDNBOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) |
| 92 | #endif |
| 93 | #define NDNBOOST_IOSTREAMS_FORWARDING_CTOR(z, n, tuple) \ |
| 94 | template<NDNBOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \ |
| 95 | NDNBOOST_PP_TUPLE_ELEM(3, 0, tuple) \ |
| 96 | (NDNBOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \ |
| 97 | NDNBOOST_IOSTREAMS_DISABLE_IF_SAME(U0, NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple))) \ |
| 98 | { this->NDNBOOST_PP_TUPLE_ELEM(3, 1, tuple) \ |
| 99 | ( NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple) \ |
| 100 | (NDNBOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \ |
| 101 | NDNBOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) \ |
| 102 | /**/ |
| 103 | #define NDNBOOST_IOSTREAMS_FORWARDING_FN(z, n, tuple) \ |
| 104 | template<NDNBOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \ |
| 105 | void open(NDNBOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \ |
| 106 | NDNBOOST_IOSTREAMS_DISABLE_IF_SAME(U0, NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple))) \ |
| 107 | { this->NDNBOOST_PP_TUPLE_ELEM(3, 1, tuple) \ |
| 108 | ( NDNBOOST_PP_TUPLE_ELEM(3, 2, tuple) \ |
| 109 | (NDNBOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \ |
| 110 | NDNBOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) \ |
| 111 | /**/ |
| 112 | |
| 113 | // Disable forwarding constructors if first parameter type is the same |
| 114 | // as the device type |
| 115 | #if !defined(NDNBOOST_NO_SFINAE) && \ |
| 116 | !NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x592)) |
| 117 | # define NDNBOOST_IOSTREAMS_DISABLE_IF_SAME(device, param) \ |
| 118 | , typename ndnboost::disable_if< ndnboost::is_same<device, param> >::type* = 0 \ |
| 119 | /**/ |
| 120 | #else |
| 121 | # define NDNBOOST_IOSTREAMS_DISABLE_IF_SAME(device, param) |
| 122 | #endif |
| 123 | |
| 124 | #endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED |