Boost logo

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&lt;RandomAccessIterator, OffsetMap, T, R&gt;
+shared_array_property_map&lt;ValueType, OffsetMap&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>.
+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 &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>
-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>&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>
+<TD><TT>ValueType</TT></TD>
+<TD>The value type of the property map.</TD>
+<TD>&nbsp;</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>
+<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>&nbsp;</TD>
 </TR>
 
 </TABLE>
@@ -153,34 +81,28 @@
 <hr>
 
 <pre>
-property_traits&lt;iterator_property_map&gt;::value_type
+property_traits&lt;shared_array_property_map&gt;::value_type
 </pre>
 This is the same type as
-<TT>std::iterator_traits&lt;Iterator&gt;::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&lt;Iterator&gt;</TT>.
-
 <hr>
 
 <h3>Non-Member functions</h3>
@@ -188,46 +110,21 @@
 <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)
+ template &lt;class ValueType, class OffsetMap&gt;
+ shared_array_property_map&lt;ValueType, OffsetMap&gt;
+ make_shared_array_property_map(size_t n, const ValueType&amp;, 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 &copy 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 &copy; 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