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: #ifndef BOOST_IOSTREAMS_SEEK_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_SEEK_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 // DEDUCED_TYPENAME, MSVC. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include // streamsize, seekdir, openmode. Chris@16: #include Chris@16: #include Chris@16: #include 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: namespace detail { Chris@16: Chris@16: template Chris@16: struct seek_device_impl; Chris@16: Chris@16: template Chris@16: struct seek_filter_impl; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template Chris@16: inline std::streampos Chris@16: seek( T& t, stream_offset off, BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out ) Chris@16: { Chris@16: using namespace detail; Chris@16: return seek_device_impl::seek(detail::unwrap(t), off, way, which); Chris@16: } Chris@16: Chris@16: template Chris@16: inline std::streampos Chris@16: seek( T& t, Device& dev, stream_offset off, BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out ) Chris@16: { Chris@16: using namespace detail; Chris@16: return seek_filter_impl::seek(detail::unwrap(t), dev, off, way, which); Chris@16: } Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: //------------------Definition of seek_device_impl----------------------------// Chris@16: Chris@16: template Chris@16: struct seek_device_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: seek_device_impl< Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: dispatch< Chris@16: T, iostream_tag, istream_tag, ostream_tag, Chris@16: streambuf_tag, two_head, any_tag Chris@16: >::type Chris@16: > Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: struct seek_impl_basic_ios { Chris@16: template Chris@16: static std::streampos seek( T& t, stream_offset off, Chris@16: BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which ) Chris@16: { Chris@16: if ( way == BOOST_IOS::beg && Chris@16: ( off < integer_traits::const_min || Chris@16: off > integer_traits::const_max ) ) Chris@16: { Chris@16: return t.rdbuf()->pubseekpos(offset_to_position(off)); Chris@16: } else { Chris@16: return t.rdbuf()->pubseekoff(off, way, which); Chris@16: } Chris@16: } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct seek_device_impl : seek_impl_basic_ios { }; Chris@16: Chris@16: template<> Chris@16: struct seek_device_impl : seek_impl_basic_ios { }; Chris@16: Chris@16: template<> Chris@16: struct seek_device_impl : seek_impl_basic_ios { }; Chris@16: Chris@16: template<> Chris@16: struct seek_device_impl { Chris@16: template Chris@16: static std::streampos seek( T& t, stream_offset off, Chris@16: BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which ) Chris@16: { Chris@16: if ( way == BOOST_IOS::beg && Chris@16: ( off < integer_traits::const_min || Chris@16: off > integer_traits::const_max ) ) Chris@16: { Chris@16: return t.BOOST_IOSTREAMS_PUBSEEKPOS(offset_to_position(off)); Chris@16: } else { Chris@16: return t.BOOST_IOSTREAMS_PUBSEEKOFF(off, way, which); Chris@16: } Chris@16: } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct seek_device_impl { Chris@16: template Chris@16: static std::streampos seek( T& t, stream_offset off, Chris@16: BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which ) Chris@16: { return t.seek(off, way, which); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct seek_device_impl { Chris@16: template Chris@16: static std::streampos seek( T& t, stream_offset off, Chris@16: BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode ) Chris@16: { return t.seek(off, way); } Chris@16: }; Chris@16: Chris@16: //------------------Definition of seek_filter_impl----------------------------// Chris@16: Chris@16: template Chris@16: struct seek_filter_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: seek_filter_impl< Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: dispatch::type Chris@16: > Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: struct seek_filter_impl { Chris@16: template Chris@16: static std::streampos seek( T& t, Device& d, Chris@16: stream_offset off, Chris@16: BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which ) Chris@16: { return t.seek(d, off, way, which); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct seek_filter_impl { Chris@16: template Chris@16: static std::streampos seek( T& t, Device& d, Chris@16: stream_offset off, Chris@16: BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode ) Chris@16: { return t.seek(d, off, way); } Chris@16: }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: } } // End namespaces iostreams, boost. Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_SEEK_HPP_INCLUDED