Chris@16
|
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
|
Chris@16
|
2 // (C) Copyright 2003-2007 Jonathan Turkanis
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
Chris@16
|
5
|
Chris@16
|
6 // See http://www.boost.org/libs/iostreams for documentation.
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
|
Chris@16
|
9 #define BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
|
Chris@16
|
10
|
Chris@16
|
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
Chris@16
|
12 # pragma once
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/config.hpp> // BOOST_MSVC.
|
Chris@16
|
16 #include <boost/detail/workaround.hpp>
|
Chris@16
|
17 #include <boost/iostreams/detail/template_params.hpp>
|
Chris@16
|
18 #include <boost/iostreams/traits.hpp>
|
Chris@16
|
19 #include <boost/mpl/bool.hpp>
|
Chris@16
|
20 #include <boost/preprocessor/punctuation/comma_if.hpp>
|
Chris@16
|
21 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
22 #include <boost/static_assert.hpp>
|
Chris@16
|
23 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
Chris@16
|
24 # include <boost/type_traits/is_base_and_derived.hpp>
|
Chris@16
|
25 #endif
|
Chris@16
|
26
|
Chris@16
|
27 #define BOOST_IOSTREAMS_PIPABLE(filter, arity) \
|
Chris@16
|
28 template< BOOST_PP_ENUM_PARAMS(arity, typename T) \
|
Chris@16
|
29 BOOST_PP_COMMA_IF(arity) typename Component> \
|
Chris@16
|
30 ::boost::iostreams::pipeline< \
|
Chris@16
|
31 ::boost::iostreams::detail::pipeline_segment< \
|
Chris@16
|
32 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
|
Chris@16
|
33 >, \
|
Chris@16
|
34 Component \
|
Chris@16
|
35 > operator|( const filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T)& f, \
|
Chris@16
|
36 const Component& c ) \
|
Chris@16
|
37 { \
|
Chris@16
|
38 typedef ::boost::iostreams::detail::pipeline_segment< \
|
Chris@16
|
39 filter BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T) \
|
Chris@16
|
40 > segment; \
|
Chris@16
|
41 return ::boost::iostreams::pipeline<segment, Component> \
|
Chris@16
|
42 (segment(f), c); \
|
Chris@16
|
43 } \
|
Chris@16
|
44 /**/
|
Chris@16
|
45
|
Chris@16
|
46 namespace boost { namespace iostreams {
|
Chris@16
|
47
|
Chris@16
|
48 template<typename Pipeline, typename Component>
|
Chris@16
|
49 struct pipeline;
|
Chris@16
|
50
|
Chris@16
|
51 namespace detail {
|
Chris@16
|
52
|
Chris@16
|
53 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
Chris@16
|
54 struct pipeline_base { };
|
Chris@16
|
55
|
Chris@16
|
56 template<typename T>
|
Chris@16
|
57 struct is_pipeline
|
Chris@16
|
58 : is_base_and_derived<pipeline_base, T>
|
Chris@16
|
59 { };
|
Chris@16
|
60 #endif
|
Chris@16
|
61 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
Chris@16
|
62 template<typename T>
|
Chris@16
|
63 struct is_pipeline : mpl::false_ { };
|
Chris@16
|
64
|
Chris@16
|
65 template<typename Pipeline, typename Component>
|
Chris@16
|
66 struct is_pipeline< pipeline<Pipeline, Component> > : mpl::true_ { };
|
Chris@16
|
67 #endif
|
Chris@16
|
68
|
Chris@16
|
69 template<typename Component>
|
Chris@16
|
70 class pipeline_segment
|
Chris@16
|
71 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
Chris@16
|
72 : pipeline_base
|
Chris@16
|
73 #endif
|
Chris@16
|
74 {
|
Chris@16
|
75 public:
|
Chris@16
|
76 pipeline_segment(const Component& component)
|
Chris@16
|
77 : component_(component)
|
Chris@16
|
78 { }
|
Chris@16
|
79 template<typename Fn>
|
Chris@16
|
80 void for_each(Fn fn) const { fn(component_); }
|
Chris@16
|
81 template<typename Chain>
|
Chris@16
|
82 void push(Chain& chn) const { chn.push(component_); }
|
Chris@16
|
83 private:
|
Chris@16
|
84 pipeline_segment operator=(const pipeline_segment&);
|
Chris@16
|
85 const Component& component_;
|
Chris@16
|
86 };
|
Chris@16
|
87
|
Chris@16
|
88 } // End namespace detail.
|
Chris@16
|
89
|
Chris@16
|
90 //------------------Definition of Pipeline------------------------------------//
|
Chris@16
|
91
|
Chris@16
|
92 template<typename Pipeline, typename Component>
|
Chris@16
|
93 struct pipeline : Pipeline {
|
Chris@16
|
94 typedef Pipeline pipeline_type;
|
Chris@16
|
95 typedef Component component_type;
|
Chris@16
|
96 pipeline(const Pipeline& p, const Component& component)
|
Chris@16
|
97 : Pipeline(p), component_(component)
|
Chris@16
|
98 { }
|
Chris@16
|
99 template<typename Fn>
|
Chris@16
|
100 void for_each(Fn fn) const
|
Chris@16
|
101 {
|
Chris@16
|
102 Pipeline::for_each(fn);
|
Chris@16
|
103 fn(component_);
|
Chris@16
|
104 }
|
Chris@16
|
105 template<typename Chain>
|
Chris@16
|
106 void push(Chain& chn) const
|
Chris@16
|
107 {
|
Chris@16
|
108 Pipeline::push(chn);
|
Chris@16
|
109 chn.push(component_);
|
Chris@16
|
110 }
|
Chris@16
|
111 const Pipeline& tail() const { return *this; }
|
Chris@16
|
112 const Component& head() const { return component_; }
|
Chris@16
|
113 private:
|
Chris@16
|
114 pipeline operator=(const pipeline&);
|
Chris@16
|
115 const Component& component_;
|
Chris@16
|
116 };
|
Chris@16
|
117
|
Chris@16
|
118 template<typename Pipeline, typename Filter, typename Component>
|
Chris@16
|
119 pipeline<pipeline<Pipeline, Filter>, Component>
|
Chris@16
|
120 operator|(const pipeline<Pipeline, Filter>& p, const Component& cmp)
|
Chris@16
|
121 {
|
Chris@16
|
122 BOOST_STATIC_ASSERT(is_filter<Filter>::value);
|
Chris@16
|
123 return pipeline<pipeline<Pipeline, Filter>, Component>(p, cmp);
|
Chris@16
|
124 }
|
Chris@16
|
125
|
Chris@16
|
126 } } // End namespaces iostreams, boost.
|
Chris@16
|
127
|
Chris@16
|
128 #endif // #ifndef BOOST_IOSTREAMS_PIPABLE_HPP_INCLUDED
|