Chris@16: /* Chris@16: * Distributed under the Boost Software License, Version 1.0.(See accompanying Chris@16: * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: * Chris@16: * See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: * File: boost/iostreams/detail/functional.hpp Chris@16: * Date: Sun Dec 09 05:38:03 MST 2007 Chris@16: * Copyright: 2007-2008 CodeRage, LLC Chris@16: * Author: Jonathan Turkanis Chris@16: * Contact: turkanis at coderage dot com Chris@16: Chris@16: * Defines several function objects and object generators for use with Chris@16: * execute_all() Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include // BOOST_IOS Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: // Function objects and object generators for invoking Chris@16: // boost::iostreams::close Chris@16: Chris@16: template Chris@16: class device_close_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: device_close_operation(T& t, BOOST_IOS::openmode which) Chris@16: : t_(t), which_(which) Chris@16: { } Chris@16: void operator()() const { boost::iostreams::close(t_, which_); } Chris@16: private: Chris@16: device_close_operation& operator=(const device_close_operation&); Chris@16: T& t_; Chris@16: BOOST_IOS::openmode which_; Chris@16: }; Chris@16: Chris@16: template Chris@16: class filter_close_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: filter_close_operation(T& t, Sink& snk, BOOST_IOS::openmode which) Chris@16: : t_(t), snk_(snk), which_(which) Chris@16: { } Chris@16: void operator()() const { boost::iostreams::close(t_, snk_, which_); } Chris@16: private: Chris@16: filter_close_operation& operator=(const filter_close_operation&); Chris@16: T& t_; Chris@16: Sink& snk_; Chris@16: BOOST_IOS::openmode which_; Chris@16: }; Chris@16: Chris@16: template Chris@16: device_close_operation Chris@16: call_close(T& t, BOOST_IOS::openmode which) Chris@16: { return device_close_operation(t, which); } Chris@16: Chris@16: template Chris@16: filter_close_operation Chris@16: call_close(T& t, Sink& snk, BOOST_IOS::openmode which) Chris@16: { return filter_close_operation(t, snk, which); } Chris@16: Chris@16: // Function objects and object generators for invoking Chris@16: // boost::iostreams::detail::close_all Chris@16: Chris@16: template Chris@16: class device_close_all_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: device_close_all_operation(T& t) : t_(t) { } Chris@16: void operator()() const { detail::close_all(t_); } Chris@16: private: Chris@16: device_close_all_operation& operator=(const device_close_all_operation&); Chris@16: T& t_; Chris@16: }; Chris@16: Chris@16: template Chris@16: class filter_close_all_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: filter_close_all_operation(T& t, Sink& snk) : t_(t), snk_(snk) { } Chris@16: void operator()() const { detail::close_all(t_, snk_); } Chris@16: private: Chris@16: filter_close_all_operation& operator=(const filter_close_all_operation&); Chris@16: T& t_; Chris@16: Sink& snk_; Chris@16: }; Chris@16: Chris@16: template Chris@16: device_close_all_operation call_close_all(T& t) Chris@16: { return device_close_all_operation(t); } Chris@16: Chris@16: template Chris@16: filter_close_all_operation Chris@16: call_close_all(T& t, Sink& snk) Chris@16: { return filter_close_all_operation(t, snk); } Chris@16: Chris@16: // Function object and object generator for invoking a Chris@16: // member function void close(std::ios_base::openmode) Chris@16: Chris@16: template Chris@16: class member_close_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: member_close_operation(T& t, BOOST_IOS::openmode which) Chris@16: : t_(t), which_(which) Chris@16: { } Chris@16: void operator()() const { t_.close(which_); } Chris@16: private: Chris@16: member_close_operation& operator=(const member_close_operation&); Chris@16: T& t_; Chris@16: BOOST_IOS::openmode which_; Chris@16: }; Chris@16: Chris@16: template Chris@16: member_close_operation call_member_close(T& t, BOOST_IOS::openmode which) Chris@16: { return member_close_operation(t, which); } Chris@16: Chris@16: // Function object and object generator for invoking a Chris@16: // member function void reset() Chris@16: Chris@16: template Chris@16: class reset_operation { Chris@16: public: Chris@16: reset_operation(T& t) : t_(t) { } Chris@16: void operator()() const { t_.reset(); } Chris@16: private: Chris@16: reset_operation& operator=(const reset_operation&); Chris@16: T& t_; Chris@16: }; Chris@16: Chris@16: template Chris@16: reset_operation call_reset(T& t) { return reset_operation(t); } Chris@16: Chris@16: // Function object and object generator for clearing a flag Chris@16: Chris@16: template Chris@16: class clear_flags_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: clear_flags_operation(T& t) : t_(t) { } Chris@16: void operator()() const { t_ = 0; } Chris@16: private: Chris@16: clear_flags_operation& operator=(const clear_flags_operation&); Chris@16: T& t_; Chris@16: }; Chris@16: Chris@16: template Chris@16: clear_flags_operation clear_flags(T& t) Chris@16: { return clear_flags_operation(t); } Chris@16: Chris@16: // Function object and generator for flushing a buffer Chris@16: Chris@16: // Function object for use with execute_all() Chris@16: template Chris@16: class flush_buffer_operation { Chris@16: public: Chris@16: typedef void result_type; Chris@16: flush_buffer_operation(Buffer& buf, Device& dev, bool flush) Chris@16: : buf_(buf), dev_(dev), flush_(flush) Chris@16: { } Chris@16: void operator()() const Chris@16: { Chris@16: if (flush_) Chris@16: buf_.flush(dev_); Chris@16: } Chris@16: private: Chris@16: flush_buffer_operation& operator=(const flush_buffer_operation&); Chris@16: Buffer& buf_; Chris@16: Device& dev_; Chris@16: bool flush_; Chris@16: }; Chris@16: Chris@16: template Chris@16: flush_buffer_operation Chris@16: flush_buffer(Buffer& buf, Device& dev, bool flush) Chris@16: { return flush_buffer_operation(buf, dev, flush); } Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_FUNCTIONAL_HPP_INCLUDED