associative_property_map.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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>Associative 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:associative-property-map"></A>
  16. </h2>
  17. <PRE>
  18. associative_property_map&lt;UniquePairAssociativeContainer&gt;
  19. </PRE>
  20. <P>
  21. This property map is an adaptor that converts any type that is a model
  22. of both <a
  23. href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
  24. Associative Container</a> and <a
  25. href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
  26. Associative Container</a> such as <a
  27. href="http://www.sgi.com/tech/stl/Map.html"><tt>std::map</tt></a> into
  28. a mutable <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
  29. Note that the adaptor only retains a reference to the container, so
  30. the lifetime of the container must encompass the use of the adaptor.
  31. </P>
  32. <h3>Example</h3>
  33. <a href="../example/example1.cpp">example1.cpp</a>:
  34. <pre>#include &lt;iostream&gt;
  35. #include &lt;map&gt;
  36. #include &lt;string&gt;
  37. #include &lt;boost/property_map/property_map.hpp&gt;
  38. template &lt;typename AddressMap&gt;
  39. void foo(AddressMap address)
  40. {
  41. typedef typename boost::property_traits&lt;AddressMap&gt;::value_type value_type;
  42. typedef typename boost::property_traits&lt;AddressMap&gt;::key_type key_type;
  43. value_type old_address, new_address;
  44. key_type fred = &quot;Fred&quot;;
  45. old_address = get(address, fred);
  46. new_address = &quot;384 Fitzpatrick Street&quot;;
  47. put(address, fred, new_address);
  48. key_type joe = &quot;Joe&quot;;
  49. value_type&amp; joes_address = address[joe];
  50. joes_address = &quot;325 Cushing Avenue&quot;;
  51. }
  52. int
  53. main()
  54. {
  55. std::map&lt;std::string, std::string&gt; name2address;
  56. boost::associative_property_map&lt; std::map&lt;std::string, std::string&gt; &gt;
  57. address_map(name2address);
  58. name2address.insert(make_pair(std::string(&quot;Fred&quot;),
  59. std::string(&quot;710 West 13th Street&quot;)));
  60. name2address.insert(make_pair(std::string(&quot;Joe&quot;),
  61. std::string(&quot;710 West 13th Street&quot;)));
  62. foo(address_map);
  63. for (std::map&lt;std::string, std::string&gt;::iterator i = name2address.begin();
  64. i != name2address.end(); ++i)
  65. std::cout &lt;&lt; i-&gt;first &lt;&lt; &quot;: &quot; &lt;&lt; i-&gt;second &lt;&lt; &quot;\n&quot;;
  66. return EXIT_SUCCESS;
  67. }</pre>
  68. <H3>Where Defined</H3>
  69. <P>
  70. <a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a>
  71. <p>
  72. <H3>Model Of</H3>
  73. <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>
  74. <P>
  75. <H3>Template Parameters</H3>
  76. <P>
  77. <TABLE border>
  78. <TR>
  79. <th>Parameter</th><th>Description</th><th>Default</th>
  80. </tr>
  81. <TR>
  82. <TD><TT>UniquePairAssociativeContainer</TT></TD>
  83. <TD>Must be a model of both <a
  84. href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
  85. Associative Container</a> and <a
  86. href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
  87. Associative Container</a> .</TD>
  88. <TD>&nbsp;</td>
  89. </tr>
  90. </TABLE>
  91. <P>
  92. <H3>Members</H3>
  93. <P>
  94. In addition to the methods and functions required by <a
  95. href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
  96. class has the following members.
  97. <hr>
  98. <pre>
  99. property_traits&lt;associative_property_map&gt;::value_type
  100. </pre>
  101. This is the same type as
  102. <TT>UniquePairAssociativeContainer::data_type</TT>.
  103. <hr>
  104. <pre>
  105. associative_property_map()
  106. </pre>
  107. Default Constructor.
  108. <pre>
  109. associative_property_map(UniquePairAssociativeContainer&amp; c)
  110. </pre>
  111. Constructor.
  112. <hr>
  113. <pre>
  114. data_type&amp; operator[](const key_type&amp; k) const
  115. </pre>
  116. The operator bracket for property access.
  117. The <TT>key_type</TT> and
  118. <TT>data_type</TT> types are from the typedefs inside of
  119. <TT>UniquePairAssociativeContainer</TT>.
  120. <hr>
  121. <h3>Non-Member functions</h3>
  122. <hr>
  123. <pre>
  124. template &lt;typename UniquePairAssociativeContainer&gt;
  125. associative_property_map&lt;UniquePairAssociativeContainer&gt;
  126. make_assoc_property_map(UniquePairAssociativeContainer&amp; c);
  127. </pre>
  128. A function for conveniently creating an associative property map.
  129. <hr>
  130. <br>
  131. <HR>
  132. <TABLE>
  133. <TR valign=top>
  134. <TD nowrap>Copyright &copy 2002</TD><TD>
  135. <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
  136. Indiana University (<A
  137. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  138. <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>
  139. <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>,
  140. Indiana University (<A
  141. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  142. </TD></TR></TABLE>
  143. </BODY>
  144. </HTML>