Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:54

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2003-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 // Thanks to Gareth Sylvester-Bradley for the Dinkumware versions of the
0009 // positioning functions.
0010 
0011 #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
0012 #define BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED
0013 
0014 #if defined(_MSC_VER)
0015 # pragma once
0016 #endif
0017 
0018 #include <boost/config.hpp>
0019 #include <boost/cstdint.hpp>
0020 #include <boost/integer_traits.hpp>
0021 #include <boost/iostreams/detail/config/codecvt.hpp> // mbstate_t.
0022 #include <boost/iostreams/detail/config/fpos.hpp>
0023 #include <boost/iostreams/detail/ios.hpp> // streamoff, streampos.
0024 
0025 // Must come last.
0026 #include <boost/iostreams/detail/config/disable_warnings.hpp> 
0027 
0028 #ifdef BOOST_NO_STDC_NAMESPACE
0029 namespace std { using ::fpos_t; }
0030 #endif
0031 
0032 namespace boost { namespace iostreams {
0033                     
0034 //------------------Definition of stream_offset-------------------------------//
0035 
0036 typedef boost::intmax_t stream_offset;
0037 
0038 //------------------Definition of stream_offset_to_streamoff------------------//
0039 
0040 inline std::streamoff stream_offset_to_streamoff(stream_offset off)
0041 { return static_cast<stream_offset>(off); }
0042 
0043 //------------------Definition of offset_to_position--------------------------//
0044 
0045 # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS
0046 
0047 inline std::streampos offset_to_position(stream_offset off) { return off; }
0048 
0049 # else // # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS
0050 
0051 inline std::streampos offset_to_position(stream_offset off)
0052 { return std::streampos(std::mbstate_t(), off); }
0053 
0054 # endif // # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS
0055 
0056 //------------------Definition of position_to_offset--------------------------//
0057 
0058 // Hande custom pos_type's
0059 template<typename PosType> 
0060 inline stream_offset position_to_offset(PosType pos)
0061 { return std::streamoff(pos); }
0062 
0063 # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS
0064 
0065 inline stream_offset position_to_offset(std::streampos pos) { return pos; }
0066 
0067 # else // # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS
0068 
0069 // In the Dinkumware standard library, a std::streampos consists of two stream
0070 // offsets -- _Fpos, of type std::fpos_t, and _Myoff, of type std::streamoff --
0071 // together with a conversion state. A std::streampos is converted to a 
0072 // boost::iostreams::stream_offset by extracting the two stream offsets and
0073 // summing them. The value of _Fpos can be extracted using the implementation-
0074 // defined member functions seekpos() or get_fpos_t(), depending on the 
0075 // Dinkumware version. The value of _Myoff cannot be extracted directly, but can
0076 // be calculated as the difference between the result of converting the 
0077 // std::fpos to a std::streamoff and the result of converting the member _Fpos
0078 // to a long. The latter operation is accomplished with the macro BOOST_IOSTREAMS_FPOSOFF,
0079 // which works correctly on platforms where std::fpos_t is an integral type and 
0080 // platforms where it is a struct
0081 
0082 // Converts a std::fpos_t to a stream_offset
0083 inline stream_offset fpos_t_to_offset(std::fpos_t pos)
0084 {
0085 #  if defined(_POSIX_) || (_INTEGRAL_MAX_BITS >= 64) || defined(__IBMCPP__)
0086     return pos;
0087 #  else
0088     return BOOST_IOSTREAMS_FPOSOFF(pos);
0089 #  endif
0090 }
0091 
0092 // Extracts the member _Fpos from a std::fpos
0093 inline std::fpos_t streampos_to_fpos_t(std::streampos pos)
0094 {
0095 #  if defined (_CPPLIB_VER) || defined(__IBMCPP__)
0096     return pos.seekpos();
0097 #  else
0098     return pos.get_fpos_t();
0099 #  endif
0100 }
0101 
0102 inline stream_offset position_to_offset(std::streampos pos)
0103 {
0104     return fpos_t_to_offset(streampos_to_fpos_t(pos)) +
0105         static_cast<stream_offset>(
0106             static_cast<std::streamoff>(pos) -
0107             BOOST_IOSTREAMS_FPOSOFF(streampos_to_fpos_t(pos))
0108         );
0109 }
0110 
0111 # endif // # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS 
0112 
0113 } } // End namespaces iostreams, boost.
0114 
0115 #include <boost/iostreams/detail/config/enable_warnings.hpp> 
0116 
0117 #endif // #ifndef BOOST_IOSTREAMS_POSITIONING_HPP_INCLUDED