os/ossrv/ossrv_pub/boost_apis/boost/iostreams/stream_buffer.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // (C) Copyright Jonathan Turkanis 2003.
     2 // Distributed under the Boost Software License, Version 1.0. (See accompanying
     3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
     4 
     5 // See http://www.boost.org/libs/iostreams for documentation.
     6 
     7 #ifndef BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED
     8 #define BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED
     9 
    10 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
    11 # pragma once
    12 #endif
    13 
    14 #include <memory>            // allocator.
    15 #include <boost/config.hpp>  // BOOST_DEDUCED_TYPENAME.
    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/ios.hpp>  // failure, streamsize.
    20 #include <boost/iostreams/detail/streambuf/direct_streambuf.hpp>
    21 #include <boost/iostreams/detail/streambuf/indirect_streambuf.hpp>
    22 #include <boost/iostreams/traits.hpp>
    23 #include <boost/static_assert.hpp>
    24 #include <boost/type_traits/is_convertible.hpp>
    25 
    26 // Must come last.
    27 #include <boost/iostreams/detail/config/disable_warnings.hpp>  // MSVC.
    28 
    29 namespace boost { namespace iostreams { namespace detail {
    30 
    31 template<typename T, typename Tr, typename Alloc, typename Mode>
    32 struct stream_buffer_traits {
    33     typedef typename
    34             mpl::if_<
    35                 is_convertible<
    36                     BOOST_DEDUCED_TYPENAME category_of<T>::type,
    37                     direct_tag
    38                 >,
    39                 direct_streambuf<T, Tr>,
    40                 indirect_streambuf<T, Tr, Alloc, Mode>
    41             >::type type;
    42 };
    43 
    44 } } } // End namespaces detail, iostreams, boost
    45 
    46 #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
    47 # include <boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp>
    48 #else
    49 
    50 namespace boost { namespace iostreams {
    51 
    52 template< typename T,
    53           typename Tr =
    54               BOOST_IOSTREAMS_CHAR_TRAITS(
    55                   BOOST_DEDUCED_TYPENAME char_type_of<T>::type
    56               ),
    57           typename Alloc =
    58               std::allocator<
    59                   BOOST_DEDUCED_TYPENAME char_type_of<T>::type
    60               >,
    61           typename Mode = BOOST_DEDUCED_TYPENAME mode_of<T>::type >
    62 class stream_buffer
    63     : public detail::stream_buffer_traits<T, Tr, Alloc, Mode>::type
    64 {
    65 private:
    66     BOOST_STATIC_ASSERT((
    67         is_convertible<
    68             BOOST_DEDUCED_TYPENAME iostreams::category_of<T>::type, Mode
    69         >::value
    70     ));
    71     typedef typename
    72             detail::stream_buffer_traits<
    73                 T, Tr, Alloc, Mode
    74             >::type                           base_type;
    75     typedef T                                 policy_type;
    76 public:
    77     typedef typename char_type_of<T>::type    char_type;
    78     BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
    79 public:
    80     stream_buffer() { }
    81     ~stream_buffer()
    82     { 
    83         try { 
    84             if (this->is_open() && this->auto_close()) 
    85                 this->close(); 
    86         } catch (std::exception&) { } 
    87     }
    88     BOOST_IOSTREAMS_FORWARD( stream_buffer, open_impl, T,
    89                              BOOST_IOSTREAMS_PUSH_PARAMS,
    90                              BOOST_IOSTREAMS_PUSH_ARGS )
    91     T& operator*() { return *this->component(); }
    92     T* operator->() { return this->component(); }
    93 private:
    94     void open_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS())
    95         {   // Used for forwarding.
    96             if (this->is_open())
    97                 BOOST_IOSTREAMS_FAILURE("already open");
    98             base_type::open(t BOOST_IOSTREAMS_PUSH_ARGS());
    99         }
   100 };
   101 
   102 } } // End namespaces iostreams, boost.
   103 
   104 #endif // #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
   105 
   106 #include <boost/iostreams/detail/config/enable_warnings.hpp>  // MSVC.
   107 
   108 #endif // #ifndef BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED