Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/property_map/associative_property_map.html @ 33

Last change on this file since 33 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 5.1 KB
Line 
1<HTML>
2<!--
3  -- Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
4  --
5  -- Permission to use, copy, modify, distribute and sell this software
6  -- and its documentation for any purpose is hereby granted without fee,
7  -- provided that the above copyright notice appears in all copies and
8  -- that both that copyright notice and this permission notice appear
9  -- in supporting documentation.  We make no
10  -- representations about the suitability of this software for any
11  -- purpose.  It is provided "as is" without express or implied warranty.
12  -->
13<Head>
14<Title>Iterator Property Map Adaptor</Title>
15<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
16        ALINK="#ff0000"> 
17<IMG SRC="../../boost.png" 
18     ALT="C++ Boost" width="277" height="86"> 
19
20<BR Clear>
21
22
23<H2><A NAME="sec:associative-property-map"></A>
24</h2>
25<PRE>
26associative_property_map&lt;UniquePairAssociativeContainer&gt;
27</PRE>
28
29<P>
30This property map is an adaptor that converts any type that is a model
31of both <a
32href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
33Associative Container</a> and <a
34href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
35Associative Container</a> such as <a
36href="http://www.sgi.com/tech/stl/Map.html"><tt>std::map</tt></a> into
37a mutable <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
38Note that the adaptor only retains a reference to the container, so
39the lifetime of the container must encompass the use of the adaptor.
40</P>
41
42<h3>Example</h3>
43
44<a href="./example1.cpp">example1.cpp</a>:
45<pre>#include &lt;iostream&gt;
46#include &lt;map&gt;
47#include &lt;string&gt;
48#include &lt;boost/property_map.hpp&gt;
49
50
51template &lt;typename AddressMap&gt;
52void foo(AddressMap address)
53{
54  typedef typename boost::property_traits&lt;AddressMap&gt;::value_type value_type;
55  typedef typename boost::property_traits&lt;AddressMap&gt;::key_type key_type;
56
57  value_type old_address, new_address;
58  key_type fred = &quot;Fred&quot;;
59  old_address = get(address, fred);
60  new_address = &quot;384 Fitzpatrick Street&quot;;
61  put(address, fred, new_address);
62
63  key_type joe = &quot;Joe&quot;;
64  value_type&amp; joes_address = address[joe];
65  joes_address = &quot;325 Cushing Avenue&quot;;
66}
67
68int
69main()
70{
71  std::map&lt;std::string, std::string&gt; name2address;
72  boost::associative_property_map&lt; std::map&lt;std::string, std::string&gt; &gt;
73    address_map(name2address);
74
75  name2address.insert(make_pair(std::string(&quot;Fred&quot;),
76                                std::string(&quot;710 West 13th Street&quot;)));
77  name2address.insert(make_pair(std::string(&quot;Joe&quot;),
78                                std::string(&quot;710 West 13th Street&quot;)));
79
80  foo(address_map);
81 
82  for (std::map&lt;std::string, std::string&gt;::iterator i = name2address.begin();
83       i != name2address.end(); ++i)
84    std::cout &lt;&lt; i-&gt;first &lt;&lt; &quot;: &quot; &lt;&lt; i-&gt;second &lt;&lt; &quot;\n&quot;;
85
86  return EXIT_SUCCESS;
87}</pre>
88
89<H3>Where Defined</H3>
90
91<P>
92<a href="../../boost/property_map.hpp"><TT>boost/property_map.hpp</TT></a>
93
94<p>
95<H3>Model Of</H3>
96
97<a href="./LvaluePropertyMap.html">Lvalue Property Map</a>
98
99<P>
100
101<H3>Template Parameters</H3>
102
103<P>
104
105<TABLE border>
106<TR>
107<th>Parameter</th><th>Description</th><th>Default</th>
108</tr>
109
110
111<TR>
112<TD><TT>UniquePairAssociativeContainer</TT></TD> 
113<TD>Must be a model of both <a
114href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
115Associative Container</a> and <a
116href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
117Associative Container</a> .</TD>
118<TD>&nbsp;</td>
119</tr>
120
121</TABLE>
122<P>
123
124<H3>Members</H3>
125
126<P>
127In addition to the methods and functions required by <a
128href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
129class has the following members.
130
131<hr>
132
133<pre>
134property_traits&lt;associative_property_map&gt;::value_type
135</pre>
136This is the same type as
137<TT>UniquePairAssociativeContainer::data_type</TT>.
138
139<hr>
140
141<pre>
142associative_property_map()
143</pre>
144Default Constructor.
145
146<pre>
147associative_property_map(UniquePairAssociativeContainer&amp; c)
148</pre>
149Constructor.
150
151<hr>
152
153<pre>
154data_type&amp; operator[](const key_type&amp; k) const
155</pre>
156The operator bracket for property access.
157The <TT>key_type</TT> and
158<TT>data_type</TT> types are from the typedefs inside of
159<TT>UniquePairAssociativeContainer</TT>.
160
161<hr>
162
163<h3>Non-Member functions</h3>
164
165<hr>
166
167<pre>
168  template &lt;typename UniquePairAssociativeContainer&gt;
169  associative_property_map&lt;UniquePairAssociativeContainer&gt;
170  make_assoc_property_map(UniquePairAssociativeContainer&amp; c);
171</pre>
172A function for conveniently creating an associative property map.
173
174
175
176<hr>
177
178
179<br>
180<HR>
181<TABLE>
182<TR valign=top>
183<TD nowrap>Copyright &copy 2002</TD><TD>
184<a HREF="../../people/jeremy_siek.htm">Jeremy Siek</a>,
185Indiana University (<A
186HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
187<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>
188<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
189Indiana University (<A
190HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
191</TD></TR></TABLE>
192
193</BODY>
194</HTML> 
Note: See TracBrowser for help on using the repository browser.