vector_property_map.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 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>Vector Property Map</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H2><A NAME="sec:vector-property-map"></A>
  16. </h2>
  17. <PRE>
  18. template&lt;typename T, typename IndexMap = identity_property_map&gt;
  19. class vector_property_map;
  20. </PRE>
  21. <P>
  22. This property map is used to efficiently store properties for a variable
  23. number of elements. It's somewhere between <a
  24. href="associative_property_map.html">associative_property_map</a> and
  25. <a href="iterator_property_map.html">iterator_property_map</a>. The latter
  26. is very fast, but requires that the number of stored elements is known
  27. when creating property map. The former does not have this requirement, but
  28. is slower, and requires stored elements to be comparable.
  29. <p>
  30. The <tt>vector_property_map</tt> uses mapping from key to indices,
  31. and allows to add new elements. It accomplishes this by storing values
  32. in a vector, which is resized on demand.
  33. <p>
  34. Note that <tt>vector_property_map</tt> does not provide reference/pointer
  35. stability for stored values.
  36. <h3>Example</h3>
  37. <a href="../example/example3.cpp">example3.cpp</a>:
  38. <p>
  39. <pre>
  40. #include &lt;boost/property_map/vector_property_map.hpp&gt;
  41. #include &lt;string&gt;
  42. #include &lt;iostream&gt;
  43. int main()
  44. {
  45. boost::vector_property_map&lt;std::string&gt; m;
  46. // Assign string to '4'.
  47. m[4] = &quot;e&quot;;
  48. std::cout &lt;&lt; &quot;'&quot; &lt;&lt; m[4] &lt;&lt; &quot;'\n&quot;;
  49. // Grab string from '10'. Since none is associated,
  50. // &quot;&quot; will be returned.
  51. std::cout &lt;&lt; &quot;'&quot; &lt;&lt; m[10] &lt;&lt; &quot;'\n&quot;;
  52. }
  53. </pre>
  54. <H3>Where Defined</H3>
  55. <P>
  56. <a href="../../../boost/property_map/vector_property_map.hpp"><TT>boost/property_map/vector_property_map.hpp</TT></a>
  57. <p>
  58. <H3>Model Of</H3>
  59. <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>
  60. <P>
  61. <H3>Template Parameters</H3>
  62. <P>
  63. <TABLE border>
  64. <TR>
  65. <th>Parameter</th><th>Description</th><th>Default</th>
  66. </tr>
  67. <TR>
  68. <TD><TT>T</TT></TD>
  69. <TD>The type of property value. Must be both <a
  70. href="http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>
  71. and <a
  72. href="http://www.sgi.com/tech/stl/DefaultConstructible.html">DefaultConstructible</a>.
  73. </TD>
  74. <TD>&nbsp;</td>
  75. </tr>
  76. <TR>
  77. <TD><TT>IndexMap</TT></TD> <TD>Must be a model of <a
  78. href="./ReadablePropertyMap.html">Readable Property Map</a>
  79. and the value type must be convertible to
  80. <tt>std::vector&lt;T&gt;::size_type</tt>.</TD>
  81. <TD><a href="identity_property_map.html">identity_property_map</a></TD>
  82. </TR>
  83. </TABLE>
  84. <P>
  85. <H3>Members</H3>
  86. <P>
  87. In addition to the methods and functions required by <a
  88. href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
  89. class has the following members.
  90. <hr>
  91. <pre>
  92. vector_property_map(const IndexMap& index = IndexMap())
  93. </pre>
  94. Constructor which takes an index map.
  95. <hr>
  96. <pre>
  97. vector_property_map(unsigned initial_size, const IndexMap& index = IndexMap())
  98. </pre>
  99. This constructor version allows to specify maximum index of element
  100. that will be stored. Correct number will improve performance, but semantic
  101. is always the same.
  102. <hr>
  103. <pre>
  104. vector_property_map(const vector_property_map&amp;)
  105. </pre>
  106. Copy constructor. The copy will share the same data and changes
  107. made to it will affect original property map.
  108. <hr>
  109. <pre>
  110. vector_property_map&amp; operator=(const vector_property_map&amp;)
  111. </pre>
  112. Assignment operator. The semantic is the same as for copy constructor.
  113. <hr>
  114. <pre>
  115. reference operator[](const key_type&amp; v) const
  116. </pre>
  117. The operator bracket for property access.
  118. <hr>
  119. <pre>
  120. std::vector&lt;T&gt;::iterator storage_begin()
  121. std::vector&lt;T&gt;::iterator storage_end()
  122. std::vector&lt;T&gt;::const_iterator storage_begin()
  123. std::vector&lt;T&gt;::const_iterator storage_end()
  124. </pre>
  125. <p>This group of methods gives access to begin and end iterators of the
  126. underlying vector.</p>
  127. <p><b>Rationale:</b> The methods are handy, for example, when it's needed to
  128. specify a single value for all elements in a freshly created property map. The
  129. methods are not called simply &quot;begin&quot; and &quot;end&quot; since
  130. conceptually, <tt>vector_property_map</tt> is unbounded map, and has no end
  131. iterator. The direct access to the underlying method is not provided, since
  132. it would decrease encapsulation and make future performance tuning dangerous.
  133. <p><b>Acknolegements:</b> Matthias Troyer suggested adding those functions.
  134. <hr>
  135. <pre>
  136. void reserve(unsigned size)
  137. </pre>
  138. Reserve the space for storing elements with maximum index of 'size'. Unless
  139. element with greater index is accesses, all accesses will be take O(1) time.
  140. <hr>
  141. <h3>Non-Member functions</h3>
  142. <hr>
  143. <pre>
  144. template<typename T, typename IndexMap>
  145. vector_property_map<T, IndexMap>
  146. make_vector_property_map(IndexMap index)
  147. {
  148. return vector_property_map<T, IndexMap>(index);
  149. }
  150. </pre>
  151. A function for conveniently creating a vector property map.
  152. <br>
  153. <HR>
  154. <TABLE>
  155. <TR valign=top>
  156. <TD nowrap>Copyright &copy 2002</TD><TD>
  157. <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
  158. Indiana University (<A
  159. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  160. <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee1@osl.iu.edu">llee1@osl.iu.edu</A>)<br>
  161. <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>,
  162. Indiana University (<A
  163. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  164. </TD></TR>
  165. <tr>
  166. <td nowrap>Copyright &copy; 2003</td><td>Vladimir Prus</td>
  167. </tr>
  168. </TABLE>
  169. </BODY>
  170. </HTML>