blob: 5152d6a43a85e410759f3338e1e1c1dc9368af59 [file] [log] [blame]
Jeff Thompson86b6d642013-10-17 15:01:56 -07001// (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_PUSH_HPP_INCLUDED
9#define NDNBOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED
10
11#if defined(_MSC_VER) && (_MSC_VER >= 1020)
12# pragma once
13#endif
14
15#include <ndnboost/config.hpp> // NDNBOOST_MSVC.
16#include <ndnboost/detail/workaround.hpp>
17#include <ndnboost/iostreams/categories.hpp>
18#include <ndnboost/iostreams/categories.hpp>
19#include <ndnboost/iostreams/detail/adapter/range_adapter.hpp>
20#include <ndnboost/iostreams/detail/config/wide_streams.hpp>
21#include <ndnboost/iostreams/detail/enable_if_stream.hpp>
22#include <ndnboost/iostreams/pipeline.hpp>
23#include <ndnboost/iostreams/detail/push_params.hpp>
24#include <ndnboost/iostreams/detail/resolve.hpp>
25#include <ndnboost/mpl/bool.hpp>
26#include <ndnboost/preprocessor/cat.hpp>
27#include <ndnboost/preprocessor/control/iif.hpp>
28#include <ndnboost/static_assert.hpp>
29#include <ndnboost/type_traits/is_convertible.hpp>
30
31//
32// Macro: NDNBOOST_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 NDNBOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name, mode, ch, helper) \
37 NDNBOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 0, ?) \
38 /**/
39
40//
41// Macro: NDNBOOST_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 NDNBOOST_IOSTREAMS_DEFINE_PUSH(name, mode, ch, helper) \
46 NDNBOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 1, void) \
47 /**/
48
49//--------------------Definition of NDNBOOST_IOSTREAMS_DEFINE_PUSH_IMPL----------//
50
51#define NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, arg, helper, has_return) \
52 this->helper( ::ndnboost::iostreams::detail::resolve<mode, ch>(arg) \
53 NDNBOOST_IOSTREAMS_PUSH_ARGS() ); \
54 /**/
55
56#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1300) && \
57 !NDNBOOST_WORKAROUND(__BORLANDC__, < 0x600) \
58 /**/
59# ifndef NDNBOOST_IOSTREAMS_NO_STREAM_TEMPLATES
60# define NDNBOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \
61 template<typename CharType, typename TraitsType> \
62 NDNBOOST_PP_IIF(has_return, result, explicit) \
63 name(::std::basic_streambuf<CharType, TraitsType>& sb NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
64 { NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, sb, helper, has_return); } \
65 template<typename CharType, typename TraitsType> \
66 NDNBOOST_PP_IIF(has_return, result, explicit) \
67 name(::std::basic_istream<CharType, TraitsType>& is NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
68 { NDNBOOST_STATIC_ASSERT((!is_convertible<mode, output>::value)); \
69 NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, is, helper, has_return); } \
70 template<typename CharType, typename TraitsType> \
71 NDNBOOST_PP_IIF(has_return, result, explicit) \
72 name(::std::basic_ostream<CharType, TraitsType>& os NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
73 { NDNBOOST_STATIC_ASSERT((!is_convertible<mode, input>::value)); \
74 NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, os, helper, has_return); } \
75 template<typename CharType, typename TraitsType> \
76 NDNBOOST_PP_IIF(has_return, result, explicit) \
77 name(::std::basic_iostream<CharType, TraitsType>& io NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
78 { NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, io, helper, has_return); } \
79 template<typename Iter> \
80 NDNBOOST_PP_IIF(has_return, result, explicit) \
81 name(const iterator_range<Iter>& rng NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
82 { NDNBOOST_PP_EXPR_IF(has_return, return) \
83 this->helper( ::ndnboost::iostreams::detail::range_adapter< \
84 mode, iterator_range<Iter> \
85 >(rng) \
86 NDNBOOST_IOSTREAMS_PUSH_ARGS() ); } \
87 template<typename Pipeline, typename Concept> \
88 NDNBOOST_PP_IIF(has_return, result, explicit) \
89 name(const ::ndnboost::iostreams::pipeline<Pipeline, Concept>& p) \
90 { p.push(*this); } \
91 template<typename T> \
92 NDNBOOST_PP_IIF(has_return, result, explicit) \
93 name(const T& t NDNBOOST_IOSTREAMS_PUSH_PARAMS() NDNBOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) \
94 { this->helper( ::ndnboost::iostreams::detail::resolve<mode, ch>(t) \
95 NDNBOOST_IOSTREAMS_PUSH_ARGS() ); } \
96 /**/
97# else // # ifndef NDNBOOST_IOSTREAMS_NO_STREAM_TEMPLATES
98# define NDNBOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \
99 NDNBOOST_PP_IF(has_return, result, explicit) \
100 name(::std::streambuf& sb NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
101 { NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, sb, helper, has_return); } \
102 NDNBOOST_PP_IF(has_return, result, explicit) \
103 name(::std::istream& is NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
104 { NDNBOOST_STATIC_ASSERT((!is_convertible<mode, output>::value)); \
105 NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, is, helper, has_return); } \
106 NDNBOOST_PP_IF(has_return, result, explicit) \
107 name(::std::ostream& os NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
108 { NDNBOOST_STATIC_ASSERT((!is_convertible<mode, input>::value)); \
109 NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, os, helper, has_return); } \
110 NDNBOOST_PP_IF(has_return, result, explicit) \
111 name(::std::iostream& io NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
112 { NDNBOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, io, helper, has_return); } \
113 template<typename Iter> \
114 NDNBOOST_PP_IF(has_return, result, explicit) \
115 name(const iterator_range<Iter>& rng NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
116 { NDNBOOST_PP_EXPR_IF(has_return, return) \
117 this->helper( ::ndnboost::iostreams::detail::range_adapter< \
118 mode, iterator_range<Iter> \
119 >(rng) \
120 NDNBOOST_IOSTREAMS_PUSH_ARGS() ); } \
121 template<typename Pipeline, typename Concept> \
122 NDNBOOST_PP_IF(has_return, result, explicit) \
123 name(const ::ndnboost::iostreams::pipeline<Pipeline, Concept>& p) \
124 { p.push(*this); } \
125 template<typename T> \
126 NDNBOOST_PP_EXPR_IF(has_return, result) \
127 name(const T& t NDNBOOST_IOSTREAMS_PUSH_PARAMS() NDNBOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) \
128 { this->helper( ::ndnboost::iostreams::detail::resolve<mode, ch>(t) \
129 NDNBOOST_IOSTREAMS_PUSH_ARGS() ); } \
130 /**/
131# endif // # ifndef NDNBOOST_IOSTREAMS_NO_STREAM_TEMPLATES
132#else // #if VC6, VC7.0, Borland 5.x
133# define NDNBOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \
134 template<typename T> \
135 void NDNBOOST_PP_CAT(name, _msvc_impl) \
136 ( ::ndnboost::mpl::true_, const T& t NDNBOOST_IOSTREAMS_PUSH_PARAMS() ) \
137 { t.push(*this); } \
138 template<typename T> \
139 void NDNBOOST_PP_CAT(name, _msvc_impl) \
140 ( ::ndnboost::mpl::false_, const T& t NDNBOOST_IOSTREAMS_PUSH_PARAMS() ) \
141 { this->helper( ::ndnboost::iostreams::detail::resolve<mode, ch>(t) \
142 NDNBOOST_IOSTREAMS_PUSH_ARGS() ); } \
143 template<typename T> \
144 NDNBOOST_PP_IF(has_return, result, explicit) \
145 name(const T& t NDNBOOST_IOSTREAMS_PUSH_PARAMS()) \
146 { \
147 this->NDNBOOST_PP_CAT(name, _msvc_impl) \
148 ( ::ndnboost::iostreams::detail::is_pipeline<T>(), \
149 t NDNBOOST_IOSTREAMS_PUSH_ARGS() ); \
150 } \
151 /**/
152#endif // #if VC6, VC7.0, Borland 5.x
153
154#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED