From 1379d5f21c8b4e8a9839bc8565ae47b5db2e57cf Mon Sep 17 00:00:00 2001 From: Jonathan Turkanis Date: Wed, 13 Apr 2005 21:25:45 +0000 Subject: [PATCH] large seek offset support [SVN r28227] --- include/boost/iostreams/chain.hpp | 10 ++-- include/boost/iostreams/code_converter.hpp | 2 - include/boost/iostreams/compose.hpp | 16 +++---- .../detail/adapter/concept_adapter.hpp | 40 ++++++++-------- .../detail/adapter/direct_adapter.hpp | 10 ++-- .../iostreams/detail/adapter/mode_adapter.hpp | 16 +++---- .../adapter/random_access_container.hpp | 10 ++-- .../detail/adapter/range_adapter.hpp | 11 +++-- .../detail/streambuf/indirect_streambuf.hpp | 5 +- .../boost/iostreams/detail/vc6/operations.hpp | 48 +++++++++++++------ include/boost/iostreams/device/file.hpp | 14 +++--- .../iostreams/device/file_descriptor.hpp | 3 +- include/boost/iostreams/device/null.hpp | 9 ++-- include/boost/iostreams/offset.hpp | 40 ++++++++-------- include/boost/iostreams/operations.hpp | 47 +++++++++++++----- include/boost/iostreams/positioning.hpp | 12 +++++ include/boost/iostreams/skip.hpp | 16 +++---- src/file_descriptor.cpp | 27 +++++++---- test/detail/filters.hpp | 4 +- test/offset_test.cpp | 28 +++++------ test/positioning_test.cpp | 21 ++++---- 21 files changed, 226 insertions(+), 163 deletions(-) diff --git a/include/boost/iostreams/chain.hpp b/include/boost/iostreams/chain.hpp index cba300a..3c55429 100755 --- a/include/boost/iostreams/chain.hpp +++ b/include/boost/iostreams/chain.hpp @@ -24,13 +24,13 @@ #include // BOOST_MSVC, template friends. #include #include -#include #include #include #include #include // pubsync. #include #include +#include #include // is_filter. #include #include @@ -162,7 +162,7 @@ public: std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek(std::streamoff off, BOOST_IOS::seekdir way); + stream_offset seek(stream_offset off, BOOST_IOS::seekdir way); //----------Direct component access---------------------------------------// @@ -488,9 +488,9 @@ inline void chain_base::write { list().front()->sputn(s, n); } template -inline std::streamoff chain_base::seek - (std::streamoff off, BOOST_IOS::seekdir way) -{ return list().front()->pubseekoff(off, way); } +inline stream_offset chain_base::seek + (stream_offset off, BOOST_IOS::seekdir way) +{ return iostreams::seek(*list().front(), off, way); } template void chain_base::reset() diff --git a/include/boost/iostreams/code_converter.hpp b/include/boost/iostreams/code_converter.hpp index b242772..99492f6 100755 --- a/include/boost/iostreams/code_converter.hpp +++ b/include/boost/iostreams/code_converter.hpp @@ -319,8 +319,6 @@ public: std::streamsize read(char_type*, std::streamsize); void write(const char_type*, std::streamsize); - std::streamoff seek( std::streamoff, BOOST_IOS::seekdir, - BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out ); void imbue(const std::locale& loc) { impl().cvt_.imbue(loc); } // Direct device access. diff --git a/include/boost/iostreams/compose.hpp b/include/boost/iostreams/compose.hpp index 74ea755..5a562f0 100755 --- a/include/boost/iostreams/compose.hpp +++ b/include/boost/iostreams/compose.hpp @@ -55,9 +55,9 @@ public: composite_device(const Filter& flt, param_type dev); std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek( std::streamoff off, BOOST_IOS::seekdir way, - BOOST_IOS::openmode which = - BOOST_IOS::in | BOOST_IOS::out ); + stream_offset seek( stream_offset off, BOOST_IOS::seekdir way, + BOOST_IOS::openmode which = + BOOST_IOS::in | BOOST_IOS::out ); void close(BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out); bool flush(); @@ -112,9 +112,9 @@ public: } template - std::streamoff - seek( Device& dev, std::streamoff off, BOOST_IOS::seekdir way, - BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out ) + stream_offset seek( Device& dev, stream_offset off, BOOST_IOS::seekdir way, + BOOST_IOS::openmode which = + BOOST_IOS::in | BOOST_IOS::out ) { composite_device cmp(filter2_, dev); return iostreams::seek(filter1_, cmp, off, way, which); @@ -286,8 +286,8 @@ inline void composite_device::write { return iostreams::write(filter_, device_, s, n); } template -std::streamoff composite_device::seek - (std::streamoff off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) +stream_offset composite_device::seek + (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) { return iostreams::seek(filter_, device_, off, way, which); } template diff --git a/include/boost/iostreams/detail/adapter/concept_adapter.hpp b/include/boost/iostreams/detail/adapter/concept_adapter.hpp index cbcdfb4..cecbf7b 100755 --- a/include/boost/iostreams/detail/adapter/concept_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/concept_adapter.hpp @@ -78,16 +78,16 @@ public: void write(const char_type* s, std::streamsize n, Sink* snk) { output_impl::write(t_, snk, s, n); } - std::streamoff seek( std::streamoff off, BOOST_IOS::seekdir way, - BOOST_IOS::openmode which ) + stream_offset seek( stream_offset off, BOOST_IOS::seekdir way, + BOOST_IOS::openmode which ) { return this->seek( off, way, which, (basic_null_device*) 0); } template - std::streamoff seek( std::streamoff off, BOOST_IOS::seekdir way, - BOOST_IOS::openmode which, Device* dev ) + stream_offset seek( stream_offset off, BOOST_IOS::seekdir way, + BOOST_IOS::openmode which, Device* dev ) { return any_impl::seek(t_, dev, off, way, which); } void close(BOOST_IOS::openmode which) @@ -120,8 +120,8 @@ public: template<> struct device_wrapper_impl { template - static std::streamoff - seek( Device& dev, Dummy*, std::streamoff off, + static stream_offset + seek( Device& dev, Dummy*, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) { typedef typename io_category::type io_category; @@ -129,16 +129,16 @@ struct device_wrapper_impl { } template - static std::streamoff - seek( Device&, std::streamoff, BOOST_IOS::seekdir, + static stream_offset + seek( Device&, stream_offset, BOOST_IOS::seekdir, BOOST_IOS::openmode, any_tag ) { throw cant_seek(); } template - static std::streamoff - seek( Device& dev, std::streamoff off, + static stream_offset + seek( Device& dev, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which, random_access ) { @@ -188,8 +188,8 @@ struct device_wrapper_impl { template<> struct flt_wrapper_impl { template - static std::streamoff - seek( Filter& f, Device* dev, std::streamoff off, + static stream_offset + seek( Filter& f, Device* dev, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) { typedef typename io_category::type io_category; @@ -197,14 +197,14 @@ struct flt_wrapper_impl { } template - static std::streamoff - seek( Filter&, Device*, std::streamoff, + static stream_offset + seek( Filter&, Device*, stream_offset, BOOST_IOS::seekdir, BOOST_IOS::openmode, any_tag ) { throw cant_seek(); } template - static std::streamoff - seek( Filter& f, Device* dev, std::streamoff off, + static stream_offset + seek( Filter& f, Device* dev, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which, random_access tag ) { @@ -213,15 +213,15 @@ struct flt_wrapper_impl { } template - static std::streamoff - seek( Filter& f, Device* dev, std::streamoff off, + static stream_offset + seek( Filter& f, Device* dev, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which, random_access, any_tag ) { return f.seek(*dev, off, way); } template - static std::streamoff - seek( Filter& f, Device* dev, std::streamoff off, + static stream_offset + seek( Filter& f, Device* dev, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which, random_access, two_sequence ) { return f.seek(*dev, off, way); } diff --git a/include/boost/iostreams/detail/adapter/direct_adapter.hpp b/include/boost/iostreams/detail/adapter/direct_adapter.hpp index 19d182a..5585bc9 100755 --- a/include/boost/iostreams/detail/adapter/direct_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/direct_adapter.hpp @@ -108,8 +108,8 @@ public: std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek( std::streamoff, BOOST_IOS::seekdir, - BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out ); + stream_offset seek( stream_offset, BOOST_IOS::seekdir, + BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out ); void close(); void close(BOOST_IOS::openmode which); #ifndef BOOST_IOSTREAMS_NO_LOCALE @@ -211,8 +211,8 @@ inline void direct_adapter::write } template -inline std::streamoff direct_adapter::seek - ( std::streamoff off, BOOST_IOS::seekdir way, +inline stream_offset direct_adapter::seek + ( stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) { using namespace std; @@ -245,7 +245,7 @@ inline std::streamoff direct_adapter::seek else bad_seek(); } - return static_cast(next); + return static_cast(next); } template diff --git a/include/boost/iostreams/detail/adapter/mode_adapter.hpp b/include/boost/iostreams/detail/adapter/mode_adapter.hpp index f267bee..02f7ad4 100755 --- a/include/boost/iostreams/detail/adapter/mode_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/mode_adapter.hpp @@ -48,9 +48,9 @@ public: std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek( std::streamoff off, BOOST_IOS::seekdir way, - BOOST_IOS::openmode which = - BOOST_IOS::in | BOOST_IOS::out ); + stream_offset seek( stream_offset off, BOOST_IOS::seekdir way, + BOOST_IOS::openmode which = + BOOST_IOS::in | BOOST_IOS::out ); #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) void close(BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out); #endif @@ -66,12 +66,12 @@ public: { iostreams::write(t_, snk, s, n); } template - std::streamoff seek(Device& dev, std::streamoff off, BOOST_IOS::seekdir way) + stream_offset seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way) { return iostreams::seek(t_, dev, off, way); } template - std::streamoff seek( Device& dev, std::streamoff off, - BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) + stream_offset seek( Device& dev, stream_offset off, + BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) { return iostreams::seek(t_, dev, off, way, which); } template @@ -100,8 +100,8 @@ void mode_adapter::write(const char_type* s, std::streamsize n) { boost::iostreams::write(t_, s, n); } template -std::streamoff mode_adapter::seek - (std::streamoff off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) +stream_offset mode_adapter::seek + (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) { return boost::iostreams::seek(t_, off, way, which); } #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) diff --git a/include/boost/iostreams/detail/adapter/random_access_container.hpp b/include/boost/iostreams/detail/adapter/random_access_container.hpp index 4315a41..0e32c9e 100755 --- a/include/boost/iostreams/detail/adapter/random_access_container.hpp +++ b/include/boost/iostreams/detail/adapter/random_access_container.hpp @@ -64,8 +64,8 @@ public: { } std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek( std::streamoff, BOOST_IOS::seekdir, - BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out ); + stream_offset seek( std::streamoff, BOOST_IOS::seekdir, + BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out ); Container container() const { return *pimpl_->cnt_; } void container(const Container& cnt) { @@ -120,8 +120,8 @@ void random_access_container::write } template -std::streamoff random_access_container::seek - (std::streamoff off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) +stream_offset random_access_container::seek + (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) { using namespace std; if (way == BOOST_IOS::cur && pimpl_->gptr() != pimpl_->pptr()) @@ -163,7 +163,7 @@ std::streamoff random_access_container::seek else bad_seek(); } - return static_cast( + return static_cast( (which & BOOST_IOS::in) ? pimpl_->gptr() : pimpl_->pptr() diff --git a/include/boost/iostreams/detail/adapter/range_adapter.hpp b/include/boost/iostreams/detail/adapter/range_adapter.hpp index 23ed745..ee16f73 100755 --- a/include/boost/iostreams/detail/adapter/range_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/range_adapter.hpp @@ -17,6 +17,7 @@ #include // streamsize, streamoff. #include #include +#include #include #include #include @@ -54,7 +55,7 @@ public: range_adapter(iterator first, iterator last); std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek(std::streamoff off, BOOST_IOS::seekdir way); + stream_offset seek(stream_offset off, BOOST_IOS::seekdir way); private: iterator first_, cur_, last_; }; @@ -81,11 +82,11 @@ void range_adapter::write template -std::streamoff range_adapter::seek - (std::streamoff off, BOOST_IOS::seekdir way) +stream_offset range_adapter::seek + (stream_offset off, BOOST_IOS::seekdir way) { impl::seek(first_, cur_, last_, off, way); - return static_cast(cur_ - first_); + return static_cast(cur_ - first_); } //------------------Implementation of range_adapter_impl----------------------// @@ -140,7 +141,7 @@ struct range_adapter_impl { template static void seek - ( Iter& first, Iter& cur, Iter& last, std::streamoff off, + ( Iter& first, Iter& cur, Iter& last, stream_offset off, BOOST_IOS::seekdir way ) { using namespace std; diff --git a/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp b/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp index c787766..5705e0d 100755 --- a/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp +++ b/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -113,7 +114,7 @@ private: //----------Utility function----------------------------------------------// - pos_type seek_impl( off_type off, BOOST_IOS::seekdir way, + pos_type seek_impl( stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ); void sync_impl(); void close_impl(BOOST_IOS::openmode); @@ -386,7 +387,7 @@ indirect_streambuf::seekpos template typename indirect_streambuf::pos_type indirect_streambuf::seek_impl - (off_type off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) + (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which) { if (pptr() != 0) sync(); if (way == BOOST_IOS::cur && gptr()) diff --git a/include/boost/iostreams/detail/vc6/operations.hpp b/include/boost/iostreams/detail/vc6/operations.hpp index 27897fe..3803eb2 100755 --- a/include/boost/iostreams/detail/vc6/operations.hpp +++ b/include/boost/iostreams/detail/vc6/operations.hpp @@ -85,8 +85,8 @@ void write(T& t, Sink& snk, const typename io_char::type* s, std::streamsize } template -inline std::streamoff -seek( T& t, std::streamoff off, BOOST_IOS::seekdir way, +inline stream_offset +seek( T& t, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out ) { return detail::seek_impl::seek(detail::unwrap(t), off, way, which); } @@ -371,26 +371,35 @@ struct seek_impl template<> struct seek_impl { template - static std::streamoff seek( T& t, std::streamoff off, - BOOST_IOS::seekdir way, BOOST_IOS::openmode ) + static stream_offset seek( T& t, stream_offset off, + BOOST_IOS::seekdir way, BOOST_IOS::openmode ) { return t.seek(off, way); } }; template<> struct seek_impl { template - static std::streamoff seek( T& t, std::streamoff off, - BOOST_IOS::seekdir way, - BOOST_IOS::openmode which ) + static stream_offset seek( T& t, stream_offset off, + BOOST_IOS::seekdir way, + BOOST_IOS::openmode which ) { return t.seek(off, way, which); } }; struct seek_impl_basic_ios { template - static std::streamoff seek( T& t, std::streamoff off, - BOOST_IOS::seekdir way, - BOOST_IOS::openmode which ) - { return t.rdbuf()->pubseekoff(off, way, which); } + static stream_offset seek( T& t, stream_offset off, + BOOST_IOS::seekdir way, + BOOST_IOS::openmode which ) + { + if ( way == BOOST_IOS::beg && + ( off < integer_traits::const_min || + off > integer_traits::const_max ) ) + { + return t.rdbuf()->pubseekpos(offset_to_position(off)); + } else { + return t.rdbuf()->pubseekoff(off, way, which); + } + } }; template<> @@ -405,10 +414,19 @@ struct seek_impl : seek_impl_basic_ios { }; template<> struct seek_impl { template - static std::streamoff seek( T& t, std::streamoff off, - BOOST_IOS::seekdir way, - BOOST_IOS::openmode which ) - { return t.pubseekoff(off, way, which); } + static stream_offset seek( T& t, stream_offset off, + BOOST_IOS::seekdir way, + BOOST_IOS::openmode which ) + { + if ( way == BOOST_IOS::beg && + ( off < integer_traits::const_min || + off > integer_traits::const_max ) ) + { + return t.pubseekpos(offset_to_position(off)); + } else { + return t.pubseekoff(off, way, which); + } + } }; //------------------Definition of close_impl----------------------------------// diff --git a/include/boost/iostreams/device/file.hpp b/include/boost/iostreams/device/file.hpp index e1387de..7f95607 100755 --- a/include/boost/iostreams/device/file.hpp +++ b/include/boost/iostreams/device/file.hpp @@ -27,7 +27,7 @@ #include #include // openmode, seekdir, int types. #include -#include // pubseekoff. +#include // seek. #include #include // MSVC. @@ -50,9 +50,9 @@ public: BOOST_IOS::in | BOOST_IOS::out ); std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek( std::streamoff off, BOOST_IOS::seekdir way, - BOOST_IOS::openmode which = - BOOST_IOS::in | BOOST_IOS::out ); + stream_offset seek( stream_offset off, BOOST_IOS::seekdir way, + BOOST_IOS::openmode which = + BOOST_IOS::in | BOOST_IOS::out ); void close(); #ifndef BOOST_IOSTREAMS_NO_LOCALE void imbue(const std::locale& loc) { pimpl_->file_.pubimbue(loc); } @@ -130,10 +130,10 @@ inline void basic_file::write { pimpl_->file_.sputn(s, n); } template -std::streamoff basic_file::seek - ( std::streamoff off, BOOST_IOS::seekdir way, +stream_offset basic_file::seek + ( stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode ) -{ return pimpl_->file_.BOOST_IOSTREAMS_PUBSEEKOFF(off, way); } +{ return iostreams::seek(pimpl_->file_, off, way); } template void basic_file::close() { pimpl_->file_.close(); } diff --git a/include/boost/iostreams/device/file_descriptor.hpp b/include/boost/iostreams/device/file_descriptor.hpp index 5052683..ae9ef12 100755 --- a/include/boost/iostreams/device/file_descriptor.hpp +++ b/include/boost/iostreams/device/file_descriptor.hpp @@ -21,6 +21,7 @@ #include #include #include // openmode, seekdir, int types. +#include #include // Must come last. @@ -61,7 +62,7 @@ public: BOOST_IOS::in | BOOST_IOS::out ); std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - boost::intmax_t seek(boost::intmax_t off, BOOST_IOS::seekdir way); + stream_offset seek(stream_offset off, BOOST_IOS::seekdir way); void close(); private: struct impl { diff --git a/include/boost/iostreams/device/null.hpp b/include/boost/iostreams/device/null.hpp index 54f3cac..6a9cf1d 100755 --- a/include/boost/iostreams/device/null.hpp +++ b/include/boost/iostreams/device/null.hpp @@ -14,7 +14,8 @@ #endif #include -#include // openmode, streamsize, streamoff. +#include // openmode, streamsize. +#include namespace boost { namespace iostreams { @@ -29,9 +30,9 @@ public: { }; std::streamsize read(Ch*, std::streamsize) { return 0; } void write(const Ch*, std::streamsize) { } - std::streamoff seek( std::streamoff, BOOST_IOS::seekdir, - BOOST_IOS::openmode = - BOOST_IOS::in | BOOST_IOS::out ) + stream_offset seek( stream_offset, BOOST_IOS::seekdir, + BOOST_IOS::openmode = + BOOST_IOS::in | BOOST_IOS::out ) { return -1; } void close(BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out) { } }; diff --git a/include/boost/iostreams/offset.hpp b/include/boost/iostreams/offset.hpp index ce087b7..73ba55d 100755 --- a/include/boost/iostreams/offset.hpp +++ b/include/boost/iostreams/offset.hpp @@ -56,13 +56,13 @@ public: localizable_tag, optimally_buffered_tag { }; - offset_indirect_device( param_type dev, std::streamoff off, - std::streamoff len ); + offset_indirect_device( param_type dev, stream_offset off, + stream_offset len ); std::streamsize read(char_type* s, std::streamsize n); void write(const char_type* s, std::streamsize n); - std::streamoff seek(std::streamoff off, BOOST_IOS::seekdir way); + stream_offset seek(stream_offset off, BOOST_IOS::seekdir way); private: - std::streamoff beg_, pos_, end_; + stream_offset beg_, pos_, end_; }; // @@ -83,8 +83,8 @@ public: closable_tag, localizable_tag { }; - offset_direct_device( const Device& dev, std::streamoff off, - std::streamoff len ); + offset_direct_device( const Device& dev, stream_offset off, + stream_offset len ); pair_type input_sequence(); pair_type output_sequence(); private: @@ -111,7 +111,7 @@ public: localizable_tag, optimally_buffered_tag { }; - offset_filter(const Filter& flt, std::streamoff off, std::streamoff len); + offset_filter(const Filter& flt, stream_offset off, stream_offset len); template std::streamsize read(Source& src, char_type* s, std::streamsize n) @@ -138,9 +138,9 @@ public: } template - std::streamoff seek(Device& dev, std::streamoff off, BOOST_IOS::seekdir way) + stream_offset seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way) { - std::streamoff next; + stream_offset next; if (way == BOOST_IOS::beg) { next = beg_ + off; } else if (way == BOOST_IOS::cur) { @@ -160,8 +160,8 @@ private: open_ = true; pos_ = iostreams::skip(this->component(), dev, beg_); } - std::streamoff beg_, pos_, end_; - bool open_; + stream_offset beg_, pos_, end_; + bool open_; }; template @@ -178,7 +178,7 @@ struct offset_traits template struct offset_view : public detail::offset_traits::type { typedef typename detail::param_type::type param_type; - offset_view(param_type t, std::streamoff off, std::streamoff len) + offset_view(param_type t, stream_offset off, stream_offset len) : detail::offset_traits::type(t, off, len) { } }; @@ -192,7 +192,7 @@ struct offset_view : public detail::offset_traits::type { # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------// template -offset_view offset( const T& t, std::streamoff off, std::streamoff len +offset_view offset( const T& t, stream_offset off, stream_offset len BOOST_IOSTREAMS_DISABLE_IF_STREAM(T) ) { return offset_view(t, off, len); } @@ -219,7 +219,7 @@ offset(std::basic_iostream& io) # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------// template -offset_view offset( const T& t, std::streamoff off, std::streamoff len +offset_view offset( const T& t, stream_offset off, stream_offset len BOOST_IOSTREAMS_DISABLE_IF_STREAM(T) ) { return offset_view(t, off, len); } @@ -269,7 +269,7 @@ namespace detail { template offset_indirect_device::offset_indirect_device - (param_type dev, std::streamoff off, std::streamoff len) + (param_type dev, stream_offset off, stream_offset len) : basic_adapter(dev), beg_(off), pos_(off), end_(off + len) { if (len < 0 || off < 0) @@ -300,10 +300,10 @@ inline void offset_indirect_device::write } template -std::streamoff offset_indirect_device::seek - (std::streamoff off, BOOST_IOS::seekdir way) +stream_offset offset_indirect_device::seek + (stream_offset off, BOOST_IOS::seekdir way) { - std::streamoff next; + stream_offset next; if (way == BOOST_IOS::beg) { next = beg_ + off; } else if (way == BOOST_IOS::cur) { @@ -321,7 +321,7 @@ std::streamoff offset_indirect_device::seek template offset_direct_device::offset_direct_device - (const Device& dev, std::streamoff off, std::streamoff len) + (const Device& dev, stream_offset off, stream_offset len) : basic_adapter(dev), beg_(0), end_(0) { std::pair seq = @@ -362,7 +362,7 @@ offset_direct_device::sequence(mpl::false_) template offset_filter::offset_filter - (const Filter& flt, std::streamoff off, std::streamoff len) + (const Filter& flt, stream_offset off, stream_offset len) : basic_adapter(flt), beg_(off), pos_(off), end_(off + len), open_(false) { diff --git a/include/boost/iostreams/operations.hpp b/include/boost/iostreams/operations.hpp index 56c8135..4a2d43d 100755 --- a/include/boost/iostreams/operations.hpp +++ b/include/boost/iostreams/operations.hpp @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -27,6 +29,8 @@ #include #include +#include + #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-----------------------------------// # include #else // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //--------------------------// @@ -92,12 +96,13 @@ inline void write(T& t, const typename io_char::type* s, std::streamsize n) { detail::write_impl::write(detail::unwrap(t), s, n); } template -void write(T& t, Sink& snk, const typename io_char::type* s, std::streamsize n) +void write( T& t, Sink& snk, const typename io_char::type* s, + std::streamsize n ) { detail::filter_impl::write(detail::unwrap(t), snk, s, n); } template -inline std::streamoff -seek( T& t, std::streamoff off, BOOST_IOS::seekdir way, +inline std::streampos +seek( T& t, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out ) { return detail::seek_impl::seek(detail::unwrap(t), off, way, which); } @@ -372,10 +377,19 @@ struct seek_impl struct seek_impl_basic_ios { template - static std::streamoff seek( T& t, std::streamoff off, + static std::streampos seek( T& t, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) - { return t.rdbuf()->pubseekoff(off, way, which); } + { + if ( way == BOOST_IOS::beg && + ( off < integer_traits::const_min || + off > integer_traits::const_max ) ) + { + return t.rdbuf()->pubseekpos(offset_to_position(off)); + } else { + return t.rdbuf()->pubseekoff(off, way, which); + } + } }; template<> @@ -390,28 +404,37 @@ struct seek_impl : seek_impl_basic_ios { }; template<> struct seek_impl { template - static std::streamoff seek( T& t, std::streamoff off, + static std::streampos seek( T& t, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) - { return t.pubseekoff(off, way, which); } + { + if ( way == BOOST_IOS::beg && + ( off < integer_traits::const_min || + off > integer_traits::const_max ) ) + { + return t.pubseekpos(offset_to_position(off)); + } else { + return t.pubseekoff(off, way, which); + } + } }; template<> struct seek_impl { template - static std::streamoff seek( T& t, std::streamoff off, + static std::streampos seek( T& t, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which ) - { return static_cast(t.seek(off, way, which)); } + { return t.seek(off, way, which); } }; template<> struct seek_impl { template - static std::streamoff seek( T& t, std::streamoff off, + static std::streampos seek( T& t, stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode ) - { return static_cast(t.seek(off, way)); } + { return t.seek(off, way); } }; //------------------Definition of close_impl----------------------------------// @@ -639,5 +662,7 @@ struct optimal_buffer_size_impl { } } // End namespaces iostreams, boost. +#include + #endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-------------------------// #endif // #ifndef BOOST_IOSTREAMS_OPERATIONS_HPP_INCLUDED //------------------// diff --git a/include/boost/iostreams/positioning.hpp b/include/boost/iostreams/positioning.hpp index 93a4dca..deda0b1 100755 --- a/include/boost/iostreams/positioning.hpp +++ b/include/boost/iostreams/positioning.hpp @@ -15,6 +15,7 @@ #endif #include +#include #include // mbstate_t. #include // streamoff, streampos. @@ -22,6 +23,17 @@ namespace boost { namespace iostreams { typedef boost::intmax_t stream_offset; +#include // VC7.1. + +inline std::streamoff stream_offset_to_streamoff(stream_offset off) +{ return static_cast(off); } + +#include + +template // Hande custom pos_type's. +inline stream_offset position_to_offset(PosType pos) +{ return std::streamoff(pos); } + #if ((defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)) && \ !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) \ /**/ diff --git a/include/boost/iostreams/skip.hpp b/include/boost/iostreams/skip.hpp index 41b0b69..05531dd 100755 --- a/include/boost/iostreams/skip.hpp +++ b/include/boost/iostreams/skip.hpp @@ -24,26 +24,26 @@ namespace boost { namespace iostreams { namespace detail { template -std::streamoff skip(Device& dev, std::streamoff off, mpl::true_) +stream_offset skip(Device& dev, stream_offset off, mpl::true_) { return iostreams::seek(dev, off, BOOST_IOS::cur); } template -std::streamoff skip(Device& dev, std::streamoff off, mpl::false_) +stream_offset skip(Device& dev, stream_offset off, mpl::false_) { - for (std::streamoff z = 0; z < off; ++z) + for (stream_offset z = 0; z < off; ++z) iostreams::get(dev); return off; } template -std::streamoff skip(Filter& flt, Device& dev, std::streamoff off, mpl::true_) +stream_offset skip(Filter& flt, Device& dev, stream_offset off, mpl::true_) { return flt.seek(dev, off, BOOST_IOS::cur); } template -std::streamoff skip(Filter& flt, Device& dev, std::streamoff off, mpl::false_) +stream_offset skip(Filter& flt, Device& dev, stream_offset off, mpl::false_) { char c; - for (std::streamoff z = 0; z < off; ++z) + for (stream_offset z = 0; z < off; ++z) iostreams::read(flt, dev, &c, 1); return off; } @@ -51,14 +51,14 @@ std::streamoff skip(Filter& flt, Device& dev, std::streamoff off, mpl::false_) } // End namespace detail. template -std::streamoff skip(Device& dev, std::streamoff off) +stream_offset skip(Device& dev, stream_offset off) { typedef typename io_mode::type mode; return detail::skip(dev, off, is_convertible()); } template -std::streamoff skip(Filter& flt, Device& dev, std::streamoff off) +stream_offset skip(Filter& flt, Device& dev, stream_offset off) { typedef typename io_mode::type filter_mode; typedef typename io_mode::type device_mode; diff --git a/src/file_descriptor.cpp b/src/file_descriptor.cpp index 70da9a0..de1399c 100755 --- a/src/file_descriptor.cpp +++ b/src/file_descriptor.cpp @@ -18,7 +18,7 @@ #include #include // openmodes, failure. #include -#include +#include // OS-specific headers for low-level i/o. @@ -174,8 +174,8 @@ void file_descriptor::write(const char_type* s, std::streamsize n) throw detail::bad_write(); } -boost::intmax_t file_descriptor::seek - (boost::intmax_t off, BOOST_IOS::seekdir way) +stream_offset file_descriptor::seek + (stream_offset off, BOOST_IOS::seekdir way) { using namespace std; #ifdef BOOST_IOSTREAMS_WINDOWS @@ -201,20 +201,26 @@ boost::intmax_t file_descriptor::seek dwResultLow; } } -#endif - if ( off > (numeric_limits::max)() || - off < (numeric_limits::min)() ) +#else // #ifdef BOOST_IOSTREAMS_WINDOWS +# ifndef BOOST_IOSTREAMS_HAS_LSEEK64 + if ( off > integer_traits::const_max || + off < integer_traits::const_min ) { throw BOOST_IOSTREAMS_FAILURE("bad offset"); } - std::streamoff result = - #if !defined(__BORLANDC__) - BOOST_RTL(lseek) +# endif + stream_offset result = + #ifdef BOOST_IOSTREAMS_HAS_LSEEK64 + lseek64 #else lseek #endif ( pimpl_->fd_, - static_cast(off), + #ifdef BOOST_IOSTREAMS_HAS_LSEEK64 + off, + #else + static_cast(off), + #endif way == BOOST_IOS::beg ? SEEK_SET : way == BOOST_IOS::cur ? @@ -223,6 +229,7 @@ boost::intmax_t file_descriptor::seek if (result == -1) throw detail::bad_seek(); return result; +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS } void file_descriptor::close() { close_impl(*pimpl_); } diff --git a/test/detail/filters.hpp b/test/detail/filters.hpp index 4e2acb1..511e5da 100755 --- a/test/detail/filters.hpp +++ b/test/detail/filters.hpp @@ -175,7 +175,7 @@ struct identity_seekable_filter : filter { void put(Sink& s, char c) { boost::iostreams::put(s, c); } template - std::streamoff seek(Device& d, std::streamoff off, BOOST_IOS::seekdir way) + stream_offset seek(Device& d, stream_offset off, BOOST_IOS::seekdir way) { return boost::iostreams::seek(d, off, way); } }; BOOST_IOSTREAMS_PIPABLE(identity_seekable_filter, 0) @@ -188,7 +188,7 @@ struct identity_seekable_multichar_filter : multichar_filter { void write(Sink& s, const char* buf, std::streamsize n) { boost::iostreams::write(s, buf, n); } template - std::streamoff seek(Device& d, std::streamoff off, BOOST_IOS::seekdir way) + stream_offset seek(Device& d, stream_offset off, BOOST_IOS::seekdir way) { return boost::iostreams::seek(d, off, way); } }; BOOST_IOSTREAMS_PIPABLE(identity_seekable_multichar_filter, 0) diff --git a/test/offset_test.cpp b/test/offset_test.cpp index 666178d..5e3209e 100755 --- a/test/offset_test.cpp +++ b/test/offset_test.cpp @@ -111,7 +111,7 @@ struct tolower_seekable_filter : public seekable_filter { } template - std::streamoff seek(Sink& s, std::streamoff off, BOOST_IOS::seekdir way) + stream_offset seek(Sink& s, stream_offset off, BOOST_IOS::seekdir way) { return boost::iostreams::seek(s, off, way); } @@ -122,7 +122,7 @@ void read_device() { offset_test_file src1(small_padding); test_file src2; - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); filtering_istream first(offset(file_source(src1.name(), in_mode), off, len)); ifstream second(src2.name().c_str(), in_mode); @@ -135,7 +135,7 @@ void read_device() { offset_test_file src1(large_padding); test_file src2; - streamoff off = large_padding, + stream_offset off = large_padding, len = data_reps * data_length(); filtering_istream first(offset(file_source(src1.name(), in_mode), off, len)); ifstream second(src2.name().c_str(), in_mode); @@ -152,7 +152,7 @@ void read_direct_device() test_sequence first; offset_test_sequence src(small_padding); array_source array_src(&src[0], &src[0] + src.size()); - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); filtering_istream second(offset(array_src, off, len)); BOOST_CHECK_MESSAGE( @@ -166,7 +166,7 @@ void read_filter() { offset_test_file src1(small_padding); uppercase_file src2; - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); filtering_istream first; first.push(offset(toupper_filter(), off, len)); @@ -181,7 +181,7 @@ void read_filter() { offset_test_file src1(large_padding); uppercase_file src2; - streamoff off = large_padding, + stream_offset off = large_padding, len = data_reps * data_length(); filtering_istream first; first.push(offset(toupper_filter(), off, len)); @@ -199,7 +199,7 @@ void write_device() { offset_uppercase_file dest1(small_padding); offset_test_file dest2(small_padding); - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); filtering_ostream out(offset(file(dest1.name(), BOOST_IOS::binary), off, len)); write_data_in_chunks(out); @@ -215,7 +215,7 @@ void write_device() { offset_uppercase_file dest1(large_padding); offset_test_file dest2(large_padding); - streamoff off = large_padding, + stream_offset off = large_padding, len = data_reps * data_length(); filtering_ostream out(offset(file(dest1.name(), BOOST_IOS::binary), off, len)); write_data_in_chunks(out); @@ -233,7 +233,7 @@ void write_direct_device() { vector dest1(data_reps * data_length() + 2 * small_padding, '\n'); offset_test_sequence dest2(small_padding); - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); array_sink array(&dest1[0], &dest1[0] + dest1.size()); filtering_ostream out(offset(array, off, len)); @@ -250,7 +250,7 @@ void write_filter() { offset_test_file dest1(small_padding); offset_lowercase_file dest2(small_padding); - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); filtering_ostream out; out.push(offset(tolower_seekable_filter(), off, len)); @@ -268,7 +268,7 @@ void write_filter() { offset_test_file dest1(large_padding); offset_lowercase_file dest2(large_padding); - streamoff off = large_padding, + stream_offset off = large_padding, len = data_reps * data_length(); filtering_ostream out; out.push(offset(tolower_seekable_filter(), off, len)); @@ -287,7 +287,7 @@ void write_filter() void seek_device() { offset_test_file src(small_padding); - streamoff off = large_padding, + stream_offset off = large_padding, len = data_reps * data_length(); filtering_stream io(offset(file(src.name(), BOOST_IOS::binary), off, len)); BOOST_CHECK_MESSAGE( @@ -299,7 +299,7 @@ void seek_device() void seek_direct_device() { vector src(data_reps * data_length() + 2 * small_padding, '\n'); - streamoff off = small_padding, + stream_offset off = small_padding, len = data_reps * data_length(); array ar(&src[0], &src[0] + src.size()); filtering_stream io(offset(ar, off, len)); @@ -312,7 +312,7 @@ void seek_direct_device() void seek_filter() { offset_test_file src(small_padding); - streamoff off = large_padding, + stream_offset off = large_padding, len = data_reps * data_length(); filtering_stream io; io.push(offset(identity_seekable_filter(), off, len)); diff --git a/test/positioning_test.cpp b/test/positioning_test.cpp index 2ca2a6e..f3138af 100755 --- a/test/positioning_test.cpp +++ b/test/positioning_test.cpp @@ -4,10 +4,9 @@ // See http://www.boost.org/libs/iostreams for documentation. -#include -//#include #include #include +#include #include #include @@ -18,15 +17,15 @@ using namespace boost; using namespace boost::iostreams; using boost::unit_test::test_suite; -void extrema_test_test() -{ - stream_offset minoff = numeric_limits::min(); - stream_offset maxoff = numeric_limits::max(); - - BOOST_CHECK(minoff == position_to_offset(offset_to_position(minoff))); - BOOST_CHECK(0 == position_to_offset(offset_to_position(0))); - BOOST_CHECK(maxoff == position_to_offset(offset_to_position(maxoff))); -} +//void extrema_test_test() +//{ +// stream_offset minoff = integer_traits::const_min; +// stream_offset maxoff = integer_traits::const_max; +// +// BOOST_CHECK(minoff == position_to_offset(offset_to_position(minoff))); +// BOOST_CHECK(0 == position_to_offset(offset_to_position(0))); +// BOOST_CHECK(maxoff == position_to_offset(offset_to_position(maxoff))); +//} void large_file_test() {