sl@0: // (C) Copyright Jonathan Turkanis 2003. sl@0: // Distributed under the Boost Software License, Version 1.0. (See accompanying sl@0: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) sl@0: sl@0: // See http://www.boost.org/libs/iostreams for documentation. sl@0: sl@0: // Thanks to Gareth Sylvester-Bradley for the Dinkumware versions of the sl@0: // positioning functions. sl@0: sl@0: #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED sl@0: #define BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED sl@0: sl@0: #if defined(_MSC_VER) && (_MSC_VER >= 1020) sl@0: # pragma once sl@0: #endif sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include // mbstate_t. sl@0: #include // streamoff, streampos. sl@0: sl@0: // Must come last. sl@0: #include sl@0: sl@0: #ifdef BOOST_NO_STDC_NAMESPACE sl@0: namespace std { using ::fpos_t; } sl@0: #endif sl@0: sl@0: namespace boost { namespace iostreams { sl@0: sl@0: typedef boost::intmax_t stream_offset; sl@0: sl@0: inline std::streamoff stream_offset_to_streamoff(stream_offset off) sl@0: { return static_cast(off); } sl@0: sl@0: template // Hande custom pos_type's. sl@0: inline stream_offset position_to_offset(PosType pos) sl@0: { return std::streamoff(pos); } sl@0: sl@0: #if ((defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)) && \ sl@0: !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) \ sl@0: && !defined(__QNX__) \ sl@0: /**/ sl@0: sl@0: /* Dinkumware */ sl@0: sl@0: inline std::streampos offset_to_position(stream_offset off) sl@0: { sl@0: // Use implementation-specific constructor. sl@0: return std::streampos(std::mbstate_t(), off); sl@0: } sl@0: sl@0: inline stream_offset fpos_t_to_offset(std::fpos_t pos) sl@0: { // Helper function. sl@0: #if defined(_POSIX_) || (_INTEGRAL_MAX_BITS >= 64) sl@0: return pos; sl@0: #else sl@0: return _FPOSOFF(pos); sl@0: #endif sl@0: } sl@0: sl@0: # if defined(_CPPLIB_VER) //--------------------------------------------------// sl@0: sl@0: /* Recent Dinkumware */ sl@0: sl@0: inline stream_offset position_to_offset(std::streampos pos) sl@0: { sl@0: // Use implementation-specific member function seekpos(). sl@0: return fpos_t_to_offset(pos.seekpos()) + sl@0: stream_offset(std::streamoff(pos)) - sl@0: stream_offset(std::streamoff(pos.seekpos())); sl@0: } sl@0: sl@0: # else // # if defined(_CPPLIB_VER) //----------------------------------------// sl@0: sl@0: /* Old Dinkumware */ sl@0: sl@0: inline stream_offset position_to_offset(std::streampos pos) sl@0: { sl@0: // use implementation-specific member function get_fpos_t(). sl@0: return fpos_t_to_offset(pos.get_fpos_t()) + sl@0: stream_offset(std::streamoff(pos)) - sl@0: stream_offset(std::streamoff(pos.get_fpos_t())); sl@0: } sl@0: sl@0: # endif // # if defined(_CPPLIB_VER) //---------------------------------------// sl@0: #else // Dinkumware //--------------------------------------------------------// sl@0: sl@0: /* Non-Dinkumware */ sl@0: sl@0: inline std::streampos offset_to_position(stream_offset off) { return off; } sl@0: sl@0: inline stream_offset position_to_offset(std::streampos pos) { return pos; } sl@0: sl@0: #endif // Dinkumware //-------------------------------------------------------// sl@0: sl@0: } } // End namespaces iostreams, boost. sl@0: sl@0: #include sl@0: sl@0: #endif // #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED