annotate DEPENDENCIES/generic/include/boost/iostreams/traits.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
Chris@16 2 // (C) Copyright 2003-2007 Jonathan Turkanis
Chris@16 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
Chris@16 5
Chris@16 6 // See http://www.boost.org/libs/iostreams for documentation.
Chris@16 7
Chris@16 8 //
Chris@16 9 // Contains metafunctions char_type_of, category_of and mode_of used for
Chris@16 10 // deducing the i/o category and i/o mode of a model of Filter or Device.
Chris@16 11 //
Chris@16 12 // Also contains several utility metafunctions, functions and macros.
Chris@16 13 //
Chris@16 14
Chris@16 15 #ifndef BOOST_IOSTREAMS_IO_TRAITS_HPP_INCLUDED
Chris@16 16 #define BOOST_IOSTREAMS_IO_TRAITS_HPP_INCLUDED
Chris@16 17
Chris@16 18 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
Chris@16 19 # pragma once
Chris@16 20 #endif
Chris@16 21
Chris@16 22 #include <iosfwd> // stream types, char_traits.
Chris@16 23 #include <boost/config.hpp> // partial spec, deduced typename.
Chris@16 24 #include <boost/detail/workaround.hpp>
Chris@16 25 #include <boost/iostreams/categories.hpp>
Chris@16 26 #include <boost/iostreams/detail/bool_trait_def.hpp>
Chris@16 27 #include <boost/iostreams/detail/config/wide_streams.hpp>
Chris@16 28 #include <boost/iostreams/detail/is_iterator_range.hpp>
Chris@16 29 #include <boost/iostreams/detail/select.hpp>
Chris@16 30 #include <boost/iostreams/detail/select_by_size.hpp>
Chris@16 31 #include <boost/iostreams/detail/wrap_unwrap.hpp>
Chris@16 32 #include <boost/iostreams/traits_fwd.hpp>
Chris@16 33 #include <boost/mpl/bool.hpp>
Chris@16 34 #include <boost/mpl/eval_if.hpp>
Chris@16 35 #include <boost/mpl/identity.hpp>
Chris@16 36 #include <boost/mpl/int.hpp>
Chris@16 37 #include <boost/mpl/or.hpp>
Chris@16 38 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
Chris@16 39 # include <boost/range/iterator_range.hpp>
Chris@16 40 # include <boost/range/value_type.hpp>
Chris@16 41 #endif // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
Chris@16 42 #include <boost/ref.hpp>
Chris@16 43 #include <boost/type_traits/is_convertible.hpp>
Chris@16 44
Chris@16 45 // Must come last.
Chris@16 46 #include <boost/iostreams/detail/config/disable_warnings.hpp>
Chris@16 47
Chris@16 48 namespace boost { namespace iostreams {
Chris@16 49
Chris@16 50 //----------Definitions of predicates for streams and stream buffers----------//
Chris@16 51
Chris@16 52 #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------------------//
Chris@16 53
Chris@16 54 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_istream, std::basic_istream, 2)
Chris@16 55 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ostream, std::basic_ostream, 2)
Chris@16 56 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_iostream, std::basic_iostream, 2)
Chris@16 57 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_streambuf, std::basic_streambuf, 2)
Chris@16 58 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ifstream, std::basic_ifstream, 2)
Chris@16 59 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ofstream, std::basic_ofstream, 2)
Chris@16 60 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_fstream, std::basic_fstream, 2)
Chris@16 61 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_filebuf, std::basic_filebuf, 2)
Chris@16 62 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_istringstream, std::basic_istringstream, 3)
Chris@16 63 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ostringstream, std::basic_ostringstream, 3)
Chris@16 64 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_stringstream, std::basic_stringstream, 3)
Chris@16 65 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_stringbuf, std::basic_stringbuf, 3)
Chris@16 66
Chris@16 67 #else // #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-----------------------//
Chris@16 68
Chris@16 69 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_istream, std::istream, 0)
Chris@16 70 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ostream, std::ostream, 0)
Chris@16 71 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_iostream, std::iostream, 0)
Chris@16 72 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_streambuf, std::streambuf, 0)
Chris@16 73
Chris@16 74 #endif // #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //----------------------//
Chris@16 75
Chris@16 76 template<typename T>
Chris@16 77 struct is_std_io
Chris@16 78 : mpl::or_< is_istream<T>, is_ostream<T>, is_streambuf<T> >
Chris@16 79 { };
Chris@16 80
Chris@16 81 template<typename T>
Chris@16 82 struct is_std_file_device
Chris@16 83 : mpl::or_<
Chris@16 84 is_ifstream<T>,
Chris@16 85 is_ofstream<T>,
Chris@16 86 is_fstream<T>,
Chris@16 87 is_filebuf<T>
Chris@16 88 >
Chris@16 89 { };
Chris@16 90
Chris@16 91 template<typename T>
Chris@16 92 struct is_std_string_device
Chris@16 93 : mpl::or_<
Chris@16 94 is_istringstream<T>,
Chris@16 95 is_ostringstream<T>,
Chris@16 96 is_stringstream<T>,
Chris@16 97 is_stringbuf<T>
Chris@16 98 >
Chris@16 99 { };
Chris@16 100
Chris@16 101 template<typename Device, typename Tr, typename Alloc>
Chris@16 102 struct stream;
Chris@16 103
Chris@16 104 template<typename T, typename Tr, typename Alloc, typename Mode>
Chris@16 105 class stream_buffer;
Chris@16 106
Chris@16 107 template< typename Mode, typename Ch, typename Tr,
Chris@16 108 typename Alloc, typename Access >
Chris@16 109 class filtering_stream;
Chris@16 110
Chris@16 111 template< typename Mode, typename Ch, typename Tr,
Chris@16 112 typename Alloc, typename Access >
Chris@16 113 class wfiltering_stream;
Chris@16 114
Chris@16 115 template< typename Mode, typename Ch, typename Tr,
Chris@16 116 typename Alloc, typename Access >
Chris@16 117 class filtering_streambuf;
Chris@16 118
Chris@16 119 template< typename Mode, typename Ch, typename Tr,
Chris@16 120 typename Alloc, typename Access >
Chris@16 121 class filtering_wstreambuf;
Chris@16 122
Chris@16 123 namespace detail {
Chris@16 124
Chris@16 125 template<typename T, typename Tr>
Chris@16 126 class linked_streambuf;
Chris@16 127
Chris@16 128 BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_boost_stream,
Chris@16 129 boost::iostreams::stream,
Chris@16 130 3 )
Chris@16 131 BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_boost_stream_buffer,
Chris@16 132 boost::iostreams::stream_buffer,
Chris@16 133 4 )
Chris@16 134 BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_stream_impl,
Chris@16 135 boost::iostreams::filtering_stream,
Chris@16 136 5 )
Chris@16 137 BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_wstream_impl,
Chris@16 138 boost::iostreams::wfiltering_stream,
Chris@16 139 5 )
Chris@16 140 BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_streambuf_impl,
Chris@16 141 boost::iostreams::filtering_streambuf,
Chris@16 142 5 )
Chris@16 143 BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_wstreambuf_impl,
Chris@16 144 boost::iostreams::filtering_wstreambuf,
Chris@16 145 5 )
Chris@16 146 BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_linked, linked_streambuf, 2)
Chris@16 147
Chris@16 148 template<typename T>
Chris@16 149 struct is_filtering_stream
Chris@16 150 : mpl::or_<
Chris@16 151 is_filtering_stream_impl<T>,
Chris@16 152 is_filtering_wstream_impl<T>
Chris@16 153 >
Chris@16 154 { };
Chris@16 155
Chris@16 156 template<typename T>
Chris@16 157 struct is_filtering_streambuf
Chris@16 158 : mpl::or_<
Chris@16 159 is_filtering_streambuf_impl<T>,
Chris@16 160 is_filtering_wstreambuf_impl<T>
Chris@16 161 >
Chris@16 162 { };
Chris@16 163
Chris@16 164 template<typename T>
Chris@16 165 struct is_boost
Chris@16 166 : mpl::or_<
Chris@16 167 is_boost_stream<T>,
Chris@16 168 is_boost_stream_buffer<T>,
Chris@16 169 is_filtering_stream<T>,
Chris@16 170 is_filtering_streambuf<T>
Chris@16 171 >
Chris@16 172 { };
Chris@16 173
Chris@16 174 } // End namespace detail.
Chris@16 175
Chris@16 176 //------------------Definitions of char_type_of-------------------------------//
Chris@16 177
Chris@16 178 namespace detail {
Chris@16 179
Chris@16 180 template<typename T>
Chris@16 181 struct member_char_type { typedef typename T::char_type type; };
Chris@16 182
Chris@16 183 } // End namespace detail.
Chris@16 184
Chris@16 185 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //---------------------------//
Chris@16 186 # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------//
Chris@16 187
Chris@16 188 template<typename T>
Chris@16 189 struct char_type_of
Chris@16 190 : detail::member_char_type<
Chris@16 191 typename detail::unwrapped_type<T>::type
Chris@16 192 >
Chris@16 193 { };
Chris@16 194
Chris@16 195 # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------//
Chris@16 196
Chris@16 197 template<typename T>
Chris@16 198 struct char_type_of {
Chris@16 199 typedef typename detail::unwrapped_type<T>::type U;
Chris@16 200 typedef typename
Chris@16 201 mpl::eval_if<
Chris@16 202 is_std_io<U>,
Chris@16 203 mpl::identity<char>,
Chris@16 204 detail::member_char_type<U>
Chris@16 205 >::type type;
Chris@16 206 };
Chris@16 207
Chris@16 208 # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------//
Chris@16 209
Chris@16 210 template<typename Iter>
Chris@16 211 struct char_type_of< iterator_range<Iter> > {
Chris@16 212 typedef typename iterator_value<Iter>::type type;
Chris@16 213 };
Chris@16 214
Chris@16 215 #else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //------------------//
Chris@16 216
Chris@16 217 template<typename T>
Chris@16 218 struct char_type_of {
Chris@16 219 template<typename U>
Chris@16 220 struct get_value_type {
Chris@16 221 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
Chris@16 222 typedef typename range_value<U>::type type;
Chris@16 223 #endif // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
Chris@16 224 };
Chris@16 225 typedef typename
Chris@16 226 mpl::eval_if<
Chris@16 227 is_iterator_range<T>,
Chris@16 228 get_value_type<T>,
Chris@16 229 detail::member_char_type<
Chris@16 230 BOOST_DEDUCED_TYPENAME detail::unwrapped_type<T>::type
Chris@16 231 >
Chris@16 232 >::type type;
Chris@16 233 };
Chris@16 234
Chris@16 235 #endif // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //-----------------//
Chris@16 236
Chris@16 237 //------------------Definitions of category_of--------------------------------//
Chris@16 238
Chris@16 239 namespace detail {
Chris@16 240
Chris@16 241 template<typename T>
Chris@16 242 struct member_category { typedef typename T::category type; };
Chris@16 243
Chris@16 244 } // End namespace detail.
Chris@16 245
Chris@16 246 template<typename T>
Chris@16 247 struct category_of {
Chris@16 248 template<typename U>
Chris@16 249 struct member_category {
Chris@16 250 typedef typename U::category type;
Chris@16 251 };
Chris@16 252 typedef typename detail::unwrapped_type<T>::type U;
Chris@16 253 typedef typename
Chris@16 254 mpl::eval_if<
Chris@16 255 mpl::and_<
Chris@16 256 is_std_io<U>,
Chris@16 257 mpl::not_< detail::is_boost<U> >
Chris@16 258 >,
Chris@16 259 iostreams::select< // Disambiguation for Tru64
Chris@16 260 is_filebuf<U>, filebuf_tag,
Chris@16 261 is_ifstream<U>, ifstream_tag,
Chris@16 262 is_ofstream<U>, ofstream_tag,
Chris@16 263 is_fstream<U>, fstream_tag,
Chris@16 264 is_stringbuf<U>, stringbuf_tag,
Chris@16 265 is_istringstream<U>, istringstream_tag,
Chris@16 266 is_ostringstream<U>, ostringstream_tag,
Chris@16 267 is_stringstream<U>, stringstream_tag,
Chris@16 268 is_streambuf<U>, generic_streambuf_tag,
Chris@16 269 is_iostream<U>, generic_iostream_tag,
Chris@16 270 is_istream<U>, generic_istream_tag,
Chris@16 271 is_ostream<U>, generic_ostream_tag
Chris@16 272 >,
Chris@16 273 detail::member_category<U>
Chris@16 274 >::type type;
Chris@16 275 };
Chris@16 276
Chris@16 277 // Partial specialization for reference wrappers
Chris@16 278 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //---------------------------//
Chris@16 279
Chris@16 280 template<typename T>
Chris@16 281 struct category_of< reference_wrapper<T> >
Chris@16 282 : category_of<T>
Chris@16 283 { };
Chris@16 284
Chris@16 285 #endif // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //-----------------//
Chris@16 286
Chris@16 287 //------------------Definition of get_category--------------------------------//
Chris@16 288
Chris@16 289 //
Chris@16 290 // Returns an object of type category_of<T>::type.
Chris@16 291 //
Chris@16 292 template<typename T>
Chris@16 293 inline typename category_of<T>::type get_category(const T&)
Chris@16 294 { typedef typename category_of<T>::type category; return category(); }
Chris@16 295
Chris@16 296 //------------------Definition of int_type_of---------------------------------//
Chris@16 297
Chris@16 298 template<typename T>
Chris@16 299 struct int_type_of {
Chris@16 300 #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES
Chris@16 301 typedef std::char_traits<
Chris@16 302 BOOST_DEDUCED_TYPENAME char_type_of<T>::type
Chris@16 303 > traits_type;
Chris@16 304 typedef typename traits_type::int_type type;
Chris@16 305 #else
Chris@16 306 typedef int type;
Chris@16 307 #endif
Chris@16 308 };
Chris@16 309
Chris@16 310 //------------------Definition of mode_of-------------------------------------//
Chris@16 311
Chris@16 312 namespace detail {
Chris@16 313
Chris@16 314 template<int N> struct io_mode_impl;
Chris@16 315
Chris@16 316 #define BOOST_IOSTREAMS_MODE_HELPER(tag_, id_) \
Chris@16 317 case_<id_> io_mode_impl_helper(tag_); \
Chris@16 318 template<> struct io_mode_impl<id_> { typedef tag_ type; }; \
Chris@16 319 /**/
Chris@16 320 BOOST_IOSTREAMS_MODE_HELPER(input, 1)
Chris@16 321 BOOST_IOSTREAMS_MODE_HELPER(output, 2)
Chris@16 322 BOOST_IOSTREAMS_MODE_HELPER(bidirectional, 3)
Chris@16 323 BOOST_IOSTREAMS_MODE_HELPER(input_seekable, 4)
Chris@16 324 BOOST_IOSTREAMS_MODE_HELPER(output_seekable, 5)
Chris@16 325 BOOST_IOSTREAMS_MODE_HELPER(seekable, 6)
Chris@16 326 BOOST_IOSTREAMS_MODE_HELPER(dual_seekable, 7)
Chris@16 327 BOOST_IOSTREAMS_MODE_HELPER(bidirectional_seekable, 8)
Chris@16 328 BOOST_IOSTREAMS_MODE_HELPER(dual_use, 9)
Chris@16 329 #undef BOOST_IOSTREAMS_MODE_HELPER
Chris@16 330
Chris@16 331 template<typename T>
Chris@16 332 struct io_mode_id {
Chris@16 333 typedef typename category_of<T>::type category;
Chris@16 334 BOOST_SELECT_BY_SIZE(int, value, detail::io_mode_impl_helper(category()));
Chris@16 335 };
Chris@16 336
Chris@16 337 } // End namespace detail.
Chris@16 338
Chris@16 339 template<typename T> // Borland 5.6.4 requires this circumlocution.
Chris@16 340 struct mode_of : detail::io_mode_impl< detail::io_mode_id<T>::value > { };
Chris@16 341
Chris@16 342 // Partial specialization for reference wrappers
Chris@16 343 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //---------------------------//
Chris@16 344
Chris@16 345 template<typename T>
Chris@16 346 struct mode_of< reference_wrapper<T> >
Chris@16 347 : mode_of<T>
Chris@16 348 { };
Chris@16 349
Chris@16 350 #endif // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //-----------------//
Chris@16 351
Chris@16 352 //------------------Definition of is_device, is_filter and is_direct----------//
Chris@16 353
Chris@16 354 namespace detail {
Chris@16 355
Chris@16 356 template<typename T, typename Tag>
Chris@16 357 struct has_trait_impl {
Chris@16 358 typedef typename category_of<T>::type category;
Chris@16 359 BOOST_STATIC_CONSTANT(bool, value = (is_convertible<category, Tag>::value));
Chris@16 360 };
Chris@16 361
Chris@16 362 template<typename T, typename Tag>
Chris@16 363 struct has_trait
Chris@16 364 : mpl::bool_<has_trait_impl<T, Tag>::value>
Chris@16 365 { };
Chris@16 366
Chris@16 367 } // End namespace detail.
Chris@16 368
Chris@16 369 template<typename T>
Chris@16 370 struct is_device : detail::has_trait<T, device_tag> { };
Chris@16 371
Chris@16 372 template<typename T>
Chris@16 373 struct is_filter : detail::has_trait<T, filter_tag> { };
Chris@16 374
Chris@16 375 template<typename T>
Chris@16 376 struct is_direct : detail::has_trait<T, direct_tag> { };
Chris@16 377
Chris@16 378 //------------------Definition of BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS----------//
Chris@16 379
Chris@16 380 #define BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
Chris@16 381 typedef Tr traits_type; \
Chris@16 382 typedef typename traits_type::int_type int_type; \
Chris@16 383 typedef typename traits_type::off_type off_type; \
Chris@16 384 typedef typename traits_type::pos_type pos_type; \
Chris@16 385 /**/
Chris@16 386
Chris@16 387 } } // End namespaces iostreams, boost.
Chris@16 388
Chris@16 389 #include <boost/iostreams/detail/config/enable_warnings.hpp>
Chris@16 390
Chris@16 391 #endif // #ifndef BOOST_IOSTREAMS_IO_TRAITS_HPP_INCLUDED