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
|
<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>Vector Property Map</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:vector-property-map"></A>
</h2>
<PRE>
template<typename T, typename IndexMap = identity_property_map>
class vector_property_map;
</PRE>
<P>
This property map is used to efficiently store properties for a variable
number of elements. It's somewhere between <a
href="associative_property_map.html">associative_property_map</a> and
<a href="iterator_property_map.html">iterator_property_map</a>. The latter
is very fast, but requires that the number of stored elements is known
when creating property map. The former does not have this requirement, but
is slower, and requires stored elements to be comparable.
<p>
The <tt>vector_property_map</tt> uses mapping from key to indices,
and allows to add new elements. It accoplishes this by storing values
in a vector, which is resized on demand.
<p>
Note that <tt>vector_property_map</tt> does not provide reference/pointer
stability for stored values.
<h3>Example</h3>
<a href="./example3.cpp">example3.cpp</a>:
<p>
<pre>
#include <boost/vector_property_map.hpp>
#include <string>
#include <iostream>
int main()
{
boost::vector_property_map<std::string> m;
// Assign string to '4'.
m[4] = "e";
std::cout << "'" << m[4] << "'\n";
// Grab string from '10'. Since none is associated,
// "" will be returned.
std::cout << "'" << m[10] << "'\n";
}
</pre>
<H3>Where Defined</H3>
<P>
<a href="../../boost/vector_property_map.hpp"><TT>boost/vector_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>T</TT></TD>
<TD>The type of property value. Must be both <a
href="http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>
and <a
href="http://www.sgi.com/tech/stl/DefaultConstructible.html">DefaultConstructible</a>.
</TD>
<TD> </td>
</tr>
<TR>
<TD><TT>IndexMap</TT></TD> <TD>Must be a model of <a
href="./ReadablePropertyMap.html">Readable Property Map</a>
and the value type must be convertible to
<tt>std::vector<T>::size_type</tt>.</TD>
<TD><a href="identity_property_map.html">identity_property_map</a></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>
vector_property_map(const IndexMap& index = IndexMap())
</pre>
Constructor which takes an index map.
<hr>
<pre>
vector_property_map(unsigned initial_size, const IndexMap& index = IndexMap())
</pre>
This constructor version allows to specify maximum index of element
that will be stored. Correct number will improve performance, but semantic
is always the same.
<hr>
<pre>
vector_property_map(const vector_property_map&)
</pre>
Copy constructor. The copy will share the same data and changes
made to it will affect original property map.
<hr>
<pre>
vector_property_map& operator=(const vector_property_map&)
</pre>
Assignment operator. The semantic is the same as for copy constructor.
<hr>
<pre>
reference operator[](const key_type& v) const
</pre>
The operator bracket for property access.
<hr>
<pre>
std::vector<T>::iterator storage_begin()
std::vector<T>::iterator storage_end()
std::vector<T>::const_iterator storage_begin()
std::vector<T>::const_iterator storage_end()
</pre>
<p>This group of methods gives access to begin and end iterators of the
underlying vector.</p>
<p><b>Rationale:</b> The methods are handy, for example, when it's needed to
specify a single value for all elements in a freshly created property map. The
methods are not called simply "begin" and "end" since
conceptually, <tt>vector_property_map</tt> is unbounded map, and has no end
iterator. The direct access to the underlying method is not provided, since
it would decrease encapsulation and make future performance tuning dangerous.
<p><b>Acknolegements:</b> Matthias Troyer suggested adding those functions.
<hr>
<pre>
void reserve(unsigned size)
</pre>
Reserve the space for storing elements with maximum index of 'size'. Unless
element with greater index is accesses, all accesses will be take O(1) time.
<hr>
<h3>Non-Member functions</h3>
<hr>
<pre>
template<typename T, typename IndexMap>
vector_property_map<T, IndexMap>
make_vector_property_map(IndexMap index)
{
return vector_property_map<T, IndexMap>(index);
}
</pre>
A function for conveniently creating a vector property map.
<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright © 2002</TD><TD>
<a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
Indiana University (<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>, Indiana University (<A HREF="mailto:llee1@osl.iu.edu">llee1@osl.iu.edu</A>)<br>
<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
Indiana University (<A
HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
</TD></TR>
<tr>
<td nowrap>Copyright © 2003</td><td>Vladimir Prus</td>
</tr>
</TABLE>
</BODY>
</HTML>
|