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