| [12] | 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_STREAM_HPP_INCLUDED | 
|---|
 | 8 | #define BOOST_IOSTREAMS_STREAM_HPP_INCLUDED | 
|---|
 | 9 |  | 
|---|
 | 10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) | 
|---|
 | 11 | # pragma once | 
|---|
 | 12 | #endif | 
|---|
 | 13 |  | 
|---|
 | 14 | #include <boost/iostreams/constants.hpp> | 
|---|
 | 15 | #include <boost/iostreams/detail/char_traits.hpp> | 
|---|
 | 16 | #include <boost/iostreams/detail/config/overload_resolution.hpp> | 
|---|
 | 17 | #include <boost/iostreams/detail/forward.hpp> | 
|---|
 | 18 | #include <boost/iostreams/detail/iostream.hpp>  // standard streams. | 
|---|
 | 19 | #include <boost/iostreams/detail/select.hpp> | 
|---|
 | 20 | #include <boost/iostreams/stream_buffer.hpp> | 
|---|
 | 21 | #include <boost/mpl/and.hpp> | 
|---|
 | 22 | #include <boost/type_traits/is_convertible.hpp> | 
|---|
 | 23 |  | 
|---|
 | 24 | namespace boost { namespace iostreams { namespace detail { | 
|---|
 | 25 |  | 
|---|
 | 26 | template<typename Device, typename Tr> | 
|---|
 | 27 | struct stream_traits { | 
|---|
 | 28 |     typedef typename char_type_of<Device>::type                char_type; | 
|---|
 | 29 |     typedef Tr                                                 traits_type; | 
|---|
 | 30 |     typedef typename category_of<Device>::type                 mode; | 
|---|
 | 31 |     typedef typename | 
|---|
 | 32 |             iostreams::select< // Dismbiguation required for Tru64. | 
|---|
 | 33 |                 mpl::and_< | 
|---|
 | 34 |                     is_convertible<mode, input>, | 
|---|
 | 35 |                     is_convertible<mode, output> | 
|---|
 | 36 |                 >, | 
|---|
 | 37 |                 BOOST_IOSTREAMS_BASIC_IOSTREAM(char_type, traits_type), | 
|---|
 | 38 |                 is_convertible<mode, input>, | 
|---|
 | 39 |                 BOOST_IOSTREAMS_BASIC_ISTREAM(char_type, traits_type), | 
|---|
 | 40 |                 else_, | 
|---|
 | 41 |                 BOOST_IOSTREAMS_BASIC_OSTREAM(char_type, traits_type) | 
|---|
 | 42 |             >::type type; | 
|---|
 | 43 | }; | 
|---|
 | 44 |  | 
|---|
 | 45 | // By encapsulating initialization in a base, we can define the macro | 
|---|
 | 46 | // BOOST_IOSTREAMS_DEFINE_FORWARDING_FUNCTIONS to generate constuctors | 
|---|
 | 47 | // without base member initializer lists. | 
|---|
 | 48 | template< typename Device, | 
|---|
 | 49 |           typename Tr = | 
|---|
 | 50 |               BOOST_IOSTREAMS_CHAR_TRAITS( | 
|---|
 | 51 |                   BOOST_DEDUCED_TYPENAME char_type_of<Device>::type | 
|---|
 | 52 |               ), | 
|---|
 | 53 |           typename Alloc = | 
|---|
 | 54 |               std::allocator< | 
|---|
 | 55 |                   BOOST_DEDUCED_TYPENAME char_type_of<Device>::type | 
|---|
 | 56 |               >, | 
|---|
 | 57 |           typename Base = // VC6 Workaround. | 
|---|
 | 58 |               BOOST_DEDUCED_TYPENAME | 
|---|
 | 59 |               detail::stream_traits<Device, Tr>::type > | 
|---|
 | 60 | class stream_base | 
|---|
 | 61 |     : protected base_from_member< stream_buffer<Device, Tr, Alloc> >, | 
|---|
 | 62 |       public Base | 
|---|
 | 63 | { | 
|---|
 | 64 | private: | 
|---|
 | 65 |     typedef base_from_member< stream_buffer<Device, Tr, Alloc> > pbase_type; | 
|---|
 | 66 |     typedef typename stream_traits<Device, Tr>::type         stream_type; | 
|---|
 | 67 | protected: | 
|---|
 | 68 |     using pbase_type::member; // Avoid warning about 'this' in initializer list. | 
|---|
 | 69 | public: | 
|---|
 | 70 |     stream_base() : pbase_type(), stream_type(&member) { } | 
|---|
 | 71 | }; | 
|---|
 | 72 |  | 
|---|
 | 73 | } } } // End namespaces detail, iostreams, boost. | 
