]> git.lyx.org Git - lyx.git/blob - boost/boost/iostreams/positioning.hpp
Update in-source boost to latest updates from boost 1.34 branch.
[lyx.git] / boost / boost / iostreams / positioning.hpp
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/config.hpp>
18 #include <boost/cstdint.hpp>
19 #include <boost/integer_traits.hpp>
20 #include <boost/iostreams/detail/config/codecvt.hpp> // mbstate_t.
21 #include <boost/iostreams/detail/ios.hpp> // streamoff, streampos.
22
23 // Must come last.
24 #include <boost/iostreams/detail/config/disable_warnings.hpp> 
25
26 #ifdef BOOST_NO_STDC_NAMESPACE
27 namespace std { using ::fpos_t; }
28 #endif
29
30 namespace boost { namespace iostreams {
31
32 typedef boost::intmax_t stream_offset;
33
34 inline std::streamoff stream_offset_to_streamoff(stream_offset off)
35 { return static_cast<stream_offset>(off); }
36
37 template<typename PosType> // Hande custom pos_type's.
38 inline stream_offset position_to_offset(PosType pos)
39 { return std::streamoff(pos); }
40
41 #if ((defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)) && \
42      !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) \
43      && !defined(__QNX__) \
44    /**/
45
46         /* Dinkumware */
47
48 inline std::streampos offset_to_position(stream_offset off)
49 {
50     // Use implementation-specific constructor.
51     return std::streampos(std::mbstate_t(), off);
52 }
53
54 inline stream_offset fpos_t_to_offset(std::fpos_t pos)
55 { // Helper function.
56 #if defined(_POSIX_) || (_INTEGRAL_MAX_BITS >= 64)
57     return pos;
58 #else
59     return _FPOSOFF(pos);
60 #endif
61 }
62
63 # if defined(_CPPLIB_VER) //--------------------------------------------------//
64
65         /* Recent Dinkumware */
66
67 inline stream_offset position_to_offset(std::streampos pos)
68 {
69     // Use implementation-specific member function seekpos().
70     return fpos_t_to_offset(pos.seekpos()) +
71            stream_offset(std::streamoff(pos)) -
72            stream_offset(std::streamoff(pos.seekpos()));
73 }
74
75 # else // # if defined(_CPPLIB_VER) //----------------------------------------//
76
77         /* Old Dinkumware */
78
79 inline stream_offset position_to_offset(std::streampos pos)
80 {
81     // use implementation-specific member function get_fpos_t().
82     return fpos_t_to_offset(pos.get_fpos_t()) +
83            stream_offset(std::streamoff(pos)) -
84            stream_offset(std::streamoff(pos.get_fpos_t()));
85 }
86
87 # endif // # if defined(_CPPLIB_VER) //---------------------------------------//
88 #else // Dinkumware //--------------------------------------------------------//
89
90         /* Non-Dinkumware */
91
92 inline std::streampos offset_to_position(stream_offset off) { return off; }
93
94 inline stream_offset position_to_offset(std::streampos pos) { return pos; }
95
96 #endif // Dinkumware //-------------------------------------------------------//
97
98 } } // End namespaces iostreams, boost.
99
100 #include <boost/iostreams/detail/config/enable_warnings.hpp> 
101
102 #endif // #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED