seek.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Function Template seek</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">Function Template <CODE>seek</CODE></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="#headers">Headers</A></DT>
  16. <DT><A href="#reference">Reference</A></DT>
  17. </DL>
  18. <A NAME="overview"></A>
  19. <H2>Overview</H2>
  20. <P>
  21. The function template <CODE>seek</CODE> is used by the Iostreams library to perform random access withing a sequence controlled by a <A HREF="../concepts/device.html">Device</A>.</P>
  22. </P>
  23. <A NAME="headers"></A>
  24. <H2>Headers</H2>
  25. <DL>
  26. <DT><A CLASS="header" HREF="../../../../boost/iostreams/operations.hpp"><CODE>&lt;boost/iostreams/operations.hpp&gt;</CODE></A></DT>
  27. <DT><A CLASS="header" HREF="../../../../boost/iostreams/seek.hpp"><CODE>&lt;boost/iostreams/seek.hpp&gt;</CODE></A></DT>
  28. </DL>
  29. <A NAME="reference"></A>
  30. <H2>Reference</H2>
  31. <A NAME="description"></A>
  32. <H4>Description</H4>
  33. Repositions one or both heads within the sequence controlled by a given instance of the template parameter <CODE>T</CODE>, returning the resulting stream position.
  34. <A NAME="synopsis"></A>
  35. <H4>Synopsis</H4>
  36. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  37. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">T</A>&gt;
  38. std::streampos
  39. <A CLASS="documented" HREF="#semantics">seek</A>( T&amp;, <A CLASS="documented" HREF="positioning.html#synopsis">stream_offset</A> <A CLASS="documented" HREF="#function_params">off</A>, std::ios_base::seekdir <A CLASS="documented" HREF="#function_params">way</A>,
  40. std::ios_base::openmode <A CLASS="documented" HREF="#function_params">which</A> =
  41. std::ios_base::in | std::ios_base::out );
  42. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  43. <A NAME="template_params"></A>
  44. <H4>Template Parameters</H4>
  45. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  46. <TR>
  47. <TR>
  48. <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  49. <TD>A model of one of the <A HREF="../guide/concepts.html#device_concepts">Device</A> concepts which allows random access.
  50. </TR>
  51. </TABLE>
  52. <A NAME="function_params"></A>
  53. <H4>Function Parameters</H4>
  54. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  55. <TR>
  56. <TR>
  57. <TD VALIGN="top"><I>off</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  58. <TD>A <A HREF="positioning.html#synopsis"><CODE>stream_offset</CODE></A> indicating the number of characters by which the appropriate reading or writing heads should be advanced. The initial position is determined by the parameter <I>way</I>.
  59. </TR>
  60. <TR>
  61. <TD VALIGN="top"><I>way</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  62. <TD><P>Determines the initial position to which the offset <I>off</I> is applied, as follows:
  63. <UL>
  64. <LI CLASS="square">if <I>way</I> is <CODE>std::ios_base::beg</CODE>, the initial position is the begining of the stream
  65. <LI CLASS="square">if <I>way</I> is <CODE>std::ios_base::cur</CODE>, the initial position is the current position
  66. <LI CLASS="square">if <I>way</I> is <CODE>std::ios_base::end</CODE>, the initial position is the end of the stream
  67. </UL>
  68. </P>
  69. </TR>
  70. <TR>
  71. <TD VALIGN="top"><I>which</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  72. <TD>Determines whether the reading head, the writing head or both are repositioned.
  73. </TR>
  74. </TABLE>
  75. <A NAME="semantics"></A>
  76. <H4>Semantics</H4>
  77. <P>The semantics of <CODE>seek</CODE> depends on the <A HREF="../guide/traits.html#category">category</A> of <CODE>T</CODE> as follows:</P>
  78. <TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
  79. <TR><TH><CODE>category_of&lt;T&gt;::type</CODE></TH><TH>semantics</TH></TR>
  80. <TR>
  81. <TD VALIGN="top">convertible to <CODE>istream_tag</CODE> or <CODE>ostream_tag</CODE></TD>
  82. <TD>returns:
  83. <UL STYLE='margin-top:0'>
  84. <LI><CODE>t.rdbuf()->pubseekpos(<A HREF="positioning.html#offset_to_position">offset_to_position</A>(off))</CODE>, if <CODE>way</CODE> is <CODE>std::ios_base::beg</CODE> and <CODE>off</CODE> is outside the range of <CODE>std::streamoff</CODE>, and
  85. <LI><CODE>t.rdbuf()->pubseekoff(off, way)</CODE>, otherwise
  86. <UL>
  87. </TR>
  88. <TR>
  89. <TD VALIGN="top">convertible to <CODE>streambuf_tag</CODE></TD>
  90. <TD>returns:
  91. <UL STYLE='margin-top:0'>
  92. <LI><CODE>t.pubseekpos(<A HREF="positioning.html#offset_to_position">offset_to_position</A>(off))</CODE>, if <CODE>way</CODE> is <CODE>std::ios_base::beg</CODE> and <CODE>off</CODE> is outside the range of <CODE>std::streamoff</CODE>, and
  93. <LI><CODE>t.pubseekoff(off, way)</CODE>, otherwise
  94. <UL>
  95. </TR>
  96. <TR>
  97. <TD VALIGN="top">convertible to <CODE>input_seekable</CODE> but not to <CODE>output_seekable</CODE></TD>
  98. <TD>returns <CODE>t.seek(off, way)</CODE></TD>
  99. </TR>
  100. <TR>
  101. <TD VALIGN="top">convertible to <CODE>output_seekable</CODE> but not to <CODE>input_seekable</CODE></TD>
  102. <TD>returns <CODE>t.seek(off, way)</CODE></TD>
  103. </TR>
  104. <TR>
  105. <TD VALIGN="top">convertible to <CODE>dual_seekable</CODE> or to <CODE>bidirectional_seekable</CODE></TD>
  106. <TD>returns <CODE>t.seek(off, way, which)</CODE></TD>
  107. </TR>
  108. <TR>
  109. <TD VALIGN="top">convertible to <CODE>seekable</CODE></TD>
  110. <TD>returns <CODE>t.seek(off, way)</CODE></TD>
  111. </TR>
  112. <TR>
  113. <TD VALIGN="top"><I>otherwise</I></TD>
  114. <TD>compile-time error</TD>
  115. </TR>
  116. </TABLE>
  117. <P>In short:
  118. <UL>
  119. <LI CLASS="square">If <CODE>T</CODE> is a standard stream or stream buffer type, delegates to <CODE>std::basic_streambuf::pubseekoff</CODE> or <CODE>std::basic_streambuf::pubseekpos</CODE>, as appropriate.
  120. <LI CLASS="square">Otherwise, if the <A HREF="../guide/modes.html">mode</A> of <CODE>T</CODE> allows only one reading head, delegates to a member function <CODE>seek</CODE> which takes a <CODE>stream_offset</CODE> and a <CODE>seekdir</CODE> but no <CODE>openmode</CODE>.
  121. <LI CLASS="square">Otherwise, if the <A HREF="../guide/modes.html">mode</A> of <CODE>T</CODE> allows random access with two reading heads, delegates to a member function <CODE>seek</CODE> which takes a <CODE>stream_offset</CODE>, a <CODE>seekdir</CODE> and an <CODE>openmode</CODE>.
  122. <LI CLASS="square">If the <A HREF="../guide/modes.html">mode</A> of T does not permit random access, attempting to invoke <CODE>seek</CODE> is a compile-time error.
  123. </UL>
  124. <!-- Begin Footer -->
  125. <HR>
  126. <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>
  127. <P CLASS="copyright">
  128. 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>)
  129. </P>
  130. <!-- End Footer -->
  131. </BODY>