iterator_property_map.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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>Iterator Property Map Adaptor</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:iterator-property-map"></A>
  16. </h2>
  17. <PRE>
  18. iterator_property_map&lt;<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>, OffsetMap, T, R&gt;
  19. </PRE>
  20. <P>
  21. This property map is an adaptor that converts any random access
  22. iterator into a <a
  23. href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
  24. The <tt>OffsetMap</tt> type is responsible for converting
  25. key objects to integers that can be used as offsets with the
  26. random access iterator.
  27. <P>
  28. <h3>Example</h3>
  29. <pre>
  30. // print out the capacity and flow for all the edges in the graph
  31. template &lt;class Graph, class CapacityPMap, class FlowPMap&gt;
  32. void print_network(Graph&amp; G, CapacityPMap capacity, FlowPMap flow)
  33. {
  34. typedef typename boost::graph_traits&lt;Graph&gt;::vertex_iterator Viter;
  35. typedef typename boost::graph_traits&lt;Graph&gt;::out_edge_iterator OutEdgeIter;
  36. typedef typename boost::graph_traits&lt;Graph&gt;::in_edge_iterator InEdgeIter;
  37. Viter ui, uiend;
  38. for (boost::tie(ui, uiend) = vertices(G); ui != uiend; ++ui) {
  39. OutEdgeIter out, out_end;
  40. std::cout &lt;&lt; *ui &lt;&lt; &quot;\t&quot;;
  41. for(boost::tie(out, out_end) = out_edges(*ui, G); out != out_end; ++out)
  42. std::cout &lt;&lt; &quot;--(&quot; &lt;&lt; get(capacity, *out) &lt;&lt; &quot;, &quot;
  43. &lt;&lt; get(flow, *out) &lt;&lt; &quot;)--&gt; &quot; &lt;&lt; target(*out,G) &lt;&lt; &quot;\t&quot;;
  44. std::cout &lt;&lt; std::endl &lt;&lt; &quot;\t&quot;;
  45. InEdgeIter in, in_end;
  46. for(boost::tie(in, in_end) = in_edges(*ui, G); in != in_end; ++in)
  47. std::cout &lt;&lt; &quot;&lt;--(&quot; &lt;&lt; get(capacity, *in) &lt;&lt; &quot;,&quot; &lt;&lt; get(flow, *in) &lt;&lt; &quot;)-- &quot;
  48. &lt;&lt; source(*in,G) &lt;&lt; &quot;\t&quot;;
  49. std::cout &lt;&lt; std::endl;
  50. }
  51. }
  52. int main(int, char*[])
  53. {
  54. typedef boost::adjacency_list&lt;boost::vecS, boost::vecS,
  55. boost::bidirectionalS, boost::no_plugin,
  56. boost::plugin&lt;boost::id_tag, std::size_t&gt; &gt; Graph;
  57. const int num_vertices = 9;
  58. Graph G(num_vertices);
  59. int capacity[] = { 10, 20, 20, 20, 40, 40, 20, 20, 20, 10 };
  60. int flow[] = { 8, 12, 12, 12, 12, 12, 16, 16, 16, 8 };
  61. // add edges to the graph, and assign each edge an ID number
  62. // to index into the property arrays
  63. add_edge(G, 0, 1, 0);
  64. // ...
  65. typedef boost::graph_traits&lt;Graph&gt;::edge_descriptor Edge;
  66. typedef boost::property_map&lt;Graph, boost::id_tag&gt;::type EdgeID_PMap;
  67. EdgeID_PMap edge_id = get(boost::edge_index(), G);
  68. boost::iterator_property_map&lt;int*, EdgeID_PMap, int, int&amp;&gt;
  69. capacity_pa(capacity, edge_id),
  70. flow_pa(flow, edge_id);
  71. print_network(G, capacity_pa, flow_pa);
  72. return 0;
  73. }
  74. </pre>
  75. <H3>Where Defined</H3>
  76. <P>
  77. <a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a>
  78. <p>
  79. <H3>Model Of</H3>
  80. <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>
  81. <P>
  82. <H3>Template Parameters</H3>
  83. <P>
  84. <TABLE border>
  85. <TR>
  86. <th>Parameter</th><th>Description</th><th>Default</th>
  87. </tr>
  88. <TR>
  89. <TD><TT>Iterator</TT></TD>
  90. <TD>Must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>.</TD>
  91. <TD>&nbsp;</td>
  92. </tr>
  93. <TR>
  94. <TD><TT>OffsetMap</TT></TD> <TD>Must be a model of <a
  95. href="./ReadablePropertyMap.html">Readable Property Map</a>
  96. and the value type must be convertible to the difference type of the
  97. iterator.</TD> <TD>&nbsp;</TD>
  98. </TR>
  99. <TR>
  100. <TD><TT>T</TT></TD>
  101. <TD>The value type of the iterator.</TD>
  102. <TD><TT>std::iterator_traits&lt;RandomAccessIterator&gt;::value_type</TT></TD>
  103. </TR>
  104. <TR>
  105. <TD><TT>R</TT></TD>
  106. <TD>The reference type of the iterator.</TD>
  107. <TD><TT>std::iterator_traits&lt;RandomAccessIterator&gt;::reference</TT></TD>
  108. </TR>
  109. </TABLE>
  110. <P>
  111. <H3>Members</H3>
  112. <P>
  113. In addition to the methods and functions required by <a
  114. href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
  115. class has the following members.
  116. <hr>
  117. <pre>
  118. property_traits&lt;iterator_property_map&gt;::value_type
  119. </pre>
  120. This is the same type as
  121. <TT>std::iterator_traits&lt;Iterator&gt;::value_type</TT>.
  122. <hr>
  123. <pre>
  124. iterator_property_map(Iterator i)
  125. </pre>
  126. Constructor. The OffsetMap is default constructed.
  127. <hr>
  128. <pre>
  129. iterator_property_map(Iterator i, OffsetMap m)
  130. </pre>
  131. Constructor.
  132. <hr>
  133. <pre>
  134. reference operator[](const key_type&amp; v) const
  135. </pre>
  136. The operator bracket for property access. The <TT>reference</TT> is from
  137. <TT>std::iterator_traits&lt;Iterator&gt;</TT> and the <tt>key_type</tt> is from <tt>boost::property_traits&lt;OffsetMap&gt;</tt>.
  138. <hr>
  139. <h3>Non-Member functions</h3>
  140. <hr>
  141. <pre>
  142. template &lt;class RAIter, class OffsetMap&gt;
  143. iterator_property_map&lt;RAIter, OffsetMap,
  144. typename std::iterator_traits&lt;RAIter&gt;::value_type,
  145. typename std::iterator_traits&lt;RAIter&gt;::reference
  146. &gt;
  147. make_iterator_property_map(RAIter iter, OffsetMap omap)
  148. </pre>
  149. A function for conveniently creating an iterator map.
  150. <hr>
  151. <pre>
  152. template &lt;class RAIter, class OffsetMap, class ValueType&gt;
  153. iterator_property_map&lt;RAIter, OffsetMap,
  154. typename std::iterator_traits&lt;RAIter&gt;::value_type,
  155. typename std::iterator_traits&lt;RAIter&gt;::reference
  156. &gt;
  157. make_iterator_property_map(RAIter iter, OffsetMap omap, ValueType dummy_arg)
  158. </pre>
  159. Use this function instead of the 2-argument version if
  160. your compiler does not support partial specialization
  161. (like Visual C++).
  162. <hr>
  163. <br>
  164. <HR>
  165. <TABLE>
  166. <TR valign=top>
  167. <TD nowrap>Copyright &copy 2000-2002</TD><TD>
  168. <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
  169. Univ.of Notre Dame (<A
  170. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  171. <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Univ.of Notre Dame (<A HREF="mailto:llee1@osl.iu.edu">llee1@osl.iu.edu</A>)<br>
  172. <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>,
  173. Univ.of Notre Dame (<A
  174. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  175. </TD></TR></TABLE>
  176. </BODY>
  177. </HTML>