os/ossrv/ossrv_pub/boost_apis/boost/iostreams/skip.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/iostreams/skip.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +// (C) Copyright Jonathan Turkanis 2003.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See accompanying
     1.6 +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
     1.7 +
     1.8 +// See http://www.boost.org/libs/iostreams for documentation.
     1.9 +
    1.10 +// To do: handle bidirection streams and output-seekable components.
    1.11 +
    1.12 +#ifndef BOOST_IOSTREAMS_SKIP_HPP_INCLUDED
    1.13 +#define BOOST_IOSTREAMS_SKIP_HPP_INCLUDED
    1.14 +
    1.15 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    1.16 +# pragma once
    1.17 +#endif
    1.18 +
    1.19 +#include <boost/iostreams/char_traits.hpp>
    1.20 +#include <boost/iostreams/detail/ios.hpp>  // failure.
    1.21 +#include <boost/iostreams/operations.hpp>
    1.22 +#include <boost/iostreams/traits.hpp>
    1.23 +#include <boost/mpl/and.hpp>
    1.24 +#include <boost/mpl/bool.hpp>
    1.25 +#include <boost/type_traits/is_convertible.hpp>
    1.26 +
    1.27 +namespace boost { namespace iostreams {
    1.28 +
    1.29 +namespace detail {
    1.30 +
    1.31 +template<typename Device>
    1.32 +void skip(Device& dev, stream_offset off, mpl::true_)
    1.33 +{ iostreams::seek(dev, off, BOOST_IOS::cur); }
    1.34 +
    1.35 +template<typename Device>
    1.36 +void skip(Device& dev, stream_offset off, mpl::false_)
    1.37 +{   // gcc 2.95 needs namespace qualification for char_traits.
    1.38 +    typedef typename char_type_of<Device>::type  char_type;
    1.39 +    typedef iostreams::char_traits<char_type>    traits_type;
    1.40 +    for (stream_offset z = 0; z < off; ) {
    1.41 +        typename traits_type::int_type c;
    1.42 +        if (traits_type::is_eof(c = iostreams::get(dev)))
    1.43 +            throw BOOST_IOSTREAMS_FAILURE("bad skip offset");
    1.44 +        if (!traits_type::would_block(c))
    1.45 +            ++z;
    1.46 +    }
    1.47 +}
    1.48 +
    1.49 +template<typename Filter, typename Device>
    1.50 +void skip(Filter& flt, Device& dev, stream_offset off, mpl::true_)
    1.51 +{ flt.seek(dev, off, BOOST_IOS::cur); }
    1.52 +
    1.53 +template<typename Filter, typename Device>
    1.54 +void skip(Filter& flt, Device& dev, stream_offset off, mpl::false_)
    1.55 +{ 
    1.56 +    typedef typename char_type_of<Device>::type char_type;
    1.57 +    char_type c;
    1.58 +    for (stream_offset z = 0; z < off; ) {
    1.59 +        std::streamsize amt;
    1.60 +        if ((amt = iostreams::read(flt, dev, &c, 1)) == -1)
    1.61 +            throw BOOST_IOSTREAMS_FAILURE("bad skip offset");
    1.62 +        if (amt == 1)
    1.63 +            ++z;
    1.64 +    }
    1.65 +}
    1.66 +
    1.67 +} // End namespace detail.
    1.68 +
    1.69 +template<typename Device>
    1.70 +void skip(Device& dev, stream_offset off)
    1.71 +{ 
    1.72 +    typedef typename mode_of<Device>::type mode;
    1.73 +    detail::skip(dev, off, is_convertible<mode, seekable>());
    1.74 +}
    1.75 +
    1.76 +template<typename Filter, typename Device>
    1.77 +void skip(Filter& flt, Device& dev, stream_offset off)
    1.78 +{ 
    1.79 +    typedef typename mode_of<Filter>::type                     filter_mode;
    1.80 +    typedef typename mode_of<Device>::type                     device_mode;
    1.81 +    typedef mpl::and_<
    1.82 +                is_convertible<filter_mode, output_seekable>,
    1.83 +                is_convertible<device_mode, output_seekable>
    1.84 +            >                                                  can_seek;
    1.85 +    detail::skip(flt, dev, off, can_seek());
    1.86 +}
    1.87 +
    1.88 +} } // End namespaces iostreams, boost.
    1.89 +
    1.90 +#endif // #ifndef BOOST_IOSTREAMS_SKIP_HPP_INCLUDED //------------------------//