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
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>
24 #define BOOST_IOSTREAMS_PIPABLE(filter, arity) \
25 template< BOOST_PP_ENUM_PARAMS(arity, typename T) \
26 BOOST_PP_COMMA_IF(arity) typename Component> \
27 ::boost::iostreams::pipeline< \
28 ::boost::iostreams::detail::pipeline_segment< \
29 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
32 > operator|( const filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T)& f, \
33 const Component& c ) \
35 typedef ::boost::iostreams::detail::pipeline_segment< \
36 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
38 return ::boost::iostreams::pipeline<segment, Component> \
43 namespace boost { namespace iostreams {
45 template<typename Pipeline, typename Component>
50 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
52 struct is_pipeline : mpl::false_ { };
54 template<typename Pipeline, typename Component>
55 struct is_pipeline< pipeline<Pipeline, Component> > : mpl::true_ { };
58 template<typename Component>
59 class pipeline_segment
62 pipeline_segment(const Component& component)
63 : component_(component)
66 void for_each(Fn fn) const { fn(component_); }
67 template<typename Chain>
68 void push(Chain& chn) const { chn.push(component_); }
70 pipeline_segment operator=(const pipeline_segment&);
71 const Component& component_;
74 } // End namespace detail.
76 //------------------Definition of Pipeline------------------------------------//
78 template<typename Pipeline, typename Component>
79 struct pipeline : Pipeline {
80 typedef Pipeline pipeline_type;
81 typedef Component component_type;
82 pipeline(const Pipeline& p, const Component& component)
83 : Pipeline(p), component_(component)
86 void for_each(Fn fn) const
88 Pipeline::for_each(fn);
91 template<typename Chain>
92 void push(Chain& chn) const
97 const Pipeline& tail() const { return *this; }
98 const Component& head() const { return component_; }
100 pipeline operator=(const pipeline&);
101 const Component& component_;
104 template<typename Pipeline, typename Filter, typename Component>
105 pipeline<pipeline<Pipeline, Filter>, Component>
106 operator|(const pipeline<Pipeline, Filter>& p, const Component& cmp)
108 BOOST_STATIC_ASSERT(is_filter<Filter>::value);
109 return pipeline<pipeline<Pipeline, Filter>, Component>(p, cmp);
112 } } // End namespaces iostreams, boost.
114 #endif // #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED