File: iterator_property_map.html

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (238 lines) | stat: -rw-r--r-- 6,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<HTML>
<!--
  -- Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
  --
  -- Permission to use, copy, modify, distribute and sell this software
  -- and its documentation for any purpose is hereby granted without fee,
  -- provided that the above copyright notice appears in all copies and
  -- that both that copyright notice and this permission notice appear
  -- in supporting documentation.  We make no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  -->
<Head>
<Title>Iterator Property Map Adaptor</Title>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
	ALINK="#ff0000"> 
<IMG SRC="../../boost.png" 
     ALT="C++ Boost" width="277" height="86"> 

<BR Clear>


<H2><A NAME="sec:iterator-property-map"></A>
</h2>
<PRE>
iterator_property_map&lt;<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>, OffsetMap, T, R&gt;
</PRE>

<P>
This property map is an adaptor that converts any random access
iterator into a <a
href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
The <tt>OffsetMap</tt> type is responsible for converting
key objects to integers that can be used as offsets with the
random access iterator.

<P>

<h3>Example</h3>

<pre>
// print out the capacity and flow for all the edges in the graph
template &lt;class Graph, class CapacityPMap, class FlowPMap&gt;
void print_network(Graph&amp; G, CapacityPMap capacity, FlowPMap flow)
{
  typedef typename boost::graph_traits&lt;Graph&gt;::vertex_iterator    Viter;
  typedef typename boost::graph_traits&lt;Graph&gt;::out_edge_iterator OutEdgeIter;
  typedef typename boost::graph_traits&lt;Graph&gt;::in_edge_iterator InEdgeIter;

  Viter ui, uiend;
  for (boost::tie(ui, uiend) = vertices(G); ui != uiend; ++ui) {
    OutEdgeIter out, out_end;
    std::cout &lt;&lt; *ui &lt;&lt; &quot;\t&quot;;

    for(boost::tie(out, out_end) = out_edges(*ui, G); out != out_end; ++out)
      std::cout &lt;&lt; &quot;--(&quot; &lt;&lt; get(capacity, *out) &lt;&lt; &quot;, &quot; 
	   &lt;&lt; get(flow, *out) &lt;&lt; &quot;)--&gt; &quot; &lt;&lt; target(*out,G) &lt;&lt; &quot;\t&quot;;
    std::cout &lt;&lt; std::endl &lt;&lt; &quot;\t&quot;;

    InEdgeIter in, in_end;    
    for(boost::tie(in, in_end) = in_edges(*ui, G); in != in_end; ++in)
      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;
           &lt;&lt; source(*in,G) &lt;&lt; &quot;\t&quot;;
    std::cout &lt;&lt; std::endl;
  }
}

int main(int, char*[])
{
  typedef boost::adjacency_list&lt;boost::vecS, boost::vecS, 
    boost::bidirectionalS, boost::no_plugin, 
    boost::plugin&lt;boost::id_tag, std::size_t&gt; &gt; Graph;

  const int num_vertices = 9;
  Graph G(num_vertices);

  int capacity[] = { 10, 20, 20, 20, 40, 40, 20, 20, 20, 10 };
  int flow[] = { 8, 12, 12, 12, 12, 12, 16, 16, 16, 8 };

  // add edges to the graph, and assign each edge an ID number
  // to index into the property arrays
  add_edge(G, 0, 1, 0);
  // ...

  typedef boost::graph_traits&lt;Graph&gt;::edge_descriptor Edge;
  typedef boost::property_map&lt;Graph, boost::id_tag&gt;::type EdgeID_PMap;
  EdgeID_PMap edge_id = get(boost::edge_index(), G);

  boost::iterator_property_map&lt;int*, EdgeID_PMap, int, int&amp;&gt;
     capacity_pa(capacity, edge_id),
     flow_pa(flow, edge_id);

  print_network(G, capacity_pa, flow_pa);
          
  return 0;
}
</pre>

<H3>Where Defined</H3>

<P>
<a href="../../boost/property_map.hpp"><TT>boost/property_map.hpp</TT></a>

<p>
<H3>Model Of</H3>

<a href="./LvaluePropertyMap.html">Lvalue Property Map</a>

<P>

<H3>Template Parameters</H3>

<P>

<TABLE border>
<TR>
<th>Parameter</th><th>Description</th><th>Default</th>
</tr>


<TR>
<TD><TT>Iterator</TT></TD> 
<TD>Must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>.</TD>
<TD>&nbsp;</td>
</tr>

<TR>
<TD><TT>OffsetMap</TT></TD> <TD>Must be a model of <a
href="./ReadablePropertyMap.html">Readable Property Map</a>
and the value type must be convertible to the difference type of the
iterator.</TD> <TD>&nbsp;</TD>
</TR>

<TR>
<TD><TT>T</TT></TD>
<TD>The value type of the iterator.</TD>
<TD><TT>std::iterator_traits&lt;RandomAccessIterator&gt;::value_type</TT></TD>
</TR>


<TR>
<TD><TT>R</TT></TD>
<TD>The reference type of the iterator.</TD>
<TD><TT>std::iterator_traits&lt;RandomAccessIterator&gt;::reference</TT></TD>
</TR>

</TABLE>
<P>

<H3>Members</H3>

<P>
In addition to the methods and functions required by <a
href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
class has the following members.

<hr>

<pre>
property_traits&lt;iterator_property_map&gt;::value_type
</pre>
This is the same type as
<TT>std::iterator_traits&lt;Iterator&gt;::value_type</TT>.

<hr>

<pre>
iterator_property_map(Iterator i)
</pre>
Constructor. The OffsetMap is default constructed.

<hr>

<pre>
iterator_property_map(Iterator i, OffsetMap m)
</pre>
Constructor.

<hr>

<pre>
reference operator[](difference_type v) const
</pre>
The operator bracket for property access. The <TT>reference</TT> and
<TT>difference_type</TT> types are from  
<TT>std::iterator_traits&lt;Iterator&gt;</TT>.

<hr>

<h3>Non-Member functions</h3>

<hr>

<pre>
  template &lt;class RAIter, class OffsetMap&gt;
  iterator_property_map&lt;RAIter, OffsetMap,
    typename std::iterator_traits&lt;RAIter&gt;::value_type,
    typename std::iterator_traits&lt;RAIter&gt;::reference
    &gt;
  make_iterator_property_map(RAIter iter, OffsetMap omap)
</pre>
A function for conveniently creating an iterator map.


<hr>

<pre>
  template &lt;class RAIter, class OffsetMap, class ValueType&gt;
  iterator_property_map&lt;RAIter, OffsetMap,
    typename std::iterator_traits&lt;RAIter&gt;::value_type,
    typename std::iterator_traits&lt;RAIter&gt;::reference
    &gt;
  make_iterator_property_map(RAIter iter, OffsetMap omap, ValueType dummy_arg)
</pre>
Use this function instead of the 2-argument version if
your compiler does not support partial specialization
(like Visual C++).


<hr>


<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright &copy 2000-2002</TD><TD>
<a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
Univ.of Notre Dame (<A
HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
<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>
<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
Univ.of Notre Dame (<A
HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
</TD></TR></TABLE>

</BODY>
</HTML>