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.)
|
---|
4 |
|
---|
5 | // See http://www.boost.org/libs/iostreams for documentation.
|
---|
6 |
|
---|
7 | // Thanks to Gareth Sylvester-Bradley for the Dinkumware versions of the
|
---|
8 | // positioning functions.
|
---|
9 |
|
---|
10 | #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
|
---|
11 | #define BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
|
---|
12 |
|
---|
13 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
14 | # pragma once
|
---|
15 | #endif
|
---|
16 |
|
---|
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.
|
---|
21 |
|
---|
22 | // Must come last.
|
---|
23 | #include <boost/iostreams/detail/config/disable_warnings.hpp>
|
---|
24 |
|
---|
25 | namespace boost { namespace iostreams {
|
---|
26 |
|
---|
27 | typedef boost::intmax_t stream_offset;
|
---|
28 |
|
---|
29 | inline std::streamoff stream_offset_to_streamoff(stream_offset off)
|
---|
30 | { return static_cast<stream_offset>(off); }
|
---|
31 |
|
---|
32 | template<typename PosType> // Hande custom pos_type's.
|
---|
33 | inline stream_offset position_to_offset(PosType pos)
|
---|
34 | { return std::streamoff(pos); }
|
---|
35 |
|
---|
36 | #if ((defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)) && \
|
---|
37 | !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) \
|
---|
38 | && !defined(__QNX__) \
|
---|
39 | /**/
|
---|
40 |
|
---|
41 | /* Dinkumware */
|
---|
42 |
|
---|
43 | inline std::streampos offset_to_position(stream_offset off)
|
---|
44 | {
|
---|
45 | // Use implementation-specific constructor.
|
---|
46 | return std::streampos(std::mbstate_t(), off);
|
---|
47 | }
|
---|
48 |
|
---|
49 | inline stream_offset fpos_t_to_offset(fpos_t pos)
|
---|
50 | { // Helper function.
|
---|
51 | #if defined(_POSIX_) || (_INTEGRAL_MAX_BITS >= 64)
|
---|
52 | return pos;
|
---|
53 | #else
|
---|
54 | return _FPOSOFF(pos);
|
---|
55 | #endif
|
---|
56 | }
|
---|
57 |
|
---|
58 | # if defined(_CPPLIB_VER) //--------------------------------------------------//
|
---|
59 |
|
---|
60 | /* Recent Dinkumware */
|
---|
61 |
|
---|
62 | inline stream_offset position_to_offset(std::streampos pos)
|
---|
63 | {
|
---|
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()));
|
---|
68 | }
|
---|
69 |
|
---|
70 | # else // # if defined(_CPPLIB_VER) //----------------------------------------//
|
---|
71 |
|
---|
72 | /* Old Dinkumware */
|
---|
73 |
|
---|
74 | inline stream_offset position_to_offset(std::streampos pos)
|
---|
75 | {
|
---|
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()));
|
---|
80 | }
|
---|
81 |
|
---|
82 | # endif // # if defined(_CPPLIB_VER) //---------------------------------------//
|
---|
83 | #else // Dinkumware //--------------------------------------------------------//
|
---|
84 |
|
---|
85 | /* Non-Dinkumware */
|
---|
86 |
|
---|
87 | inline std::streampos offset_to_position(stream_offset off) { return off; }
|
---|
88 |
|
---|
89 | inline stream_offset position_to_offset(std::streampos pos) { return pos; }
|
---|
90 |
|
---|
91 | #endif // Dinkumware //-------------------------------------------------------//
|
---|
92 |
|
---|
93 | } } // End namespaces iostreams, boost.
|
---|
94 |
|
---|
95 | #include <boost/iostreams/detail/config/enable_warnings.hpp>
|
---|
96 |
|
---|
97 | #endif // #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
|
---|