Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-2007 Jonathan Turkanis 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: #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: // Contains the definition of the class template mode_adapter, which allows Chris@16: // a filter or device to function as if it has a different i/o mode than that Chris@16: // deduced by the metafunction mode_of. Chris@16: Chris@16: #include // BOOST_MSVC. Chris@16: #include Chris@16: #include Chris@16: #include // openmode, seekdir, int types. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: template Chris@16: class mode_adapter { Chris@16: private: Chris@16: struct empty_base { }; Chris@16: public: Chris@16: typedef typename wrapped_type::type component_type; Chris@16: typedef typename char_type_of::type char_type; Chris@16: struct category Chris@16: : Mode, Chris@16: device_tag, Chris@16: mpl::if_, filter_tag, device_tag>, Chris@16: mpl::if_, multichar_tag, empty_base>, Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) Chris@16: closable_tag, // VC6 can't see member close()! Chris@16: #endif Chris@16: localizable_tag Chris@16: { }; Chris@16: explicit mode_adapter(const component_type& t) : t_(t) { } Chris@16: Chris@16: // Device member functions. Chris@16: Chris@16: std::streamsize read(char_type* s, std::streamsize n); Chris@16: std::streamsize write(const char_type* s, std::streamsize n); Chris@16: std::streampos seek( stream_offset off, BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which = Chris@16: BOOST_IOS::in | BOOST_IOS::out ); Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) Chris@16: void close(); Chris@16: void close(BOOST_IOS::openmode which); Chris@16: #endif Chris@16: Chris@16: // Filter member functions. Chris@16: Chris@16: template Chris@16: std::streamsize read(Source& src, char_type* s, std::streamsize n) Chris@16: { return iostreams::read(t_, src, s, n); } Chris@16: Chris@16: template Chris@16: std::streamsize write(Sink& snk, const char_type* s, std::streamsize n) Chris@16: { return iostreams::write(t_, snk, s, n); } Chris@16: Chris@16: template Chris@16: std::streampos seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way) Chris@16: { return iostreams::seek(t_, dev, off, way); } Chris@16: Chris@16: template Chris@16: std::streampos seek( Device& dev, stream_offset off, Chris@16: BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) Chris@16: { return iostreams::seek(t_, dev, off, way, which); } Chris@16: Chris@16: template Chris@16: void close(Device& dev) Chris@16: { detail::close_all(t_, dev); } Chris@16: Chris@16: template Chris@16: void close(Device& dev, BOOST_IOS::openmode which) Chris@16: { iostreams::close(t_, dev, which); } Chris@16: Chris@16: template Chris@16: void imbue(const Locale& loc) Chris@16: { iostreams::imbue(t_, loc); } Chris@16: private: Chris@16: component_type t_; Chris@16: }; Chris@16: Chris@16: //------------------Implementation of mode_adapter----------------------------// Chris@16: Chris@16: template Chris@16: std::streamsize mode_adapter::read Chris@16: (char_type* s, std::streamsize n) Chris@16: { return boost::iostreams::read(t_, s, n); } Chris@16: Chris@16: template Chris@16: std::streamsize mode_adapter::write Chris@16: (const char_type* s, std::streamsize n) Chris@16: { return boost::iostreams::write(t_, s, n); } Chris@16: Chris@16: template Chris@16: std::streampos mode_adapter::seek Chris@16: (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) Chris@16: { return boost::iostreams::seek(t_, off, way, which); } Chris@16: Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) Chris@16: template Chris@16: void mode_adapter::close() Chris@16: { detail::close_all(t_); } Chris@16: Chris@16: template Chris@16: void mode_adapter::close(BOOST_IOS::openmode which) Chris@16: { iostreams::close(t_, which); } Chris@16: #endif Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED //-----//