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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
15 #include <boost/config.hpp> // BOOST_MSVC.
16 #include <boost/detail/workaround.hpp>
17 #include <boost/iostreams/detail/template_params.hpp>
18 #include <boost/iostreams/traits.hpp>
19 #include <boost/mpl/bool.hpp>
20 #include <boost/preprocessor/punctuation/comma_if.hpp>
21 #include <boost/preprocessor/repetition/enum_params.hpp>
22 #include <boost/static_assert.hpp>
23 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
24 # include <boost/type_traits/is_base_and_derived.hpp>
27 #define BOOST_IOSTREAMS_PIPABLE(filter, arity) \
28 template< BOOST_PP_ENUM_PARAMS(arity, typename T) \
29 BOOST_PP_COMMA_IF(arity) typename Component> \
30 ::boost::iostreams::pipeline< \
31 ::boost::iostreams::detail::pipeline_segment< \
32 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
35 > operator|( const filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T)& f, \
36 const Component& c ) \
38 typedef ::boost::iostreams::detail::pipeline_segment< \
39 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
41 return ::boost::iostreams::pipeline<segment, Component> \
46 namespace boost
{ namespace iostreams
{
48 template<typename Pipeline
, typename Component
>
53 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
54 struct pipeline_base
{ };
58 : is_base_and_derived
<pipeline_base
, T
>
61 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
63 struct is_pipeline
: mpl::false_
{ };
65 template<typename Pipeline
, typename Component
>
66 struct is_pipeline
< pipeline
<Pipeline
, Component
> > : mpl::true_
{ };
69 template<typename Component
>
70 class pipeline_segment
71 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
76 pipeline_segment(const Component
& component
)
77 : component_(component
)
80 void for_each(Fn fn
) const { fn(component_
); }
81 template<typename Chain
>
82 void push(Chain
& chn
) const { chn
.push(component_
); }
84 pipeline_segment
operator=(const pipeline_segment
&);
85 const Component
& component_
;
88 } // End namespace detail.
90 //------------------Definition of Pipeline------------------------------------//
92 template<typename Pipeline
, typename Component
>
93 struct pipeline
: Pipeline
{
94 typedef Pipeline pipeline_type
;
95 typedef Component component_type
;
96 pipeline(const Pipeline
& p
, const Component
& component
)
97 : Pipeline(p
), component_(component
)
100 void for_each(Fn fn
) const
102 Pipeline::for_each(fn
);
105 template<typename Chain
>
106 void push(Chain
& chn
) const
109 chn
.push(component_
);
111 const Pipeline
& tail() const { return *this; }
112 const Component
& head() const { return component_
; }
114 pipeline
operator=(const pipeline
&);
115 const Component
& component_
;
118 template<typename Pipeline
, typename Filter
, typename Component
>
119 pipeline
<pipeline
<Pipeline
, Filter
>, Component
>
120 operator|(const pipeline
<Pipeline
, Filter
>& p
, const Component
& cmp
)
122 BOOST_STATIC_ASSERT(is_filter
<Filter
>::value
);
123 return pipeline
<pipeline
<Pipeline
, Filter
>, Component
>(p
, cmp
);
126 } } // End namespaces iostreams, boost.
128 #endif // #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED