Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: // Chris@16: // Contains metafunctions char_type_of, category_of and mode_of used for Chris@16: // deducing the i/o category and i/o mode of a model of Filter or Device. Chris@16: // Chris@16: // Also contains several utility metafunctions, functions and macros. Chris@16: // Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_IO_TRAITS_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_IO_TRAITS_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include // stream types, char_traits. Chris@16: #include // partial spec, deduced typename. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: # include Chris@16: # include Chris@16: #endif // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: #include Chris@16: #include Chris@16: Chris@16: // Must come last. Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { Chris@16: Chris@16: //----------Definitions of predicates for streams and stream buffers----------// Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------------------// Chris@16: Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_istream, std::basic_istream, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ostream, std::basic_ostream, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_iostream, std::basic_iostream, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_streambuf, std::basic_streambuf, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ifstream, std::basic_ifstream, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ofstream, std::basic_ofstream, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_fstream, std::basic_fstream, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_filebuf, std::basic_filebuf, 2) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_istringstream, std::basic_istringstream, 3) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ostringstream, std::basic_ostringstream, 3) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_stringstream, std::basic_stringstream, 3) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_stringbuf, std::basic_stringbuf, 3) Chris@16: Chris@16: #else // #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-----------------------// Chris@16: Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_istream, std::istream, 0) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_ostream, std::ostream, 0) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_iostream, std::iostream, 0) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_streambuf, std::streambuf, 0) Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //----------------------// Chris@16: Chris@16: template Chris@16: struct is_std_io Chris@16: : mpl::or_< is_istream, is_ostream, is_streambuf > Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct is_std_file_device Chris@16: : mpl::or_< Chris@16: is_ifstream, Chris@16: is_ofstream, Chris@16: is_fstream, Chris@16: is_filebuf Chris@16: > Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct is_std_string_device Chris@16: : mpl::or_< Chris@16: is_istringstream, Chris@16: is_ostringstream, Chris@16: is_stringstream, Chris@16: is_stringbuf Chris@16: > Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct stream; Chris@16: Chris@16: template Chris@16: class stream_buffer; Chris@16: Chris@16: template< typename Mode, typename Ch, typename Tr, Chris@16: typename Alloc, typename Access > Chris@16: class filtering_stream; Chris@16: Chris@16: template< typename Mode, typename Ch, typename Tr, Chris@16: typename Alloc, typename Access > Chris@16: class wfiltering_stream; Chris@16: Chris@16: template< typename Mode, typename Ch, typename Tr, Chris@16: typename Alloc, typename Access > Chris@16: class filtering_streambuf; Chris@16: Chris@16: template< typename Mode, typename Ch, typename Tr, Chris@16: typename Alloc, typename Access > Chris@16: class filtering_wstreambuf; Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: class linked_streambuf; Chris@16: Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_boost_stream, Chris@16: boost::iostreams::stream, Chris@16: 3 ) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_boost_stream_buffer, Chris@16: boost::iostreams::stream_buffer, Chris@16: 4 ) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_stream_impl, Chris@16: boost::iostreams::filtering_stream, Chris@16: 5 ) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_wstream_impl, Chris@16: boost::iostreams::wfiltering_stream, Chris@16: 5 ) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_streambuf_impl, Chris@16: boost::iostreams::filtering_streambuf, Chris@16: 5 ) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF( is_filtering_wstreambuf_impl, Chris@16: boost::iostreams::filtering_wstreambuf, Chris@16: 5 ) Chris@16: BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_linked, linked_streambuf, 2) Chris@16: Chris@16: template Chris@16: struct is_filtering_stream Chris@16: : mpl::or_< Chris@16: is_filtering_stream_impl, Chris@16: is_filtering_wstream_impl Chris@16: > Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct is_filtering_streambuf Chris@16: : mpl::or_< Chris@16: is_filtering_streambuf_impl, Chris@16: is_filtering_wstreambuf_impl Chris@16: > Chris@16: { }; Chris@16: Chris@16: template Chris@16: struct is_boost Chris@16: : mpl::or_< Chris@16: is_boost_stream, Chris@16: is_boost_stream_buffer, Chris@16: is_filtering_stream, Chris@16: is_filtering_streambuf Chris@16: > Chris@16: { }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: //------------------Definitions of char_type_of-------------------------------// Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct member_char_type { typedef typename T::char_type type; }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //---------------------------// Chris@16: # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------// Chris@16: Chris@16: template Chris@16: struct char_type_of Chris@16: : detail::member_char_type< Chris@16: typename detail::unwrapped_type::type Chris@16: > Chris@16: { }; Chris@16: Chris@16: # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------// Chris@16: Chris@16: template Chris@16: struct char_type_of { Chris@16: typedef typename detail::unwrapped_type::type U; Chris@16: typedef typename Chris@16: mpl::eval_if< Chris@16: is_std_io, Chris@16: mpl::identity, Chris@16: detail::member_char_type Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------// Chris@16: Chris@16: template Chris@16: struct char_type_of< iterator_range > { Chris@16: typedef typename iterator_value::type type; Chris@16: }; Chris@16: Chris@16: #else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //------------------// Chris@16: Chris@16: template Chris@16: struct char_type_of { Chris@16: template Chris@16: struct get_value_type { Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: typedef typename range_value::type type; Chris@16: #endif // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: }; Chris@16: typedef typename Chris@16: mpl::eval_if< Chris@16: is_iterator_range, Chris@16: get_value_type, Chris@16: detail::member_char_type< Chris@16: BOOST_DEDUCED_TYPENAME detail::unwrapped_type::type Chris@16: > Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: #endif // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //-----------------// Chris@16: Chris@16: //------------------Definitions of category_of--------------------------------// Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct member_category { typedef typename T::category type; }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template Chris@16: struct category_of { Chris@16: template Chris@16: struct member_category { Chris@16: typedef typename U::category type; Chris@16: }; Chris@16: typedef typename detail::unwrapped_type::type U; Chris@16: typedef typename Chris@16: mpl::eval_if< Chris@16: mpl::and_< Chris@16: is_std_io, Chris@16: mpl::not_< detail::is_boost > Chris@16: >, Chris@16: iostreams::select< // Disambiguation for Tru64 Chris@16: is_filebuf, filebuf_tag, Chris@16: is_ifstream, ifstream_tag, Chris@16: is_ofstream, ofstream_tag, Chris@16: is_fstream, fstream_tag, Chris@16: is_stringbuf, stringbuf_tag, Chris@16: is_istringstream, istringstream_tag, Chris@16: is_ostringstream, ostringstream_tag, Chris@16: is_stringstream, stringstream_tag, Chris@16: is_streambuf, generic_streambuf_tag, Chris@16: is_iostream, generic_iostream_tag, Chris@16: is_istream, generic_istream_tag, Chris@16: is_ostream, generic_ostream_tag Chris@16: >, Chris@16: detail::member_category Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: // Partial specialization for reference wrappers Chris@16: #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //---------------------------// Chris@16: Chris@16: template Chris@16: struct category_of< reference_wrapper > Chris@16: : category_of Chris@16: { }; Chris@16: Chris@16: #endif // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //-----------------// Chris@16: Chris@16: //------------------Definition of get_category--------------------------------// Chris@16: Chris@16: // Chris@16: // Returns an object of type category_of::type. Chris@16: // Chris@16: template Chris@16: inline typename category_of::type get_category(const T&) Chris@16: { typedef typename category_of::type category; return category(); } Chris@16: Chris@16: //------------------Definition of int_type_of---------------------------------// Chris@16: Chris@16: template Chris@16: struct int_type_of { Chris@16: #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES Chris@16: typedef std::char_traits< Chris@16: BOOST_DEDUCED_TYPENAME char_type_of::type Chris@16: > traits_type; Chris@16: typedef typename traits_type::int_type type; Chris@16: #else Chris@16: typedef int type; Chris@16: #endif Chris@16: }; Chris@16: Chris@16: //------------------Definition of mode_of-------------------------------------// Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template struct io_mode_impl; Chris@16: Chris@16: #define BOOST_IOSTREAMS_MODE_HELPER(tag_, id_) \ Chris@16: case_ io_mode_impl_helper(tag_); \ Chris@16: template<> struct io_mode_impl { typedef tag_ type; }; \ Chris@16: /**/ Chris@16: BOOST_IOSTREAMS_MODE_HELPER(input, 1) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(output, 2) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(bidirectional, 3) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(input_seekable, 4) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(output_seekable, 5) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(seekable, 6) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(dual_seekable, 7) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(bidirectional_seekable, 8) Chris@16: BOOST_IOSTREAMS_MODE_HELPER(dual_use, 9) Chris@16: #undef BOOST_IOSTREAMS_MODE_HELPER Chris@16: Chris@16: template Chris@16: struct io_mode_id { Chris@16: typedef typename category_of::type category; Chris@16: BOOST_SELECT_BY_SIZE(int, value, detail::io_mode_impl_helper(category())); Chris@16: }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template // Borland 5.6.4 requires this circumlocution. Chris@16: struct mode_of : detail::io_mode_impl< detail::io_mode_id::value > { }; Chris@16: Chris@16: // Partial specialization for reference wrappers Chris@16: #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //---------------------------// Chris@16: Chris@16: template Chris@16: struct mode_of< reference_wrapper > Chris@16: : mode_of Chris@16: { }; Chris@16: Chris@16: #endif // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION //-----------------// Chris@16: Chris@16: //------------------Definition of is_device, is_filter and is_direct----------// Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct has_trait_impl { Chris@16: typedef typename category_of::type category; Chris@16: BOOST_STATIC_CONSTANT(bool, value = (is_convertible::value)); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct has_trait Chris@16: : mpl::bool_::value> Chris@16: { }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template Chris@16: struct is_device : detail::has_trait { }; Chris@16: Chris@16: template Chris@16: struct is_filter : detail::has_trait { }; Chris@16: Chris@16: template Chris@16: struct is_direct : detail::has_trait { }; Chris@16: Chris@16: //------------------Definition of BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS----------// Chris@16: Chris@16: #define BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \ Chris@16: typedef Tr traits_type; \ Chris@16: typedef typename traits_type::int_type int_type; \ Chris@16: typedef typename traits_type::off_type off_type; \ Chris@16: typedef typename traits_type::pos_type pos_type; \ Chris@16: /**/ Chris@16: Chris@16: } } // End namespaces iostreams, boost. Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_IO_TRAITS_HPP_INCLUDED