Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77535 - in trunk: boost/property_map libs/property_map/doc libs/property_map/test
From: jewillco_at_[hidden]
Date: 2012-03-25 01:19:31


Author: jewillco
Date: 2012-03-25 01:19:30 EDT (Sun, 25 Mar 2012)
New Revision: 77535
URL: http://svn.boost.org/trac/boost/changeset/77535

Log:
Added composition of function to output of property map
Added:
   trunk/boost/property_map/transform_value_property_map.hpp
      - copied, changed from r77514, /trunk/boost/property_map/function_property_map.hpp
   trunk/libs/property_map/doc/transform_value_property_map.html
      - copied, changed from r77514, /trunk/libs/property_map/doc/function_property_map.html
   trunk/libs/property_map/test/transform_value_property_map_test.cpp
      - copied, changed from r77513, /trunk/libs/property_map/test/function_property_map_test.cpp
Text files modified:
   trunk/boost/property_map/transform_value_property_map.hpp | 35 +++++++++++++++--------------
   trunk/libs/property_map/doc/property_map.html | 1
   trunk/libs/property_map/doc/transform_value_property_map.html | 34 ++++++++++++++--------------
   trunk/libs/property_map/test/Jamfile.v2 | 1
   trunk/libs/property_map/test/transform_value_property_map_test.cpp | 48 ++++++++++++++++++++++-----------------
   5 files changed, 64 insertions(+), 55 deletions(-)

Copied: trunk/boost/property_map/transform_value_property_map.hpp (from r77514, /trunk/boost/property_map/function_property_map.hpp)
==============================================================================
--- /trunk/boost/property_map/function_property_map.hpp (original)
+++ trunk/boost/property_map/transform_value_property_map.hpp 2012-03-25 01:19:30 EDT (Sun, 25 Mar 2012)
@@ -10,8 +10,8 @@
 //=======================================================================
 //
 
-#ifndef BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
-#define BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
+#ifndef BOOST_PROPERTY_MAP_TRANSFORM_VALUE_PROPERTY_MAP_HPP
+#define BOOST_PROPERTY_MAP_TRANSFORM_VALUE_PROPERTY_MAP_HPP
 
 #include <boost/config.hpp>
 #include <boost/property_map/property_map.hpp>
