1 // (C) Copyright Jonathan Turkanis 2003.
2 // Distributed under the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 // See http://www.boost.org/libs/iostreams for documentation.
7 // Thanks to Gareth Sylvester-Bradley for the Dinkumware versions of the
8 // positioning functions.
10 #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
11 #define BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
13 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
17 #include <boost/cstdint.hpp>
18 #include <boost/integer_traits.hpp>
19 #include <boost/iostreams/detail/config/codecvt.hpp> // mbstate_t.
20 #include <boost/iostreams/detail/ios.hpp> // streamoff, streampos.
23 #include <boost/iostreams/detail/config/disable_warnings.hpp>
25 namespace boost { namespace iostreams {
27 typedef boost::intmax_t stream_offset;
29 inline std::streamoff stream_offset_to_streamoff(stream_offset off)
30 { return static_cast<stream_offset>(off); }
32 template<typename PosType> // Hande custom pos_type's.
33 inline stream_offset position_to_offset(PosType pos)
34 { return std::streamoff(pos); }
36 #if ((defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)) && \
37 !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) \
38 && !defined(__QNX__) \
43 inline std::streampos offset_to_position(stream_offset off)
45 // Use implementation-specific constructor.
46 return std::streampos(std::mbstate_t(), off);
49 inline stream_offset fpos_t_to_offset(std::fpos_t pos)
51 #if defined(_POSIX_) || (_INTEGRAL_MAX_BITS >= 64)
58 # if defined(_CPPLIB_VER) //--------------------------------------------------//
60 /* Recent Dinkumware */
62 inline stream_offset position_to_offset(std::streampos pos)
64 // Use implementation-specific member function seekpos().
65 return fpos_t_to_offset(pos.seekpos()) +
66 stream_offset(std::streamoff(pos)) -
67 stream_offset(std::streamoff(pos.seekpos()));
70 # else // # if defined(_CPPLIB_VER) //----------------------------------------//
74 inline stream_offset position_to_offset(std::streampos pos)
76 // use implementation-specific member function get_fpos_t().
77 return fpos_t_to_offset(pos.get_fpos_t()) +
78 stream_offset(std::streamoff(pos)) -
79 stream_offset(std::streamoff(pos.get_fpos_t()));
82 # endif // # if defined(_CPPLIB_VER) //---------------------------------------//
83 #else // Dinkumware //--------------------------------------------------------//
87 inline std::streampos offset_to_position(stream_offset off) { return off; }
89 inline stream_offset position_to_offset(std::streampos pos) { return pos; }
91 #endif // Dinkumware //-------------------------------------------------------//
93 } } // End namespaces iostreams, boost.
95 #include <boost/iostreams/detail/config/enable_warnings.hpp>
97 #endif // #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED