]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/iostreams/pipeline.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / iostreams / pipeline.hpp
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 BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
10
11 #if defined(_MSC_VER)
12 # pragma once
13 #endif
14
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
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) \
30 >, \
31 Component \
32 > operator|( const filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T)& f, \
33 const Component& c ) \
34 { \
35 typedef ::boost::iostreams::detail::pipeline_segment< \
36 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
37 > segment; \
38 return ::boost::iostreams::pipeline<segment, Component> \
39 (segment(f), c); \
40 } \
41 /**/
42
43 namespace boost { namespace iostreams {
44
45 template<typename Pipeline, typename Component>
46 struct pipeline;
47
48 namespace detail {
49
50 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
51 template<typename T>
52 struct is_pipeline : mpl::false_ { };
53
54 template<typename Pipeline, typename Component>
55 struct is_pipeline< pipeline<Pipeline, Component> > : mpl::true_ { };
56 #endif
57
58 template<typename Component>
59 class pipeline_segment
60 {
61 public:
62 pipeline_segment(const Component& component)
63 : component_(component)
64 { }
65 template<typename Fn>
66 void for_each(Fn fn) const { fn(component_); }
67 template<typename Chain>
68 void push(Chain& chn) const { chn.push(component_); }
69 private:
70 pipeline_segment operator=(const pipeline_segment&);
71 const Component& component_;
72 };
73
74 } // End namespace detail.
75
76 //------------------Definition of Pipeline------------------------------------//
77
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)
84 { }
85 template<typename Fn>
86 void for_each(Fn fn) const
87 {
88 Pipeline::for_each(fn);
89 fn(component_);
90 }
91 template<typename Chain>
92 void push(Chain& chn) const
93 {
94 Pipeline::push(chn);
95 chn.push(component_);
96 }
97 const Pipeline& tail() const { return *this; }
98 const Component& head() const { return component_; }
99 private:
100 pipeline operator=(const pipeline&);
101 const Component& component_;
102 };
103
104 template<typename Pipeline, typename Filter, typename Component>
105 pipeline<pipeline<Pipeline, Filter>, Component>
106 operator|(const pipeline<Pipeline, Filter>& p, const Component& cmp)
107 {
108 BOOST_STATIC_ASSERT(is_filter<Filter>::value);
109 return pipeline<pipeline<Pipeline, Filter>, Component>(p, cmp);
110 }
111
112 } } // End namespaces iostreams, boost.
113
114 #endif // #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED