fix doc example typo
[boost.git] / boost / iostreams / detail / functional.hpp
bloba7b9b6bbb12e8a2ae622024915cf7449d1be1bf5
1 /*
2 * Distributed under the Boost Software License, Version 1.0.(See accompanying
3 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
4 *
5 * See http://www.boost.org/libs/iostreams for documentation.
7 * File: boost/iostreams/detail/functional.hpp
8 * Date: Sun Dec 09 05:38:03 MST 2007
9 * Copyright: 2007-2008 CodeRage, LLC
10 * Author: Jonathan Turkanis
11 * Contact: turkanis at coderage dot com
13 * Defines several function objects and object generators for use with
14 * execute_all()
17 #ifndef BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED
18 #define BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED
20 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
21 # pragma once
22 #endif
24 #include <boost/iostreams/close.hpp>
25 #include <boost/iostreams/detail/ios.hpp> // BOOST_IOS
27 namespace boost { namespace iostreams { namespace detail {
29 // Function objects and object generators for invoking
30 // boost::iostreams::close
32 template<typename T>
33 class device_close_operation {
34 public:
35 typedef void result_type;
36 device_close_operation(T& t, BOOST_IOS::openmode which)
37 : t_(t), which_(which)
38 { }
39 void operator()() const { boost::iostreams::close(t_, which_); }
40 private:
41 device_close_operation& operator=(const device_close_operation&);
42 T& t_;
43 BOOST_IOS::openmode which_;
46 template<typename T, typename Sink>
47 class filter_close_operation {
48 public:
49 typedef void result_type;
50 filter_close_operation(T& t, Sink& snk, BOOST_IOS::openmode which)
51 : t_(t), snk_(snk), which_(which)
52 { }
53 void operator()() const { boost::iostreams::close(t_, snk_, which_); }
54 private:
55 filter_close_operation& operator=(const filter_close_operation&);
56 T& t_;
57 Sink& snk_;
58 BOOST_IOS::openmode which_;
61 template<typename T>
62 device_close_operation<T>
63 call_close(T& t, BOOST_IOS::openmode which)
64 { return device_close_operation<T>(t, which); }
66 template<typename T, typename Sink>
67 filter_close_operation<T, Sink>
68 call_close(T& t, Sink& snk, BOOST_IOS::openmode which)
69 { return filter_close_operation<T, Sink>(t, snk, which); }
71 // Function objects and object generators for invoking
72 // boost::iostreams::detail::close_all
74 template<typename T>
75 class device_close_all_operation {
76 public:
77 typedef void result_type;
78 device_close_all_operation(T& t) : t_(t) { }
79 void operator()() const { detail::close_all(t_); }
80 private:
81 device_close_all_operation& operator=(const device_close_all_operation&);
82 T& t_;
85 template<typename T, typename Sink>
86 class filter_close_all_operation {
87 public:
88 typedef void result_type;
89 filter_close_all_operation(T& t, Sink& snk) : t_(t), snk_(snk) { }
90 void operator()() const { detail::close_all(t_, snk_); }
91 private:
92 filter_close_all_operation& operator=(const filter_close_all_operation&);
93 T& t_;
94 Sink& snk_;
97 template<typename T>
98 device_close_all_operation<T> call_close_all(T& t)
99 { return device_close_all_operation<T>(t); }
101 template<typename T, typename Sink>
102 filter_close_all_operation<T, Sink>
103 call_close_all(T& t, Sink& snk)
104 { return filter_close_all_operation<T, Sink>(t, snk); }
106 // Function object and object generator for invoking a
107 // member function void close(std::ios_base::openmode)
109 template<typename T>
110 class member_close_operation {
111 public:
112 typedef void result_type;
113 member_close_operation(T& t, BOOST_IOS::openmode which)
114 : t_(t), which_(which)
116 void operator()() const { t_.close(which_); }
117 private:
118 member_close_operation& operator=(const member_close_operation&);
119 T& t_;
120 BOOST_IOS::openmode which_;
123 template<typename T>
124 member_close_operation<T> call_member_close(T& t, BOOST_IOS::openmode which)
125 { return member_close_operation<T>(t, which); }
127 // Function object and object generator for invoking a
128 // member function void reset()
130 template<typename T>
131 class reset_operation {
132 public:
133 reset_operation(T& t) : t_(t) { }
134 void operator()() const { t_.reset(); }
135 private:
136 reset_operation& operator=(const reset_operation&);
137 T& t_;
140 template<typename T>
141 reset_operation<T> call_reset(T& t) { return reset_operation<T>(t); }
143 // Function object and object generator for clearing a flag
145 template<typename T>
146 class clear_flags_operation {
147 public:
148 typedef void result_type;
149 clear_flags_operation(T& t) : t_(t) { }
150 void operator()() const { t_ = 0; }
151 private:
152 clear_flags_operation& operator=(const clear_flags_operation&);
153 T& t_;
156 template<typename T>
157 clear_flags_operation<T> clear_flags(T& t)
158 { return clear_flags_operation<T>(t); }
160 // Function object and generator for flushing a buffer
162 // Function object for use with execute_all()
163 template<typename Buffer, typename Device>
164 class flush_buffer_operation {
165 public:
166 typedef void result_type;
167 flush_buffer_operation(Buffer& buf, Device& dev, bool flush)
168 : buf_(buf), dev_(dev), flush_(flush)
170 void operator()() const
172 if (flush_)
173 buf_.flush(dev_);
175 private:
176 flush_buffer_operation& operator=(const flush_buffer_operation&);
177 Buffer& buf_;
178 Device& dev_;
179 bool flush_;
182 template<typename Buffer, typename Device>
183 flush_buffer_operation<Buffer, Device>
184 flush_buffer(Buffer& buf, Device& dev, bool flush)
185 { return flush_buffer_operation<Buffer, Device>(buf, dev, flush); }
187 } } } // End namespaces detail, iostreams, boost.
189 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED