File indexing completed on 2025-01-18 09:38:54
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
0010
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif
0014
0015 #include <boost/config.hpp> // BOOST_MSVC.
0016 #include <boost/detail/workaround.hpp>
0017 #include <boost/iostreams/detail/template_params.hpp>
0018 #include <boost/iostreams/traits.hpp>
0019 #include <boost/mpl/bool.hpp>
0020 #include <boost/preprocessor/punctuation/comma_if.hpp>
0021 #include <boost/preprocessor/repetition/enum_params.hpp>
0022 #include <boost/static_assert.hpp>
0023
0024 #define BOOST_IOSTREAMS_PIPABLE(filter, arity) \
0025 template< BOOST_PP_ENUM_PARAMS(arity, typename T) \
0026 BOOST_PP_COMMA_IF(arity) typename Component> \
0027 ::boost::iostreams::pipeline< \
0028 ::boost::iostreams::detail::pipeline_segment< \
0029 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
0030 >, \
0031 Component \
0032 > operator|( const filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T)& f, \
0033 const Component& c ) \
0034 { \
0035 typedef ::boost::iostreams::detail::pipeline_segment< \
0036 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
0037 > segment; \
0038 return ::boost::iostreams::pipeline<segment, Component> \
0039 (segment(f), c); \
0040 } \
0041
0042
0043 namespace boost { namespace iostreams {
0044
0045 template<typename Pipeline, typename Component>
0046 struct pipeline;
0047
0048 namespace detail {
0049
0050 #if BOOST_WORKAROUND(BOOST_BORLANDC, < 0x600)
0051 template<typename T>
0052 struct is_pipeline : mpl::false_ { };
0053
0054 template<typename Pipeline, typename Component>
0055 struct is_pipeline< pipeline<Pipeline, Component> > : mpl::true_ { };
0056 #endif
0057
0058 template<typename Component>
0059 class pipeline_segment
0060 {
0061 public:
0062 pipeline_segment(const Component& component)
0063 : component_(component)
0064 { }
0065 template<typename Fn>
0066 void for_each(Fn fn) const { fn(component_); }
0067 template<typename Chain>
0068 void push(Chain& chn) const { chn.push(component_); }
0069 private:
0070 pipeline_segment operator=(const pipeline_segment&);
0071 const Component& component_;
0072 };
0073
0074 }
0075
0076
0077
0078 template<typename Pipeline, typename Component>
0079 struct pipeline : Pipeline {
0080 typedef Pipeline pipeline_type;
0081 typedef Component component_type;
0082 pipeline(const Pipeline& p, const Component& component)
0083 : Pipeline(p), component_(component)
0084 { }
0085 template<typename Fn>
0086 void for_each(Fn fn) const
0087 {
0088 Pipeline::for_each(fn);
0089 fn(component_);
0090 }
0091 template<typename Chain>
0092 void push(Chain& chn) const
0093 {
0094 Pipeline::push(chn);
0095 chn.push(component_);
0096 }
0097 const Pipeline& tail() const { return *this; }
0098 const Component& head() const { return component_; }
0099 private:
0100 pipeline operator=(const pipeline&);
0101 const Component& component_;
0102 };
0103
0104 template<typename Pipeline, typename Filter, typename Component>
0105 pipeline<pipeline<Pipeline, Filter>, Component>
0106 operator|(const pipeline<Pipeline, Filter>& p, const Component& cmp)
0107 {
0108 BOOST_STATIC_ASSERT(is_filter<Filter>::value);
0109 return pipeline<pipeline<Pipeline, Filter>, Component>(p, cmp);
0110 }
0111
0112 } }
0113
0114 #endif