| 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> |
|---|
| 26 | associative_property_map<UniquePairAssociativeContainer> |
|---|
| 27 | </PRE> |
|---|
| 28 | |
|---|
| 29 | <P> |
|---|
| 30 | This property map is an adaptor that converts any type that is a model |
|---|
| 31 | of both <a |
|---|
| 32 | href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair |
|---|
| 33 | Associative Container</a> and <a |
|---|
| 34 | href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique |
|---|
| 35 | Associative Container</a> such as <a |
|---|
| 36 | href="http://www.sgi.com/tech/stl/Map.html"><tt>std::map</tt></a> into |
|---|
| 37 | a mutable <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>. |
|---|
| 38 | Note that the adaptor only retains a reference to the container, so |
|---|
| 39 | the 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 <iostream> |
|---|
| 46 | #include <map> |
|---|
| 47 | #include <string> |
|---|
| 48 | #include <boost/property_map.hpp> |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | template <typename AddressMap> |
|---|
| 52 | void foo(AddressMap address) |
|---|
| 53 | { |
|---|
| 54 | typedef typename boost::property_traits<AddressMap>::value_type value_type; |
|---|
| 55 | typedef typename boost::property_traits<AddressMap>::key_type key_type; |
|---|
| 56 | |
|---|
| 57 | value_type old_address, new_address; |
|---|
| 58 | key_type fred = "Fred"; |
|---|
| 59 | old_address = get(address, fred); |
|---|
| 60 | new_address = "384 Fitzpatrick Street"; |
|---|
| 61 | put(address, fred, new_address); |
|---|
| 62 | |
|---|
| 63 | key_type joe = "Joe"; |
|---|
| 64 | value_type& joes_address = address[joe]; |
|---|
| 65 | joes_address = "325 Cushing Avenue"; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | int |
|---|
| 69 | main() |
|---|
| 70 | { |
|---|
| 71 | std::map<std::string, std::string> name2address; |
|---|
| 72 | boost::associative_property_map< std::map<std::string, std::string> > |
|---|
| 73 | address_map(name2address); |
|---|
| 74 | |
|---|
| 75 | name2address.insert(make_pair(std::string("Fred"), |
|---|
| 76 | std::string("710 West 13th Street"))); |
|---|
| 77 | name2address.insert(make_pair(std::string("Joe"), |
|---|
| 78 | std::string("710 West 13th Street"))); |
|---|
| 79 | |
|---|
| 80 | foo(address_map); |
|---|
| 81 | |
|---|
| 82 | for (std::map<std::string, std::string>::iterator i = name2address.begin(); |
|---|
| 83 | i != name2address.end(); ++i) |
|---|
| 84 | std::cout << i->first << ": " << i->second << "\n"; |
|---|
| 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 |
|---|
| 114 | href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair |
|---|
| 115 | Associative Container</a> and <a |
|---|
| 116 | href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique |
|---|
| 117 | Associative Container</a> .</TD> |
|---|
| 118 | <TD> </td> |
|---|
| 119 | </tr> |
|---|
| 120 | |
|---|
| 121 | </TABLE> |
|---|
| 122 | <P> |
|---|
| 123 | |
|---|
| 124 | <H3>Members</H3> |
|---|
| 125 | |
|---|
| 126 | <P> |
|---|
| 127 | In addition to the methods and functions required by <a |
|---|
| 128 | href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this |
|---|
| 129 | class has the following members. |
|---|
| 130 | |
|---|
| 131 | <hr> |
|---|
| 132 | |
|---|
| 133 | <pre> |
|---|
| 134 | property_traits<associative_property_map>::value_type |
|---|
| 135 | </pre> |
|---|
| 136 | This is the same type as |
|---|
| 137 | <TT>UniquePairAssociativeContainer::data_type</TT>. |
|---|
| 138 | |
|---|
| 139 | <hr> |
|---|
| 140 | |
|---|
| 141 | <pre> |
|---|
| 142 | associative_property_map() |
|---|
| 143 | </pre> |
|---|
| 144 | Default Constructor. |
|---|
| 145 | |
|---|
| 146 | <pre> |
|---|
| 147 | associative_property_map(UniquePairAssociativeContainer& c) |
|---|
| 148 | </pre> |
|---|
| 149 | Constructor. |
|---|
| 150 | |
|---|
| 151 | <hr> |
|---|
| 152 | |
|---|
| 153 | <pre> |
|---|
| 154 | data_type& operator[](const key_type& k) const |
|---|
| 155 | </pre> |
|---|
| 156 | The operator bracket for property access. |
|---|
| 157 | The <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 <typename UniquePairAssociativeContainer> |
|---|
| 169 | associative_property_map<UniquePairAssociativeContainer> |
|---|
| 170 | make_assoc_property_map(UniquePairAssociativeContainer& c); |
|---|
| 171 | </pre> |
|---|
| 172 | A 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 © 2002</TD><TD> |
|---|
| 184 | <a HREF="../../people/jeremy_siek.htm">Jeremy Siek</a>, |
|---|
| 185 | Indiana University (<A |
|---|
| 186 | HREF="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>, |
|---|
| 189 | Indiana University (<A |
|---|
| 190 | HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>) |
|---|
| 191 | </TD></TR></TABLE> |
|---|
| 192 | |
|---|
| 193 | </BODY> |
|---|
| 194 | </HTML> |
|---|