source: NonGTP/Boost/boost/iostreams/detail/adapter/mode_adapter.hpp @ 857

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