positioning.html 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Stream Offsets</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../../boost.css">
  6. <LINK REL="stylesheet" HREF="../theme/iostreams.css">
  7. </HEAD>
  8. <BODY>
  9. <!-- Begin Banner -->
  10. <H1 CLASS="title">Stream Offsets</H1>
  11. <HR CLASS="banner">
  12. <!-- End Banner -->
  13. <DL class="page-index">
  14. <DT><A href="#overview">Overview</A></DT>
  15. <DT><A href="#acknowledgments">Acknowledgments</A>
  16. <DT><A href="#headers">Headers</A></DT>
  17. <DT><A href="#reference">Reference</A></DT>
  18. </DL>
  19. <HR>
  20. <A NAME="overview"></A>
  21. <H2>Overview</H2>
  22. <P>
  23. The header <A CLASS="header" HREF="../../../../boost/iostreams/positioning.hpp"><CODE>&lt;boost/iostreams/positioning.hpp&gt;</CODE></A> provides the definition of the integral type <CODE>boost::iostreams::stream_offset</CODE>, capable of holding arbitrary stream offsets on most platforms, together with the definition of two functions, <CODE>offset_to_position</CODE> and <CODE>position_to_offset</CODE>, for converting between <CODE>stream_offset</CODE> and <CODE>std::streampos</CODE>.
  24. </P>
  25. <P>
  26. The type <CODE>std::streampos</CODE> is required to be able to hold an arbitrary stream position, but it is not an intergral type. Although <CODE>std::streampos</CODE> is interconvertible with the integral type <CODE>std::streamoff</CODE>, the conversion from <CODE>std::streampos</CODE> to <CODE>std::streamoff</CODE> may not be faithful for large (64-bit) values. The integral type <CODE>boost::iostreams::stream_offset</CODE> is intended as a replacement for <CODE>std::streamoff</CODE>, with the implicit conversions to and from <CODE>std::streampos</CODE> being replaced by explicit conversion functions.
  27. </P>
  28. <P>
  29. The implementation of <CODE>offset_to_position</CODE> and <CODE>position_to_offset</CODE> relies on implementation defined behavior, and is guaranteed to work correctly for large values only for standard libraries which define <CODE>std::streamoff</CODE> to be 64-bit type or for which the Boost Iostreams library has been explicitly configured.
  30. </P>
  31. <A NAME="acknowledgments"></A>
  32. <H2>Acknowledgments</H2>
  33. <P>Gareth Sylvester-Bradley suggested the treatment of large stream offsets used by the Boost Iostreams library and supplied the implementation of <CODE>offset_to_position</CODE> and <CODE>position_to_offset</CODE> used with the Dinkumware standard library.</P>
  34. <A NAME="headers"></A>
  35. <H2>Headers</H2>
  36. <DL class="page-index">
  37. <DT><A CLASS="header" HREF="../../../../boost/iostreams/positioning.hpp"><CODE>&lt;boost/iostreams/positioning.hpp&gt;</CODE></A></DT>
  38. </DL>
  39. <A NAME="reference"></A>
  40. <H2>Reference</H2>
  41. <A NAME="synopsis"></A>
  42. <H4>Synopsis</H4>
  43. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  44. <SPAN CLASS='keyword'>typedef</SPAN> <A CLASS='documented' HREF='../../../integer/doc/html/boost_integer/cstdint.html' TARGET='_top'>boost::intmax_t</A> stream_offset;
  45. std::streampos <A CLASS='documented' HREF='#offset_to_position'>offset_to_position</A>(stream_offset n);
  46. stream_offset <A CLASS='documented' HREF='#position_to_offset'>position_to_offset</A>(std::streampos pos);
  47. } } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
  48. <A NAME="offset_to_position"></A>
  49. <H4>Function template <CODE>offset_to_position</CODE></H4>
  50. <PRE CLASS="broken_ie">std::streampos offset_to_position(stream_offset n);</PRE>
  51. <P>Returns a <CODE>std::streampos</CODE> representing the <CODE>n</CODE><I>th</I> position in a stream.</P>
  52. <A NAME="position_to_offset"></A>
  53. <H4>Function template <CODE>position_to_offset</CODE></H4>
  54. <PRE CLASS="broken_ie">stream_offset position_to_offset(std::streampos pos);</PRE>
  55. <P>Returns a <CODE>stream_offset</CODE> representing the same character position as <CODE>pos</CODE>, disregarding any code-conversion state.</P>
  56. <!-- Begin Footer -->
  57. <HR>
  58. <P CLASS="copyright">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>&copy; Copyright 2004-2007 <a href="https://www.boost.org/users/people/jonathan_turkanis.html" target="_top">Jonathan Turkanis</a></P>
  59. <P CLASS="copyright">
  60. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <A HREF="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)
  61. </P>
  62. <!-- End Footer -->
  63. </BODY>