Buffer.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek 2000
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Buffer</Title>
  10. </HEAD>
  11. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  12. ALINK="#ff0000">
  13. <IMG SRC="../../../boost.png"
  14. ALT="C++ Boost" width="277" height="86">
  15. <BR Clear>
  16. <h3>Buffer Concept</h3>
  17. A Buffer is something in which items can be put and removed.
  18. The Buffer <i>concept</i> has very few requirements. It does
  19. not require any particular ordering of how the items are stored or in
  20. what order they will appear when removed, however, there is typically
  21. some sort of ordering policy.
  22. <h3>Notation</h3>
  23. <table>
  24. <tr> <td> <tt>B</tt> </td> <td> is a type that models Buffer. </td></tr>
  25. <tr> <td> <tt>T</tt> </td> <td> is the value type of <tt>B</tt>. </td></tr>
  26. <tr> <td> <tt>t</tt> </td> <td> is an object of type <tt>T</tt>. </td></tr>
  27. </table>
  28. <h3>Members</h3>
  29. For a type to model the Buffer concept it must have the following members.
  30. <p>
  31. <table border="1">
  32. <tr> <td><b>Member</b></td> <td><b>Description</b></td> </tr>
  33. <tr> <td> <tt>value_type</tt> </td>
  34. <td> The type of object stored in the Buffer. The value type
  35. must be <A href="http://www.boost.org/sgi/stl/Assignable.html">Assignable</a>.</td>
  36. </tr>
  37. <tr> <td> <tt>size_type</tt> </td>
  38. <td> An unsigned integral type for representing the number of
  39. objects in the Buffer.</td>
  40. </tr>
  41. <tr> <td> <tt>void push(const T& t)</tt> </td>
  42. <td> Inserts <tt>t</tt> into the Buffer. <tt>size()</tt> will be
  43. incremented by one.</td>
  44. </tr>
  45. <tr> <td> <tt>void pop()</tt> </td>
  46. <td> Removes an object from the Buffer. <tt>size()</tt> will be
  47. decremented by one. Precondition: <tt>empty()</tt>
  48. is <tt>false</tt>. </td>
  49. </tr>
  50. <tr> <td> <tt>T& top()</tt> </td>
  51. <td> Returns a mutable reference to some object in the Buffer.
  52. Precondition: <tt>empty()</tt> is <tt>false</tt>.</td>
  53. </tr>
  54. <tr> <td> <tt>const T& top() const</tt> </td>
  55. <td> Returns a const reference to some object in the Buffer.
  56. Precondition: <tt>empty()</tt> is <tt>false</tt>.</td>
  57. </tr>
  58. <tr> <td> <tt>size_type size() const</tt> </td>
  59. <td> Returns the number of objects in the Buffer.
  60. Invariant: <tt>size() >= 0</tt>. </td>
  61. </tr>
  62. <tr> <td> <tt>bool empty() const</tt> </td>
  63. <td> Equivalent to <tt>b.size() == 0</tt>.</td>
  64. </tr>
  65. </table>
  66. <h3>Complexity Guarantees</h3>
  67. <UL>
  68. <LI> <tt>push()</tt>, <tt>pop()</tt>, and <tt>size()</tt> must be at
  69. most linear time complexity in the size of the Generalized Queue.
  70. <LI> <tt>top()</tt> and <tt>empty()</tt> must be amortized constant time.
  71. </UL>
  72. <h3>Models</h3>
  73. <UL>
  74. <LI><a href="http://www.boost.org/sgi/stl/stack.html"><tt>std::stack</tt></a>
  75. <LI><a href="../../../boost/pending/mutable_queue.hpp"><tt>boost::mutable_queue</tt></a>
  76. </UL>
  77. <p>
  78. <br>
  79. <HR>
  80. <TABLE>
  81. <TR valign=top>
  82. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  83. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>, Indiana University and C++ Library & Compiler Group/SGI (<A HREF="mailto:jsiek@engr.sgi.com">jsiek@engr.sgi.com</A>)
  84. </TD></TR></TABLE>
  85. </BODY>
  86. </HTML>