1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
15 // Contains the definition of the class template mode_adapter, which allows
16 // a filter or device to function as if it has a different i/o mode than that
17 // deduced by the metafunction mode_of.
19 #include <boost/config.hpp> // BOOST_MSVC.
20 #include <boost/detail/workaround.hpp>
21 #include <boost/iostreams/categories.hpp>
22 #include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
23 #include <boost/iostreams/traits.hpp>
24 #include <boost/iostreams/operations.hpp>
25 #include <boost/mpl/if.hpp>
27 namespace boost
{ namespace iostreams
{ namespace detail
{
29 template<typename Mode
, typename T
>
32 struct empty_base
{ };
34 typedef typename wrapped_type
<T
>::type component_type
;
35 typedef typename char_type_of
<T
>::type char_type
;
39 mpl::if_
<is_filter
<T
>, filter_tag
, device_tag
>,
40 mpl::if_
<is_filter
<T
>, multichar_tag
, empty_base
>,
41 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
42 closable_tag
, // VC6 can't see member close()!
46 explicit mode_adapter(const component_type
& t
) : t_(t
) { }
48 // Device member functions.
50 std::streamsize
read(char_type
* s
, std::streamsize n
);
51 std::streamsize
write(const char_type
* s
, std::streamsize n
);
52 std::streampos
seek( stream_offset off
, BOOST_IOS::seekdir way
,
53 BOOST_IOS::openmode which
=
54 BOOST_IOS::in
| BOOST_IOS::out
);
55 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
57 void close(BOOST_IOS::openmode which
);
60 // Filter member functions.
62 template<typename Source
>
63 std::streamsize
read(Source
& src
, char_type
* s
, std::streamsize n
)
64 { return iostreams::read(t_
, src
, s
, n
); }
66 template<typename Sink
>
67 std::streamsize
write(Sink
& snk
, const char_type
* s
, std::streamsize n
)
68 { return iostreams::write(t_
, snk
, s
, n
); }
70 template<typename Device
>
71 std::streampos
seek(Device
& dev
, stream_offset off
, BOOST_IOS::seekdir way
)
72 { return iostreams::seek(t_
, dev
, off
, way
); }
74 template<typename Device
>
75 std::streampos
seek( Device
& dev
, stream_offset off
,
76 BOOST_IOS::seekdir way
, BOOST_IOS::openmode which
)
77 { return iostreams::seek(t_
, dev
, off
, way
, which
); }
79 template<typename Device
>
80 void close(Device
& dev
)
81 { detail::close_all(t_
, dev
); }
83 template<typename Device
>
84 void close(Device
& dev
, BOOST_IOS::openmode which
)
85 { iostreams::close(t_
, dev
, which
); }
87 template<typename Locale
>
88 void imbue(const Locale
& loc
)
89 { iostreams::imbue(t_
, loc
); }
94 //------------------Implementation of mode_adapter----------------------------//
96 template<typename Mode
, typename T
>
97 std::streamsize mode_adapter
<Mode
, T
>::read
98 (char_type
* s
, std::streamsize n
)
99 { return boost::iostreams::read(t_
, s
, n
); }
101 template<typename Mode
, typename T
>
102 std::streamsize mode_adapter
<Mode
, T
>::write
103 (const char_type
* s
, std::streamsize n
)
104 { return boost::iostreams::write(t_
, s
, n
); }
106 template<typename Mode
, typename T
>
107 std::streampos mode_adapter
<Mode
, T
>::seek
108 (stream_offset off
, BOOST_IOS::seekdir way
, BOOST_IOS::openmode which
)
109 { return boost::iostreams::seek(t_
, off
, way
, which
); }
111 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
112 template<typename Mode
, typename T
>
113 void mode_adapter
<Mode
, T
>::close()
114 { detail::close_all(t_
); }
116 template<typename Mode
, typename T
>
117 void mode_adapter
<Mode
, T
>::close(BOOST_IOS::openmode which
)
118 { iostreams::close(t_
, which
); }
121 } } } // End namespaces detail, iostreams, boost.
123 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED //-----//