sl@0
|
1 |
// (C) Copyright Jonathan Turkanis 2003.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
sl@0
|
3 |
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
sl@0
|
4 |
|
sl@0
|
5 |
// See http://www.boost.org/libs/iostreams for documentation.
|
sl@0
|
6 |
|
sl@0
|
7 |
#ifndef BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
|
sl@0
|
8 |
#define BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
|
sl@0
|
9 |
|
sl@0
|
10 |
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
sl@0
|
11 |
# pragma once
|
sl@0
|
12 |
#endif
|
sl@0
|
13 |
|
sl@0
|
14 |
#include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
|
sl@0
|
15 |
#include <boost/detail/workaround.hpp>
|
sl@0
|
16 |
#include <boost/iostreams/categories.hpp>
|
sl@0
|
17 |
#include <boost/iostreams/detail/char_traits.hpp>
|
sl@0
|
18 |
#include <boost/iostreams/detail/dispatch.hpp>
|
sl@0
|
19 |
#include <boost/iostreams/detail/ios.hpp> // streamsize.
|
sl@0
|
20 |
#include <boost/iostreams/detail/streambuf.hpp>
|
sl@0
|
21 |
#include <boost/iostreams/detail/wrap_unwrap.hpp>
|
sl@0
|
22 |
#include <boost/iostreams/operations_fwd.hpp>
|
sl@0
|
23 |
#include <boost/iostreams/traits.hpp>
|
sl@0
|
24 |
#include <boost/mpl/if.hpp>
|
sl@0
|
25 |
|
sl@0
|
26 |
// Must come last.
|
sl@0
|
27 |
#include <boost/iostreams/detail/config/disable_warnings.hpp>
|
sl@0
|
28 |
|
sl@0
|
29 |
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-----------------------------------//
|
sl@0
|
30 |
# include <boost/iostreams/detail/vc6/write.hpp>
|
sl@0
|
31 |
#else // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //--------------------------//
|
sl@0
|
32 |
|
sl@0
|
33 |
namespace boost { namespace iostreams {
|
sl@0
|
34 |
|
sl@0
|
35 |
namespace detail {
|
sl@0
|
36 |
|
sl@0
|
37 |
template<typename T>
|
sl@0
|
38 |
struct write_device_impl;
|
sl@0
|
39 |
|
sl@0
|
40 |
template<typename T>
|
sl@0
|
41 |
struct write_filter_impl;
|
sl@0
|
42 |
|
sl@0
|
43 |
} // End namespace detail.
|
sl@0
|
44 |
|
sl@0
|
45 |
template<typename T>
|
sl@0
|
46 |
bool put(T& t, typename char_type_of<T>::type c)
|
sl@0
|
47 |
{ return detail::write_device_impl<T>::put(detail::unwrap(t), c); }
|
sl@0
|
48 |
|
sl@0
|
49 |
template<typename T>
|
sl@0
|
50 |
inline std::streamsize write
|
sl@0
|
51 |
(T& t, const typename char_type_of<T>::type* s, std::streamsize n)
|
sl@0
|
52 |
{ return detail::write_device_impl<T>::write(detail::unwrap(t), s, n); }
|
sl@0
|
53 |
|
sl@0
|
54 |
template<typename T, typename Sink>
|
sl@0
|
55 |
inline std::streamsize
|
sl@0
|
56 |
write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
|
sl@0
|
57 |
std::streamsize n )
|
sl@0
|
58 |
{ return detail::write_filter_impl<T>::write(detail::unwrap(t), snk, s, n); }
|
sl@0
|
59 |
|
sl@0
|
60 |
namespace detail {
|
sl@0
|
61 |
|
sl@0
|
62 |
//------------------Definition of write_device_impl---------------------------//
|
sl@0
|
63 |
|
sl@0
|
64 |
template<typename T>
|
sl@0
|
65 |
struct write_device_impl
|
sl@0
|
66 |
: mpl::if_<
|
sl@0
|
67 |
is_custom<T>,
|
sl@0
|
68 |
operations<T>,
|
sl@0
|
69 |
write_device_impl<
|
sl@0
|
70 |
BOOST_DEDUCED_TYPENAME
|
sl@0
|
71 |
dispatch<
|
sl@0
|
72 |
T, ostream_tag, streambuf_tag, output
|
sl@0
|
73 |
>::type
|
sl@0
|
74 |
>
|
sl@0
|
75 |
>::type
|
sl@0
|
76 |
{ };
|
sl@0
|
77 |
|
sl@0
|
78 |
template<>
|
sl@0
|
79 |
struct write_device_impl<ostream_tag> {
|
sl@0
|
80 |
template<typename T>
|
sl@0
|
81 |
static bool put(T& t, typename char_type_of<T>::type c)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
typedef typename char_type_of<T>::type char_type;
|
sl@0
|
84 |
typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type;
|
sl@0
|
85 |
return !traits_type::eq_int_type( t.rdbuf()->s.sputc(),
|
sl@0
|
86 |
traits_type::eof() );
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
template<typename T>
|
sl@0
|
90 |
static std::streamsize write
|
sl@0
|
91 |
(T& t, const typename char_type_of<T>::type* s, std::streamsize n)
|
sl@0
|
92 |
{ return t.rdbuf()->sputn(s, n); }
|
sl@0
|
93 |
};
|
sl@0
|
94 |
|
sl@0
|
95 |
template<>
|
sl@0
|
96 |
struct write_device_impl<streambuf_tag> {
|
sl@0
|
97 |
template<typename T>
|
sl@0
|
98 |
static bool put(T& t, typename char_type_of<T>::type c)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
typedef typename char_type_of<T>::type char_type;
|
sl@0
|
101 |
typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type;
|
sl@0
|
102 |
return !traits_type::eq_int_type(t.sputc(c), traits_type::eof());
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
template<typename T>
|
sl@0
|
106 |
static std::streamsize write
|
sl@0
|
107 |
(T& t, const typename char_type_of<T>::type* s, std::streamsize n)
|
sl@0
|
108 |
{ return t.sputn(s, n); }
|
sl@0
|
109 |
};
|
sl@0
|
110 |
|
sl@0
|
111 |
template<>
|
sl@0
|
112 |
struct write_device_impl<output> {
|
sl@0
|
113 |
template<typename T>
|
sl@0
|
114 |
static bool put(T& t, typename char_type_of<T>::type c)
|
sl@0
|
115 |
{ return t.write(&c, 1) == 1; }
|
sl@0
|
116 |
|
sl@0
|
117 |
template<typename T>
|
sl@0
|
118 |
static std::streamsize
|
sl@0
|
119 |
write(T& t, const typename char_type_of<T>::type* s, std::streamsize n)
|
sl@0
|
120 |
{ return t.write(s, n); }
|
sl@0
|
121 |
};
|
sl@0
|
122 |
|
sl@0
|
123 |
//------------------Definition of write_filter_impl---------------------------//
|
sl@0
|
124 |
|
sl@0
|
125 |
template<typename T>
|
sl@0
|
126 |
struct write_filter_impl
|
sl@0
|
127 |
: mpl::if_<
|
sl@0
|
128 |
is_custom<T>,
|
sl@0
|
129 |
operations<T>,
|
sl@0
|
130 |
write_filter_impl<
|
sl@0
|
131 |
BOOST_DEDUCED_TYPENAME
|
sl@0
|
132 |
dispatch<
|
sl@0
|
133 |
T, multichar_tag, any_tag
|
sl@0
|
134 |
>::type
|
sl@0
|
135 |
>
|
sl@0
|
136 |
>::type
|
sl@0
|
137 |
{ };
|
sl@0
|
138 |
|
sl@0
|
139 |
template<>
|
sl@0
|
140 |
struct write_filter_impl<multichar_tag> {
|
sl@0
|
141 |
template<typename T, typename Sink>
|
sl@0
|
142 |
static std::streamsize
|
sl@0
|
143 |
write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
|
sl@0
|
144 |
std::streamsize n )
|
sl@0
|
145 |
{ return t.write(snk, s, n); }
|
sl@0
|
146 |
};
|
sl@0
|
147 |
|
sl@0
|
148 |
template<>
|
sl@0
|
149 |
struct write_filter_impl<any_tag> {
|
sl@0
|
150 |
template<typename T, typename Sink>
|
sl@0
|
151 |
static std::streamsize
|
sl@0
|
152 |
write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
|
sl@0
|
153 |
std::streamsize n )
|
sl@0
|
154 |
{
|
sl@0
|
155 |
for (std::streamsize off = 0; off < n; ++off)
|
sl@0
|
156 |
if (!t.put(snk, s[off]))
|
sl@0
|
157 |
return off;
|
sl@0
|
158 |
return n;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
};
|
sl@0
|
161 |
|
sl@0
|
162 |
} // End namespace detail.
|
sl@0
|
163 |
|
sl@0
|
164 |
} } // End namespaces iostreams, boost.
|
sl@0
|
165 |
|
sl@0
|
166 |
#endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-------------------------//
|
sl@0
|
167 |
|
sl@0
|
168 |
#include <boost/iostreams/detail/config/enable_warnings.hpp>
|
sl@0
|
169 |
|
sl@0
|
170 |
#endif // #ifndef BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
|