|---|
 | 74 |  | 
|---|
 | 75 | #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION | 
|---|
 | 76 | # include <boost/iostreams/detail/broken_overload_resolution/stream.hpp> | 
|---|
 | 77 | #else | 
|---|
 | 78 |  | 
|---|
 | 79 | namespace boost { namespace iostreams { | 
|---|
 | 80 |  | 
|---|
 | 81 | // | 
|---|
 | 82 | // Template name: stream. | 
|---|
 | 83 | // Description: A iostream which reads from and writes to an instance of a | 
|---|
 | 84 | //      designated device type. | 
|---|
 | 85 | // Template paramters: | 
|---|
 | 86 | //      Device - A device type. | 
|---|
 | 87 | //      Alloc - The allocator type. | 
|---|
 | 88 | // | 
|---|
 | 89 | template< typename Device, | 
|---|
 | 90 |           typename Tr = | 
|---|
 | 91 |               BOOST_IOSTREAMS_CHAR_TRAITS( | 
|---|
 | 92 |                   BOOST_DEDUCED_TYPENAME char_type_of<Device>::type | 
|---|
 | 93 |               ), | 
|---|
 | 94 |           typename Alloc = | 
|---|
 | 95 |               std::allocator< | 
|---|
 | 96 |                   BOOST_DEDUCED_TYPENAME char_type_of<Device>::type | 
|---|
 | 97 |               > > | 
|---|
 | 98 | struct stream : detail::stream_base<Device, Tr, Alloc> { | 
|---|
 | 99 | public: | 
|---|
 | 100 |     typedef typename char_type_of<Device>::type  char_type; | 
|---|
 | 101 |     BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) | 
|---|
 | 102 | private: | 
|---|
 | 103 |     typedef typename | 
|---|
 | 104 |             detail::stream_traits< | 
|---|
 | 105 |                 Device, Tr | 
|---|
 | 106 |             >::type                              stream_type; | 
|---|
 | 107 |     typedef Device                               policy_type; | 
|---|
 | 108 | public: | 
|---|
 | 109 |     stream() { } | 
|---|
 | 110 |     BOOST_IOSTREAMS_FORWARD( stream, open_impl, Device, | 
|---|
 | 111 |                              BOOST_IOSTREAMS_PUSH_PARAMS, | 
|---|
 | 112 |                              BOOST_IOSTREAMS_PUSH_ARGS ) | 
|---|
 | 113 |     bool is_open() const { return this->member.is_open(); } | 
|---|
 | 114 |     void close() { this->member.close(); } | 
|---|
 | 115 |     bool auto_close() const { return this->member.auto_close(); } | 
|---|
 | 116 |     void set_auto_close(bool close) { this->member.set_auto_close(close); } | 
|---|
 | 117 |     bool strict_sync() { return this->member.strict_sync(); } | 
|---|
 | 118 |     Device& operator*() { return *this->member; } | 
|---|
 | 119 |     Device* operator->() { return &*this->member; } | 
|---|
 | 120 |     Device* component() { return this->member.component(); } | 
|---|
 | 121 | private: | 
|---|
 | 122 |     void open_impl(const Device& dev BOOST_IOSTREAMS_PUSH_PARAMS()) // For forwarding. | 
|---|
 | 123 |     {  | 
|---|
 | 124 |         this->clear();  | 
|---|
 | 125 |         this->member.open(dev BOOST_IOSTREAMS_PUSH_ARGS());  | 
|---|
 | 126 |     } | 
|---|
 | 127 | }; | 
|---|
 | 128 |  | 
|---|
 | 129 | } } // End namespaces iostreams, boost. | 
|---|
 | 130 |  | 
|---|
 | 131 | #endif // #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION | 
|---|
 | 132 |  | 
|---|
 | 133 | #endif // #ifndef BOOST_IOSTREAMS_stream_HPP_INCLUDED | 
|---|