]>
Commit | Line | Data |
---|---|---|
1 | <HTML> | |
2 | <!-- | |
3 | Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000 | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. | |
6 | (See accompanying file LICENSE_1_0.txt or copy at | |
7 | http://www.boost.org/LICENSE_1_0.txt) | |
8 | --> | |
9 | <Head> | |
10 | <Title>Iterator Property Map Adaptor</Title> | |
11 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" | |
12 | ALINK="#ff0000"> | |
13 | <IMG SRC="../../../boost.png" | |
14 | ALT="C++ Boost" width="277" height="86"> | |
15 | ||
16 | <BR Clear> | |
17 | ||
18 | ||
19 | <H2><A NAME="sec:iterator-property-map"></A> | |
20 | </h2> | |
21 | <PRE> | |
22 | iterator_property_map<<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>, OffsetMap, T, R> | |
23 | </PRE> | |
24 | ||
25 | <P> | |
26 | This property map is an adaptor that converts any random access | |
27 | iterator into a <a | |
28 | href="./LvaluePropertyMap.html">Lvalue Property Map</a>. | |
29 | The <tt>OffsetMap</tt> type is responsible for converting | |
30 | key objects to integers that can be used as offsets with the | |
31 | random access iterator. | |
32 | ||
33 | <P> | |
34 | ||
35 | <h3>Example</h3> | |
36 | ||
37 | <pre> | |
38 | // print out the capacity and flow for all the edges in the graph | |
39 | template <class Graph, class CapacityPMap, class FlowPMap> | |
40 | void print_network(Graph& G, CapacityPMap capacity, FlowPMap flow) | |
41 | { | |
42 | typedef typename boost::graph_traits<Graph>::vertex_iterator Viter; | |
43 | typedef typename boost::graph_traits<Graph>::out_edge_iterator OutEdgeIter; | |
44 | typedef typename boost::graph_traits<Graph>::in_edge_iterator InEdgeIter; | |
45 | ||
46 | Viter ui, uiend; | |
47 | for (boost::tie(ui, uiend) = vertices(G); ui != uiend; ++ui) { | |
48 | OutEdgeIter out, out_end; | |
49 | std::cout << *ui << "\t"; | |
50 | ||
51 | for(boost::tie(out, out_end) = out_edges(*ui, G); out != out_end; ++out) | |
52 | std::cout << "--(" << get(capacity, *out) << ", " | |
53 | << get(flow, *out) << ")--> " << target(*out,G) << "\t"; | |
54 | std::cout << std::endl << "\t"; | |
55 | ||
56 | InEdgeIter in, in_end; | |
57 | for(boost::tie(in, in_end) = in_edges(*ui, G); in != in_end; ++in) | |
58 | std::cout << "<--(" << get(capacity, *in) << "," << get(flow, *in) << ")-- " | |
59 | << source(*in,G) << "\t"; | |
60 | std::cout << std::endl; | |
61 | } | |
62 | } | |
63 | ||
64 | int main(int, char*[]) | |
65 | { | |
66 | typedef boost::adjacency_list<boost::vecS, boost::vecS, | |
67 | boost::bidirectionalS, boost::no_plugin, | |
68 | boost::plugin<boost::id_tag, std::size_t> > Graph; | |
69 | ||
70 | const int num_vertices = 9; | |
71 | Graph G(num_vertices); | |
72 | ||
73 | int capacity[] = { 10, 20, 20, 20, 40, 40, 20, 20, 20, 10 }; | |
74 | int flow[] = { 8, 12, 12, 12, 12, 12, 16, 16, 16, 8 }; | |
75 | ||
76 | // add edges to the graph, and assign each edge an ID number | |
77 | // to index into the property arrays | |
78 | add_edge(G, 0, 1, 0); | |
79 | // ... | |
80 | ||
81 | typedef boost::graph_traits<Graph>::edge_descriptor Edge; | |
82 | typedef boost::property_map<Graph, boost::id_tag>::type EdgeID_PMap; | |
83 | EdgeID_PMap edge_id = get(boost::edge_index(), G); | |
84 | ||
85 | boost::iterator_property_map<int*, EdgeID_PMap, int, int&> | |
86 | capacity_pa(capacity, edge_id), | |
87 | flow_pa(flow, edge_id); | |
88 | ||
89 | print_network(G, capacity_pa, flow_pa); | |
90 | ||
91 | return 0; | |
92 | } | |
93 | </pre> | |
94 | ||
95 | <H3>Where Defined</H3> | |
96 | ||
97 | <P> | |
98 | <a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a> | |
99 | ||
100 | <p> | |
101 | <H3>Model Of</H3> | |
102 | ||
103 | <a href="./LvaluePropertyMap.html">Lvalue Property Map</a> | |
104 | ||
105 | <P> | |
106 | ||
107 | <H3>Template Parameters</H3> | |
108 | ||
109 | <P> | |
110 | ||
111 | <TABLE border> | |
112 | <TR> | |
113 | <th>Parameter</th><th>Description</th><th>Default</th> | |
114 | </tr> | |
115 | ||
116 | ||
117 | <TR> | |
118 | <TD><TT>Iterator</TT></TD> | |
119 | <TD>Must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>.</TD> | |
120 | <TD> </td> | |
121 | </tr> | |
122 | ||
123 | <TR> | |
124 | <TD><TT>OffsetMap</TT></TD> <TD>Must be a model of <a | |
125 | href="./ReadablePropertyMap.html">Readable Property Map</a> | |
126 | and the value type must be convertible to the difference type of the | |
127 | iterator.</TD> <TD> </TD> | |
128 | </TR> | |
129 | ||
130 | <TR> | |
131 | <TD><TT>T</TT></TD> | |
132 | <TD>The value type of the iterator.</TD> | |
133 | <TD><TT>std::iterator_traits<RandomAccessIterator>::value_type</TT></TD> | |
134 | </TR> | |
135 | ||
136 | ||
137 | <TR> | |
138 | <TD><TT>R</TT></TD> | |
139 | <TD>The reference type of the iterator.</TD> | |
140 | <TD><TT>std::iterator_traits<RandomAccessIterator>::reference</TT></TD> | |
141 | </TR> | |
142 | ||
143 | </TABLE> | |
144 | <P> | |
145 | ||
146 | <H3>Members</H3> | |
147 | ||
148 | <P> | |
149 | In addition to the methods and functions required by <a | |
150 | href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this | |
151 | class has the following members. | |
152 | ||
153 | <hr> | |
154 | ||
155 | <pre> | |
156 | property_traits<iterator_property_map>::value_type | |
157 | </pre> | |
158 | This is the same type as | |
159 | <TT>std::iterator_traits<Iterator>::value_type</TT>. | |
160 | ||
161 | <hr> | |
162 | ||
163 | <pre> | |
164 | iterator_property_map(Iterator i) | |
165 | </pre> | |
166 | Constructor. The OffsetMap is default constructed. | |
167 | ||
168 | <hr> | |
169 | ||
170 | <pre> | |
171 | iterator_property_map(Iterator i, OffsetMap m) | |
172 | </pre> | |
173 | Constructor. | |
174 | ||
175 | <hr> | |
176 | ||
177 | <pre> | |
178 | reference operator[](const key_type& v) const | |
179 | </pre> | |
180 | The operator bracket for property access. The <TT>reference</TT> is from | |
181 | <TT>std::iterator_traits<Iterator></TT> and the <tt>key_type</tt> is from <tt>boost::property_traits<OffsetMap></tt>. | |
182 | <hr> | |
183 | ||
184 | <h3>Non-Member functions</h3> | |
185 | ||
186 | <hr> | |
187 | ||
188 | <pre> | |
189 | template <class RAIter, class OffsetMap> | |
190 | iterator_property_map<RAIter, OffsetMap, | |
191 | typename std::iterator_traits<RAIter>::value_type, | |
192 | typename std::iterator_traits<RAIter>::reference | |
193 | > | |
194 | make_iterator_property_map(RAIter iter, OffsetMap omap) | |
195 | </pre> | |
196 | A function for conveniently creating an iterator map. | |
197 | ||
198 | ||
199 | <hr> | |
200 | ||
201 | <pre> | |
202 | template <class RAIter, class OffsetMap, class ValueType> | |
203 | iterator_property_map<RAIter, OffsetMap, | |
204 | typename std::iterator_traits<RAIter>::value_type, | |
205 | typename std::iterator_traits<RAIter>::reference | |
206 | > | |
207 | make_iterator_property_map(RAIter iter, OffsetMap omap, ValueType dummy_arg) | |
208 | </pre> | |
209 | Use this function instead of the 2-argument version if | |
210 | your compiler does not support partial specialization | |
211 | (like Visual C++). | |
212 | ||
213 | ||
214 | <hr> | |
215 | ||
216 | ||
217 | <br> | |
218 | <HR> | |
219 | <TABLE> | |
220 | <TR valign=top> | |
221 | <TD nowrap>Copyright © 2000-2002</TD><TD> | |
222 | <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>, | |
223 | Univ.of Notre Dame (<A | |
224 | HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br> | |
225 | <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> | |
226 | <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>, | |
227 | Univ.of Notre Dame (<A | |
228 | HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>) | |
229 | </TD></TR></TABLE> | |
230 | ||
231 | </BODY> | |
232 | </HTML> |