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.)
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
17 #ifndef BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED
18 #define BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED
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
33 class device_close_operation {
35 typedef void result_type;
36 device_close_operation(T& t, BOOST_IOS::openmode which)
37 : t_(t), which_(which)
39 void operator()() const { boost::iostreams::close(t_, which_); }
41 device_close_operation& operator=(const device_close_operation&);
43 BOOST_IOS::openmode which_;
46 template<typename T, typename Sink>
47 class filter_close_operation {
49 typedef void result_type;
50 filter_close_operation(T& t, Sink& snk, BOOST_IOS::openmode which)
51 : t_(t), snk_(snk), which_(which)
53 void operator()() const { boost::iostreams::close(t_, snk_, which_); }
55 filter_close_operation& operator=(const filter_close_operation&);
58 BOOST_IOS::openmode which_;
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
75 class device_close_all_operation {
77 typedef void result_type;
78 device_close_all_operation(T& t) : t_(t) { }
79 void operator()() const { detail::close_all(t_); }
81 device_close_all_operation& operator=(const device_close_all_operation&);
85 template<typename T, typename Sink>
86 class filter_close_all_operation {
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_); }
92 filter_close_all_operation& operator=(const filter_close_all_operation&);
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)
110 class member_close_operation {
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_); }
118 member_close_operation& operator=(const member_close_operation&);
120 BOOST_IOS::openmode which_;
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()
131 class reset_operation {
133 reset_operation(T& t) : t_(t) { }
134 void operator()() const { t_.reset(); }
136 reset_operation& operator=(const reset_operation&);
141 reset_operation<T> call_reset(T& t) { return reset_operation<T>(t); }
143 // Function object and object generator for clearing a flag
146 class clear_flags_operation {
148 typedef void result_type;
149 clear_flags_operation(T& t) : t_(t) { }
150 void operator()() const { t_ = 0; }
152 clear_flags_operation& operator=(const clear_flags_operation&);
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 {
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
176 flush_buffer_operation& operator=(const flush_buffer_operation&);
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