|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53480 - in trunk: boost/property_map libs/property_map/doc libs/property_map/test
From: jewillco_at_[hidden]
Date: 2009-05-30 23:32:09
Author: jewillco
Date: 2009-05-30 23:32:08 EDT (Sat, 30 May 2009)
New Revision: 53480
URL: http://svn.boost.org/trac/boost/changeset/53480
Log:
Added shared_array_property_map
Added:
trunk/boost/property_map/shared_array_property_map.hpp (contents, props changed)
trunk/libs/property_map/doc/shared_array_property_map.html
- copied, changed from r53477, /trunk/libs/property_map/doc/iterator_property_map.html
Text files modified:
trunk/libs/property_map/doc/property_map.html | 1
trunk/libs/property_map/doc/shared_array_property_map.html | 163 +++++++--------------------------------
trunk/libs/property_map/test/property_map_cc.cpp | 9 ++
3 files changed, 40 insertions(+), 133 deletions(-)
Added: trunk/boost/property_map/shared_array_property_map.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/property_map/shared_array_property_map.hpp 2009-05-30 23:32:08 EDT (Sat, 30 May 2009)
@@ -0,0 +1,50 @@
+// Copyright (C) 2009 Trustees of Indiana University
+// Authors: Jeremiah Willcock, Andrew Lumsdaine
+
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/property_map for documentation.
+
+#ifndef BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
+#define BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
+
+#include <boost/smart_ptr/shared_array.hpp>
+#include <boost/property_map/property_map.hpp>
+
+namespace boost {
+
+template <class T, class IndexMap>
+class shared_array_property_map
+ : public boost::put_get_helper<T&, shared_array_property_map<T, IndexMap> >
+{
+ public:
+ typedef typename property_traits<IndexMap>::key_type key_type;
+ typedef T value_type;
+ typedef T& reference;
+ typedef boost::lvalue_property_map_tag category;
+
+ explicit inline shared_array_property_map(
+ size_t n,
+ const IndexMap& _id = IndexMap())
+ : data(new T[n]), index(_id) {}
+
+ inline T& operator[](key_type v) const {
+ return data[get(index, v)];
+ }
+
+ private:
+ boost::shared_array<T> data;
+ IndexMap index;
+};
+
+template <class T, class IndexMap>
+shared_array_property_map<T, IndexMap>
+make_shared_array_property_map(size_t n, const T&, const IndexMap& index) {
+ return shared_array_property_map<T, IndexMap>(n, index);
+}
+
+} // end namespace boost
+
+#endif // BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
Modified: trunk/libs/property_map/doc/property_map.html
==============================================================================
--- trunk/libs/property_map/doc/property_map.html (original)
+++ trunk/libs/property_map/doc/property_map.html 2009-05-30 23:32:08 EDT (Sat, 30 May 2009)
@@ -283,6 +283,7 @@
</li>
<li>identity_property_map </li>
<li>iterator_property_map</li>
+ <li>shared_array_property_map</li>
<li>associative_property_map</li>
<li>const_associative_property_map</li>
<li>vector_property_map</li>
Copied: trunk/libs/property_map/doc/shared_array_property_map.html (from r53477, /trunk/libs/property_map/doc/iterator_property_map.html)
==============================================================================
--- /trunk/libs/property_map/doc/iterator_property_map.html (original)
+++ trunk/libs/property_map/doc/shared_array_property_map.html 2009-05-30 23:32:08 EDT (Sat, 30 May 2009)
@@ -1,13 +1,13 @@
<HTML>
<!--
- Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
+ Copyright (c) Trustees of Indiana University 2009
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
-->
<Head>
-<Title>Iterator Property Map Adaptor</Title>
+<Title>Shared Array Property Map</Title>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
ALINK="#ff0000">
<IMG SRC="../../../boost.png"
@@ -16,86 +16,26 @@
<BR Clear>
-<H2><A NAME="sec:iterator-property-map"></A>
+<H2><A NAME="sec:shared-array-property-map"></A>
</h2>
<PRE>
-iterator_property_map<RandomAccessIterator, OffsetMap, T, R>
+shared_array_property_map<ValueType, OffsetMap>
</PRE>
<P>
-This property map is an adaptor that converts any random access
-iterator into a <a
-href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
+This property map is an adaptor that contains a <a
+href="../../smart_ptr/shared_array.htm">boost::shared_array</a> and uses that
+array to store the property map's data. The resulting property map is a model
+of Lvalue Property Map.
The <tt>OffsetMap</tt> type is responsible for converting
-key objects to integers that can be used as offsets with the
-random access iterator.
+key objects to integers that can be used as offsets into the array.
<P>
-<h3>Example</h3>
-
-<pre>
-// print out the capacity and flow for all the edges in the graph
-template <class Graph, class CapacityPMap, class FlowPMap>
-void print_network(Graph& G, CapacityPMap capacity, FlowPMap flow)
-{
- typedef typename boost::graph_traits<Graph>::vertex_iterator Viter;
- typedef typename boost::graph_traits<Graph>::out_edge_iterator OutEdgeIter;
- typedef typename boost::graph_traits<Graph>::in_edge_iterator InEdgeIter;
-
- Viter ui, uiend;
- for (boost::tie(ui, uiend) = vertices(G); ui != uiend; ++ui) {
- OutEdgeIter out, out_end;
- std::cout << *ui << "\t";
-
- for(boost::tie(out, out_end) = out_edges(*ui, G); out != out_end; ++out)
- std::cout << "--(" << get(capacity, *out) << ", "
- << get(flow, *out) << ")--> " << target(*out,G) << "\t";
- std::cout << std::endl << "\t";
-
- InEdgeIter in, in_end;
- for(boost::tie(in, in_end) = in_edges(*ui, G); in != in_end; ++in)
- std::cout << "<--(" << get(capacity, *in) << "," << get(flow, *in) << ")-- "
- << source(*in,G) << "\t";
- std::cout << std::endl;
- }
-}
-
-int main(int, char*[])
-{
- typedef boost::adjacency_list<boost::vecS, boost::vecS,
- boost::bidirectionalS, boost::no_plugin,
- boost::plugin<boost::id_tag, std::size_t> > 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<Graph>::edge_descriptor Edge;
- typedef boost::property_map<Graph, boost::id_tag>::type EdgeID_PMap;
- EdgeID_PMap edge_id = get(boost::edge_index(), G);
-
- boost::iterator_property_map<int*, EdgeID_PMap, int, int&>
- 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>
-boost/property_map/property_map.hpp
+boost/property_map/shared_array_property_map.hpp
<p>
<H3>Model Of</H3>
@@ -115,29 +55,17 @@
<TR>
-<TD><TT>Iterator</TT></TD>
-<TD>Must be a model of Random Access Iterator.</TD>
-<TD> </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> </TD>
-</TR>
-
-<TR>
-<TD><TT>T</TT></TD>
-<TD>The value type of the iterator.</TD>
-<TD><TT>std::iterator_traits<RandomAccessIterator>::value_type</TT></TD>
+<TD><TT>ValueType</TT></TD>
+<TD>The value type of the property map.</TD>
+<TD> </TD>
</TR>
<TR>
-<TD><TT>R</TT></TD>
-<TD>The reference type of the iterator.</TD>
-<TD><TT>std::iterator_traits<RandomAccessIterator>::reference</TT></TD>
+<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 <tt>std::size_t</tt>.
+</TD> <TD> </TD>
</TR>
</TABLE>
@@ -153,34 +81,28 @@
<hr>
<pre>
-property_traits<iterator_property_map>::value_type
+property_traits<shared_array_property_map>::value_type
</pre>
This is the same type as
-<TT>std::iterator_traits<Iterator>::value_type</TT>.
+<TT>ValueType</TT>.
<hr>
<pre>
-iterator_property_map(Iterator i)
+shared_array_property_map(size_t n)
</pre>
-Constructor. The OffsetMap is default constructed.
+Constructor. Builds the property map with a size of <tt>n</tt> elements. The
+<tt>OffsetMap</tt> is default constructed.
<hr>
<pre>
-iterator_property_map(Iterator i, OffsetMap m)
+shared_array_property_map(size_t n, OffsetMap m)
</pre>
-Constructor.
+Constructor. Builds the property map with a size of <tt>n</tt> elements.
<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<Iterator></TT>.
-
<hr>
<h3>Non-Member functions</h3>
@@ -188,46 +110,21 @@
<hr>
<pre>
- template <class RAIter, class OffsetMap>
- iterator_property_map<RAIter, OffsetMap,
- typename std::iterator_traits<RAIter>::value_type,
- typename std::iterator_traits<RAIter>::reference
- >
- make_iterator_property_map(RAIter iter, OffsetMap omap)
-</pre>
-A function for conveniently creating an iterator map.
-
-
-<hr>
-
-<pre>
- template <class RAIter, class OffsetMap, class ValueType>
- iterator_property_map<RAIter, OffsetMap,
- typename std::iterator_traits<RAIter>::value_type,
- typename std::iterator_traits<RAIter>::reference
- >
- make_iterator_property_map(RAIter iter, OffsetMap omap, ValueType dummy_arg)
+ template <class ValueType, class OffsetMap>
+ shared_array_property_map<ValueType, OffsetMap>
+ make_shared_array_property_map(size_t n, const ValueType&, OffsetMap omap)
</pre>
-Use this function instead of the 2-argument version if
-your compiler does not support partial specialization
-(like Visual C++).
+A function for conveniently creating a shared array map.
<hr>
-
<br>
<HR>
<TABLE>
<TR valign=top>
-<TD nowrap>Copyright © 2000-2002</TD><TD>
-Jeremy Siek,
-Univ.of Notre Dame (<A
-HREF="mailto:jsiek_at_[hidden]">jsiek_at_[hidden]</A>)<br>
-<A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Univ.of Notre Dame (<A HREF="mailto:llee1_at_[hidden]">llee1_at_[hidden]</A>)<br>
-Andrew Lumsdaine,
-Univ.of Notre Dame (<A
-HREF="mailto:lums_at_[hidden]">lums_at_[hidden]</A>)
+<TD nowrap>Copyright © 2009</TD><TD>
+Trustees of Indiana University.
</TD></TR></TABLE>
</BODY>
Modified: trunk/libs/property_map/test/property_map_cc.cpp
==============================================================================
--- trunk/libs/property_map/test/property_map_cc.cpp (original)
+++ trunk/libs/property_map/test/property_map_cc.cpp 2009-05-30 23:32:08 EDT (Sat, 30 May 2009)
@@ -4,6 +4,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/property_map/property_map.hpp>
+#include <boost/property_map/shared_array_property_map.hpp>
#include <map>
// This file checks the property map concepts against the property map
@@ -103,5 +104,13 @@
typedef dummy_property_map PMap;
function_requires<ReadWritePropertyMapConcept<PMap, int> >();
}
+ {
+ typedef sgi_assignable_archetype<> Key; // ?
+ typedef sgi_assignable_archetype<> Value;
+ typedef random_access_iterator_archetype<Value> Iterator;
+ typedef readable_property_map_archetype<Key, std::ptrdiff_t> IndexMap;
+ typedef shared_array_property_map<Value, IndexMap> PMap;
+ function_requires<Mutable_LvaluePropertyMapConcept<PMap, Key> >();
+ }
return 0;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk