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_STREAM_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_STREAM_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
15 #include <boost/iostreams/constants.hpp>
16 #include <boost/iostreams/detail/char_traits.hpp>
17 #include <boost/iostreams/detail/config/overload_resolution.hpp>
18 #include <boost/iostreams/detail/forward.hpp>
19 #include <boost/iostreams/detail/iostream.hpp> // standard streams.
20 #include <boost/iostreams/detail/select.hpp>
21 #include <boost/iostreams/stream_buffer.hpp>
22 #include <boost/mpl/and.hpp>
23 #include <boost/type_traits/is_convertible.hpp>
24 #include <boost/utility/base_from_member.hpp>
26 namespace boost
{ namespace iostreams
{ namespace detail
{
28 template<typename Device
, typename Tr
>
29 struct stream_traits
{
30 typedef typename char_type_of
<Device
>::type char_type
;
31 typedef Tr traits_type
;
32 typedef typename category_of
<Device
>::type mode
;
34 iostreams::select
< // Dismbiguation required for Tru64.
36 is_convertible
<mode
, input
>,
37 is_convertible
<mode
, output
>
39 BOOST_IOSTREAMS_BASIC_IOSTREAM(char_type
, traits_type
),
40 is_convertible
<mode
, input
>,
41 BOOST_IOSTREAMS_BASIC_ISTREAM(char_type
, traits_type
),
43 BOOST_IOSTREAMS_BASIC_OSTREAM(char_type
, traits_type
)
46 iostreams::select
< // Dismbiguation required for Tru64.
48 is_convertible
<mode
, input
>,
49 is_convertible
<mode
, output
>
52 is_convertible
<mode
, input
>,
59 // By encapsulating initialization in a base, we can define the macro
60 // BOOST_IOSTREAMS_DEFINE_FORWARDING_FUNCTIONS to generate constuctors
61 // without base member initializer lists.
62 template< typename Device
,
64 BOOST_IOSTREAMS_CHAR_TRAITS(
65 BOOST_DEDUCED_TYPENAME char_type_of
<Device
>::type
69 BOOST_DEDUCED_TYPENAME char_type_of
<Device
>::type
71 typename Base
= // VC6 Workaround.
72 BOOST_DEDUCED_TYPENAME
73 detail::stream_traits
<Device
, Tr
>::stream_type
>
75 : protected base_from_member
< stream_buffer
<Device
, Tr
, Alloc
> >,
79 typedef base_from_member
< stream_buffer
<Device
, Tr
, Alloc
> > pbase_type
;
80 typedef typename stream_traits
<Device
, Tr
>::stream_type stream_type
;
82 using pbase_type::member
; // Avoid warning about 'this' in initializer list.
84 stream_base() : pbase_type(), stream_type(&member
) { }
87 } } } // End namespaces detail, iostreams, boost.
89 #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
90 # include <boost/iostreams/detail/broken_overload_resolution/stream.hpp>
93 namespace boost
{ namespace iostreams
{
96 // Template name: stream.
97 // Description: A iostream which reads from and writes to an instance of a
98 // designated device type.
99 // Template paramters:
100 // Device - A device type.
101 // Alloc - The allocator type.
103 template< typename Device
,
105 BOOST_IOSTREAMS_CHAR_TRAITS(
106 BOOST_DEDUCED_TYPENAME char_type_of
<Device
>::type
110 BOOST_DEDUCED_TYPENAME char_type_of
<Device
>::type
112 struct stream
: detail::stream_base
<Device
, Tr
, Alloc
> {
114 typedef typename char_type_of
<Device
>::type char_type
;
116 : mode_of
<Device
>::type
,
118 detail::stream_traits
<Device
, Tr
>::stream_tag
120 BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr
)
123 detail::stream_traits
<
125 >::stream_type stream_type
;
128 BOOST_IOSTREAMS_FORWARD( stream
, open_impl
, Device
,
129 BOOST_IOSTREAMS_PUSH_PARAMS
,
130 BOOST_IOSTREAMS_PUSH_ARGS
)
131 bool is_open() const { return this->member
.is_open(); }
132 void close() { this->member
.close(); }
133 bool auto_close() const { return this->member
.auto_close(); }
134 void set_auto_close(bool close
) { this->member
.set_auto_close(close
); }
135 bool strict_sync() { return this->member
.strict_sync(); }
136 Device
& operator*() { return *this->member
; }
137 Device
* operator->() { return &*this->member
; }
138 Device
* component() { return this->member
.component(); }
140 void open_impl(const Device
& dev
BOOST_IOSTREAMS_PUSH_PARAMS()) // For forwarding.
143 this->member
.open(dev
BOOST_IOSTREAMS_PUSH_ARGS());
147 } } // End namespaces iostreams, boost.
149 #endif // #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
151 #endif // #ifndef BOOST_IOSTREAMS_stream_HPP_INCLUDED