diff --git a/include/boost/iostreams/offset.hpp b/include/boost/iostreams/offset.hpp deleted file mode 100755 index d721744..0000000 --- a/include/boost/iostreams/offset.hpp +++ /dev/null @@ -1,384 +0,0 @@ -// (C) Copyright Jonathan Turkanis 2005. -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) - -// See http://www.boost.org/libs/iostreams for documentation. - -#ifndef BOOST_IOSTREAMS_OFFSET_HPP_INCLUDED -#define BOOST_IOSTREAMS_OFFSET_HPP_INCLUDED - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include // min. -#include // pair. -#include // intmax_t. -#include // DEDUCED_TYPENAME. -#include -#include -#include -#include -#include -#include -#include // failure. -#include -#include -#include -#include // mode_of, is_direct. -#include -#include -#include - -#include // VC7.1 C4244. - -namespace boost { namespace iostreams { - -namespace detail { - -// -// Template name: offset_indirect_device. -// Description: Provides an offset view of an indirect Device. -// Template paramters: -// Device - An indirect model of Device that models either Source or -// SeekableDevice. -// -template -class offset_indirect_device : public basic_adapter { -private: - typedef typename detail::param_type::type param_type; -public: - typedef typename char_type_of::type char_type; - struct category - : mode_of::type, - device_tag, - closable_tag, - flushable_tag, - localizable_tag, - optimally_buffered_tag - { }; - offset_indirect_device( param_type dev, stream_offset off, - stream_offset len ); - std::streamsize read(char_type* s, std::streamsize n); - std::streamsize write(const char_type* s, std::streamsize n); - stream_offset seek(stream_offset off, BOOST_IOS::seekdir way); -private: - stream_offset beg_, pos_, end_; -}; - -// -// Template name: offset_direct_device. -// Description: Provides an offset view of a Direct Device. -// Template paramters: -// Device - A model of Direct and Device. -// -template -class offset_direct_device : public basic_adapter { -public: - typedef typename char_type_of::type char_type; - typedef std::pair pair_type; - struct category - : mode_of::type, - device_tag, - direct_tag, - closable_tag, - localizable_tag - { }; - offset_direct_device( const Device& dev, stream_offset off, - stream_offset len ); - pair_type input_sequence(); - pair_type output_sequence(); -private: - pair_type sequence(mpl::true_); - pair_type sequence(mpl::false_); - char_type *beg_, *end_; -}; - -// -// Template name: offset_filter. -// Description: Provides an offset view of a Filter. -// Template paramters: -// Filter - An indirect model of Filter. -// -template -class offset_filter : public basic_adapter { -public: - typedef typename char_type_of::type char_type; - struct category - : mode_of::type, - filter_tag, - multichar_tag, - closable_tag, - localizable_tag, - optimally_buffered_tag - { }; - offset_filter(const Filter& flt, stream_offset off, stream_offset len); - - template - std::streamsize read(Source& src, char_type* s, std::streamsize n) - { - using namespace std; - if (!open_) - open(src); - streamsize amt = - (std::min) (n, static_cast(end_ - pos_)); - streamsize result = iostreams::read(this->component(), src, s, amt); - if (result != -1) - pos_ += result; - return result; - } - - template - std::streamsize write(Sink& snk, const char_type* s, std::streamsize n) - { - if (!open_) - open(snk); - if (pos_ + n >= end_) - bad_write(); - std::streamsize result = - iostreams::write(this->component(), snk, s, n); - pos_ += result; - return result; - } - - template - stream_offset seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way) - { - stream_offset next; - if (way == BOOST_IOS::beg) { - next = beg_ + off; - } else if (way == BOOST_IOS::cur) { - next = pos_ + off; - } else { - next = end_ + off; - } - if (next < beg_ || next >= end_) - bad_seek(); - pos_ = this->component().seek(dev, next, BOOST_IOS::cur); - return pos_ - beg_; - } -private: - template - void open(Device& dev) - { - open_ = true; - iostreams::skip(this->component(), dev, beg_); - } - stream_offset beg_, pos_, end_; - bool open_; -}; - -template -struct offset_traits - : iostreams::select< // Disambiguation for Tru64. - is_filter, offset_filter, - is_direct, offset_direct_device, - else_, offset_indirect_device - > - { }; - -} // End namespace detail. - -template -struct offset_view : public detail::offset_traits::type { - typedef typename detail::param_type::type param_type; - offset_view(param_type t, stream_offset off, stream_offset len) - : detail::offset_traits::type(t, off, len) - { } -}; - -//--------------Implementation of offset--------------------------------------// - -// Note: The following workarounds are patterned after resolve.hpp. It has not -// yet been confirmed that they are necessary. - -#ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //-------------------------// -# ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------// - -template -offset_view offset( const T& t, stream_offset off, stream_offset len - BOOST_IOSTREAMS_DISABLE_IF_STREAM(T) ) -{ return offset_view(t, off, len); } - -template -offset_view< std::basic_streambuf > -offset(std::basic_streambuf& sb) -{ return offset_view< std::basic_streambuf >(sb); } - -template -offset_view< std::basic_istream > -offset(std::basic_istream& is) -{ return offset_view< std::basic_istream >(is); } - -template -offset_view< std::basic_ostream > -offset(std::basic_ostream& os) -{ return offset_view< std::basic_ostream >(os); } - -template -offset_view< std::basic_iostream > -offset(std::basic_iostream& io) -{ return offset_view< std::basic_iostream >(io); } - -# else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------// - -template -offset_view offset( const T& t, stream_offset off, stream_offset len - BOOST_IOSTREAMS_DISABLE_IF_STREAM(T) ) -{ return offset_view(t, off, len); } - -offset_view offset(std::streambuf& sb) -{ return offset_view(sb); } - -offset_view offset(std::istream& is) -{ return offset_view(is); } - -offset_view offset(std::ostream& os) -{ return offset_view(os); } - -offset_view offset(std::iostream& io) -{ return offset_view(io); } - -# endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------// -#else // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //----------------// - -template -offset_view offset(const T& t, mpl::true_) -{ // Bad overload resolution. - return offset_view(const_cast(t)); -} - -template -offset_view offset(const T& t, mpl::false_) -{ return offset_view(t); } - -template -offset_view offset(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) -{ return offset(t, is_std_io()); } - -# if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) && \ - !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \ - !defined(__GNUC__) // ---------------------------------------------------// - -template -offset_view offset(T& t) { return offset_view(t); } - -# endif // Borland 5.x, VC6-7.0 or GCC 2.9x //--------------------------------// -#endif // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //---------------// -//----------------------------------------------------------------------------// - -namespace detail { - -//--------------Implementation of offset_indirect_device----------------------// - -template -offset_indirect_device::offset_indirect_device - (param_type dev, stream_offset off, stream_offset len) - : basic_adapter(dev), beg_(off), pos_(off), end_(off + len) -{ - if (len < 0 || off < 0) - throw BOOST_IOSTREAMS_FAILURE("bad offset"); - iostreams::skip(this->component(), off); -} - -template -inline std::streamsize offset_indirect_device::read - (char_type* s, std::streamsize n) -{ - using namespace std; - streamsize amt = - (std::min) (n, static_cast(end_ - pos_)); - streamsize result = iostreams::read(this->component(), s, amt); - if (result != -1) - pos_ += result; - return result; -} - -template -inline std::streamsize offset_indirect_device::write - (const char_type* s, std::streamsize n) -{ - if (pos_ + n >= end_) - bad_write(); - streamsize result = iostreams::write(this->component(), s, n); - pos_ += result; - return result; -} - -template -stream_offset offset_indirect_device::seek - (stream_offset off, BOOST_IOS::seekdir way) -{ - stream_offset next; - if (way == BOOST_IOS::beg) { - next = beg_ + off; - } else if (way == BOOST_IOS::cur) { - next = pos_ + off; - } else { - next = end_ + off; - } - if (next < beg_ || next >= end_) - bad_seek(); - pos_ = iostreams::seek(this->component(), next - pos_, BOOST_IOS::cur); - return pos_ - beg_; -} - -//--------------Implementation of offset_direct_device------------------------// - -template -offset_direct_device::offset_direct_device - (const Device& dev, stream_offset off, stream_offset len) - : basic_adapter(dev), beg_(0), end_(0) -{ - std::pair seq = - sequence(is_convertible()); - if (off < 0 || len < 0 || off + len > seq.second - seq.first) - throw BOOST_IOSTREAMS_FAILURE("bad offset"); - beg_ = seq.first + off; - end_ = seq.first + off + len; -} - -template -typename offset_direct_device::pair_type -offset_direct_device::input_sequence() -{ - BOOST_STATIC_ASSERT((is_convertible::value)); - return std::make_pair(beg_, end_); -} - -template -typename offset_direct_device::pair_type -offset_direct_device::output_sequence() -{ - BOOST_STATIC_ASSERT((is_convertible::value)); - return std::make_pair(beg_, end_); -} - -template -typename offset_direct_device::pair_type -offset_direct_device::sequence(mpl::true_) -{ return iostreams::input_sequence(this->component()); } - -template -typename offset_direct_device::pair_type -offset_direct_device::sequence(mpl::false_) -{ return iostreams::output_sequence(this->component()); } - -//--------------Implementation of offset_filter-------------------------------// - -template -offset_filter::offset_filter - (const Filter& flt, stream_offset off, stream_offset len) - : basic_adapter(flt), beg_(off), - pos_(off), end_(off + len), open_(false) -{ - if (len < 0 || off < 0) - throw BOOST_IOSTREAMS_FAILURE("bad offset"); -} - -} // End namespace detail. - -} } // End namespaces iostreams, boost. - - -#endif // #ifndef BOOST_IOSTREAMS_OFFSET_HPP_INCLUDED