@@ -23,10 +23,10 @@
 
 namespace boost {
 
-template<typename Func, typename Key, typename Ret = typename boost::result_of<const Func(const Key&)>::type>
-class function_property_map: public put_get_helper<Ret, function_property_map<Func, Key, Ret> > {
+template<typename Func, typename PM, typename Ret = typename boost::result_of<const Func(typename property_traits<PM>::reference)>::type>
+class transform_value_property_map: public put_get_helper<Ret, transform_value_property_map<Func, PM, Ret> > {
   public:
- typedef Key key_type;
+ typedef typename property_traits<PM>::key_type key_type;
   typedef Ret reference;
   typedef typename boost::remove_cv<typename boost::remove_reference<Ret>::type>::type value_type;
 
@@ -39,28 +39,29 @@
                      boost::readable_property_map_tag>::type
     category;
 
- function_property_map(Func f = Func()) : f(f) {}
+ transform_value_property_map(Func f, PM pm) : f(f), pm(pm) {}
 
- reference operator[](const Key& k) const {
- return f(k);
+ reference operator[](const key_type& k) const {
+ return f(get(pm, k));
   }
 
   private:
   Func f;
+ PM pm;
 };
 
-template<typename Key, typename Func>
-function_property_map<Func, Key>
-make_function_property_map(const Func& f) {
- return function_property_map<Func, Key>(f);
+template<typename PM, typename Func>
+transform_value_property_map<Func, PM>
+make_transform_value_property_map(const Func& f, const PM& pm) {
+ return transform_value_property_map<Func, PM>(f, pm);
 }
 
-template<typename Key, typename Ret, typename Func>
-function_property_map<Func, Key, Ret>
-make_function_property_map(const Func& f) {
- return function_property_map<Func, Key, Ret>(f);
+template<typename Ret, typename PM, typename Func>
+transform_value_property_map<Func, PM, Ret>
+make_transform_value_property_map(const Func& f, const PM& pm) {
+ return transform_value_property_map<Func, PM, Ret>(f, pm);
 }
 
 } // boost
 
-#endif /* BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP */
+#endif /* BOOST_PROPERTY_MAP_TRANSFORM_VALUE_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 2012-03-25 01:19:30 EDT (Sun, 25 Mar 2012)
@@ -291,6 +291,7 @@
   <li>const_associative_property_map</li>
   <li>vector_property_map</li>
   <li>ref_property_map </li>
+ <li>transform_value_property_map </li>
 </ul>
 
 <h3>History</h3>

Copied: trunk/libs/property_map/doc/transform_value_property_map.html (from r77514, /trunk/libs/property_map/doc/function_property_map.html)
==============================================================================
--- /trunk/libs/property_map/doc/function_property_map.html (original)
+++ trunk/libs/property_map/doc/transform_value_property_map.html 2012-03-25 01:19:30 EDT (Sun, 25 Mar 2012)
@@ -7,7 +7,7 @@
      http://www.boost.org/LICENSE_1_0.txt)
   -->
 <Head>
-<Title>Function Property Map Adaptor</Title>
+<Title>Value-Transforming Property Map Adaptor</Title>
 <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
         ALINK="#ff0000">
 <IMG SRC="../../../boost.png"
@@ -19,11 +19,11 @@
 <H2><A NAME="sec:function-property-map"></A>
 </h2>
 <PRE>
-function_property_map&lt;UnaryFunction, Key, Ref&gt;
+transform_value_property_map&lt;UnaryFunction, PM, Ref&gt;
 </PRE>
 
 <P>
-This property map is an adaptor that converts a function object into either a Readable Property Map or a Lvalue Property Map. The category of the property map is based on whether the function's return type (as given by <tt>Ref</tt>) is a non-const reference type.
+This property map is an adaptor that composes a function object after an existing property map. The new property map will model either Readable Property Map or a Lvalue Property Map. The category of the property map is based on whether the function's return type (as given by <tt>Ref</tt>) is a non-const reference type.
 
 <P>
 
@@ -35,7 +35,7 @@
 <H3>Where Defined</H3>
 
 <P>
-boost/property_map/function_property_map.hpp
+boost/property_map/transform_value_property_map.hpp
 
 <p>
 <H3>Model Of</H3>
@@ -56,19 +56,19 @@
 
 <TR>
 <TD><TT>UnaryFunction</TT></TD>
-<TD>Must be a model of Unary Function that accepts an object of type <tt>Key</tt> as an argument and returns a result of type <tt>Ref</tt>.</TD>
+<TD>Must be a model of Unary Function that accepts an object of type <tt>property_traits&lt;PM&gt;::reference</tt> as an argument and returns a result of type <tt>Ref</tt>.</TD>
 <TD>&nbsp;</td>
 </tr>
 
 <TR>
-<TD><TT>Key</TT></TD> <TD>The key type of the property map.
+<TD><TT>PM</TT></TD> <TD>The underlying property map.
 </TD> <TD>&nbsp;</TD>
 </TR>
 
 <TR>
 <TD><TT>Ref</TT></TD>
 <TD>The result type of the function.</TD>
-<TD><TT>boost::result_of&lt;const UnaryFunction(const Key&amp;)&gt;::type</TT></TD>
+<TD><TT>boost::result_of&lt;const UnaryFunction(property_traits&lt;PM&gt;::reference)&gt;::type</TT></TD>
 </TR>
 
 
@@ -85,14 +85,14 @@
 <hr>
 
 <pre>
-property_traits&lt;function_property_map&gt;::value_type
+property_traits&lt;transform_value_property_map&gt;::value_type
 </pre>
 The type <tt>Ref</tt> with any reference or cv-qualifiers removed.
 
 <hr>
 
 <pre>
-function_property_map(const UnaryFunction&amp; f = UnaryFunction())
+transform_value_property_map(const UnaryFunction&amp; f, const PM&amp; pm);
 </pre>
 Constructor.
 
@@ -103,20 +103,20 @@
 <hr>
 
 <pre>
- template &lt;class Key, class UnaryFunction&gt;
- function_property_map&lt;UnaryFunction, Key&gt;
- make_function_property_map(const UnaryFunction&amp; f);
+ template &lt;class PM, class UnaryFunction&gt;
+ transform_value_property_map&lt;UnaryFunction, PM&gt;
+ make_transform_value_property_map(const UnaryFunction&amp; f, const PM&amp; pm);
 </pre>
-Returns a <tt>function_property_map</tt> using the given function and key type.
+Returns a <tt>transform_value_property_map</tt> using the given function and property map type.
 
 <hr>
 
 <pre>
- template &lt;class Key, class Ref, class UnaryFunction&gt;
- function_property_map&lt;UnaryFunction, Key, Ref&gt;
- make_function_property_map(const UnaryFunction&amp; f);
+ template &lt;class Ref, class PM, class UnaryFunction&gt;
+ transform_value_property_map&lt;UnaryFunction, PM, Ref&gt;
+ make_transform_value_property_map(const UnaryFunction&amp; f, const PM&amp; pm);
 </pre>
-Returns a <tt>function_property_map</tt> using the given function and key and reference types.
+Returns a <tt>transform_value_property_map</tt> using the given function and property map, explicitly giving the function's result type.
 
 <hr>
 

Modified: trunk/libs/property_map/test/Jamfile.v2
==============================================================================
--- trunk/libs/property_map/test/Jamfile.v2 (original)
+++ trunk/libs/property_map/test/Jamfile.v2 2012-03-25 01:19:30 EDT (Sun, 25 Mar 2012)
@@ -14,4 +14,5 @@
   : [ compile property_map_cc.cpp ]
     [ run dynamic_properties_test.cpp ]
     [ run function_property_map_test.cpp ]
+ [ run transform_value_property_map_test.cpp ]
   ;

Copied: trunk/libs/property_map/test/transform_value_property_map_test.cpp (from r77513, /trunk/libs/property_map/test/function_property_map_test.cpp)
==============================================================================
--- /trunk/libs/property_map/test/function_property_map_test.cpp (original)
+++ trunk/libs/property_map/test/transform_value_property_map_test.cpp 2012-03-25 01:19:30 EDT (Sun, 25 Mar 2012)
@@ -11,11 +11,15 @@
 //
 
 #include <boost/property_map/function_property_map.hpp>
+#include <boost/property_map/transform_value_property_map.hpp>
 #include <boost/concept_check.hpp>
 #include <boost/property_map/property_map.hpp>
 #include <boost/test/minimal.hpp>
 #include <boost/static_assert.hpp>
 
+// Ensure this is not default constructible
+struct times2 {typedef int result_type; times2(int) {}; int operator()(int x) const {return 2 * x;}};
+
 template <typename T>
 struct add1 {typedef T result_type; T operator()(const T& x) const {return x + 1;}};
 
@@ -32,32 +36,34 @@
 
 int test_main(int, char**) {
   using namespace boost;
- function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int>, int> >();
- function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int, double>, int> >();
- function_requires<ReadablePropertyMapConcept<function_property_map<add1_val<int>, int>, int> >();
- function_requires<ReadablePropertyMapConcept<function_property_map<add1_val<int>, int, double>, int> >();
- function_requires<ReadablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
- function_requires<WritablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
- function_requires<ReadWritePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
- function_requires<LvaluePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
-
- BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<function_property_map<add1<int>, int> >::category, boost::readable_property_map_tag>::value));
- BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<function_property_map<add1_val<int>, int> >::category, boost::readable_property_map_tag>::value));
- BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<function_property_map<return_fixed_ref<int>, int> >::category, boost::lvalue_property_map_tag>::value));
-
- BOOST_CHECK(get(function_property_map<add1<int>, int>(), 3) == 4);
- BOOST_CHECK(get(function_property_map<add1<int>, int>(add1<int>()), 4) == 5);
- BOOST_CHECK(get(make_function_property_map<int>(add1<int>()), 5) == 6);
- BOOST_CHECK(get(function_property_map<add1_val<int>, int>(), 3) == 4);
- BOOST_CHECK(get(function_property_map<add1_val<int>, int>(add1_val<int>()), 4) == 5);
- BOOST_CHECK(get(make_function_property_map<int>(add1_val<int>()), 5) == 6);
+ typedef function_property_map<times2, int> PM;
+ PM orig_pm(times2(0));
+ function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1<int>, PM>, int> >();
+ function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1<int>, PM, double>, int> >();
+ function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1_val<int>, PM>, int> >();
+ function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1_val<int>, PM, double>, int> >();
+ function_requires<ReadablePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >();
+ function_requires<WritablePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >();
+ function_requires<ReadWritePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >();
+ function_requires<LvaluePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >();
+
+ BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<transform_value_property_map<add1<int>, PM> >::category, boost::readable_property_map_tag>::value));
+ BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<transform_value_property_map<add1_val<int>, PM> >::category, boost::readable_property_map_tag>::value));
+ BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<transform_value_property_map<return_fixed_ref<int>, PM> >::category, boost::lvalue_property_map_tag>::value));
+
+ BOOST_CHECK(get(transform_value_property_map<add1<int>, PM>(add1<int>(), orig_pm), 3) == 7);
+ BOOST_CHECK(get(transform_value_property_map<add1<int>, PM>(add1<int>(), orig_pm), 4) == 9);
+ BOOST_CHECK(get(make_transform_value_property_map(add1<int>(), orig_pm), 5) == 11);
+ BOOST_CHECK(get(transform_value_property_map<add1_val<int>, PM>(add1_val<int>(), orig_pm), 3) == 7);
+ BOOST_CHECK(get(transform_value_property_map<add1_val<int>, PM>(add1_val<int>(), orig_pm), 4) == 9);
+ BOOST_CHECK(get(make_transform_value_property_map<int>(add1_val<int>(), orig_pm), 5) == 11);
   int val;
- const function_property_map<return_fixed_ref<int>, int> pm = return_fixed_ref<int>((&val));
+ const transform_value_property_map<return_fixed_ref<int>, PM> pm(return_fixed_ref<int>((&val)), orig_pm);
   put(pm, 1, 6);
   BOOST_CHECK(get(pm, 2) == 6);
   BOOST_CHECK((get(pm, 3) = 7) == 7);
   BOOST_CHECK(get(pm, 4) == 7);
- const function_property_map<return_fixed_ref<int>, int> pm2 = pm; // Check shallow copying
+ const transform_value_property_map<return_fixed_ref<int>, PM> pm2 = pm; // Check shallow copying
   BOOST_CHECK(get(pm2, 5) == 7);
   put(pm2, 3, 1);
   BOOST_CHECK(get(pm, 1) == 1);


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