File indexing completed on 2025-01-18 09:38:54
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
0010
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif
0014
0015 #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
0016 #include <boost/detail/workaround.hpp>
0017 #include <boost/iostreams/categories.hpp>
0018 #include <boost/iostreams/detail/char_traits.hpp>
0019 #include <boost/iostreams/detail/dispatch.hpp>
0020 #include <boost/iostreams/detail/ios.hpp> // streamsize.
0021 #include <boost/iostreams/detail/streambuf.hpp>
0022 #include <boost/iostreams/detail/wrap_unwrap.hpp>
0023 #include <boost/iostreams/operations_fwd.hpp>
0024 #include <boost/iostreams/traits.hpp>
0025 #include <boost/mpl/if.hpp>
0026
0027
0028 #include <boost/iostreams/detail/config/disable_warnings.hpp>
0029
0030 namespace boost { namespace iostreams {
0031
0032 namespace detail {
0033
0034 template<typename T>
0035 struct write_device_impl;
0036
0037 template<typename T>
0038 struct write_filter_impl;
0039
0040 }
0041
0042 template<typename T>
0043 bool put(T& t, typename char_type_of<T>::type c)
0044 { return detail::write_device_impl<T>::put(detail::unwrap(t), c); }
0045
0046 template<typename T>
0047 inline std::streamsize write
0048 (T& t, const typename char_type_of<T>::type* s, std::streamsize n)
0049 { return detail::write_device_impl<T>::write(detail::unwrap(t), s, n); }
0050
0051 template<typename T, typename Sink>
0052 inline std::streamsize
0053 write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
0054 std::streamsize n )
0055 { return detail::write_filter_impl<T>::write(detail::unwrap(t), snk, s, n); }
0056
0057 namespace detail {
0058
0059
0060
0061 template<typename T>
0062 struct write_device_impl
0063 : mpl::if_<
0064 is_custom<T>,
0065 operations<T>,
0066 write_device_impl<
0067 BOOST_DEDUCED_TYPENAME
0068 dispatch<
0069 T, ostream_tag, streambuf_tag, output
0070 >::type
0071 >
0072 >::type
0073 { };
0074
0075 template<>
0076 struct write_device_impl<ostream_tag> {
0077 template<typename T>
0078 static bool put(T& t, typename char_type_of<T>::type c)
0079 {
0080 typedef typename char_type_of<T>::type char_type;
0081 typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type;
0082 return !traits_type::eq_int_type( t.rdbuf()->sputc(c),
0083 traits_type::eof() );
0084 }
0085
0086 template<typename T>
0087 static std::streamsize write
0088 (T& t, const typename char_type_of<T>::type* s, std::streamsize n)
0089 { return t.rdbuf()->sputn(s, n); }
0090 };
0091
0092 template<>
0093 struct write_device_impl<streambuf_tag> {
0094 template<typename T>
0095 static bool put(T& t, typename char_type_of<T>::type c)
0096 {
0097 typedef typename char_type_of<T>::type char_type;
0098 typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type;
0099 return !traits_type::eq_int_type(t.sputc(c), traits_type::eof());
0100 }
0101
0102 template<typename T>
0103 static std::streamsize write
0104 (T& t, const typename char_type_of<T>::type* s, std::streamsize n)
0105 { return t.sputn(s, n); }
0106 };
0107
0108 template<>
0109 struct write_device_impl<output> {
0110 template<typename T>
0111 static bool put(T& t, typename char_type_of<T>::type c)
0112 { return t.write(&c, 1) == 1; }
0113
0114 template<typename T>
0115 static std::streamsize
0116 write(T& t, const typename char_type_of<T>::type* s, std::streamsize n)
0117 { return t.write(s, n); }
0118 };
0119
0120
0121
0122 template<typename T>
0123 struct write_filter_impl
0124 : mpl::if_<
0125 is_custom<T>,
0126 operations<T>,
0127 write_filter_impl<
0128 BOOST_DEDUCED_TYPENAME
0129 dispatch<
0130 T, multichar_tag, any_tag
0131 >::type
0132 >
0133 >::type
0134 { };
0135
0136 template<>
0137 struct write_filter_impl<multichar_tag> {
0138 template<typename T, typename Sink>
0139 static std::streamsize
0140 write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
0141 std::streamsize n )
0142 { return t.write(snk, s, n); }
0143 };
0144
0145 template<>
0146 struct write_filter_impl<any_tag> {
0147 template<typename T, typename Sink>
0148 static std::streamsize
0149 write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
0150 std::streamsize n )
0151 {
0152 for (std::streamsize off = 0; off < n; ++off)
0153 if (!t.put(snk, s[off]))
0154 return off;
0155 return n;
0156 }
0157 };
0158
0159 }
0160
0161 } }
0162
0163 #include <boost/iostreams/detail/config/enable_warnings.hpp>
0164
0165 #endif