|
Boost-Commit : |
From: asutton_at_[hidden]
Date: 2007-09-07 12:50:23
Author: asutton
Date: 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
New Revision: 39155
URL: http://svn.boost.org/trac/boost/changeset/39155
Log:
Small tweaks to some identity and iterator property maps
Added example for iterator/identity property map
Wrote reference docs for iterator property map
Added project root (forgot)
Added:
sandbox/graph-v2/libs/property_map/doc/identity_property_map.qbk (contents, props changed)
sandbox/graph-v2/libs/property_map/doc/reference.qbk (contents, props changed)
sandbox/graph-v2/libs/property_map/example/Jamfile (contents, props changed)
sandbox/graph-v2/libs/property_map/example/iterator_property_map.cpp (contents, props changed)
sandbox/graph-v2/libs/property_map/project-root.jam (contents, props changed)
sandbox/graph-v2/libs/property_map/test/runtime/iterator_property_map.cpp (contents, props changed)
Text files modified:
sandbox/graph-v2/boost/property_map.hpp | 3 -
sandbox/graph-v2/boost/property_map/identity_property_map.hpp | 2
sandbox/graph-v2/boost/property_map/iterator_property_map.hpp | 2
sandbox/graph-v2/libs/property_map/ChangeLog | 7 ++++
sandbox/graph-v2/libs/property_map/doc/concepts.qbk | 13 ++-------
sandbox/graph-v2/libs/property_map/doc/property_map.qbk | 22 ++++++++++++++
sandbox/graph-v2/libs/property_map/example/example1.cpp | 57 +++++++++++++++++++++------------------
sandbox/graph-v2/libs/property_map/test/compile/iterator_property_map.cpp | 5 ++-
8 files changed, 66 insertions(+), 45 deletions(-)
Modified: sandbox/graph-v2/boost/property_map.hpp
==============================================================================
--- sandbox/graph-v2/boost/property_map.hpp (original)
+++ sandbox/graph-v2/boost/property_map.hpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -5,8 +5,6 @@
// 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_PROPERTY_MAP_HPP
#define BOOST_PROPERTY_MAP_HPP
@@ -17,6 +15,7 @@
#include <boost/property_map/constant_property_map.hpp>
#include <boost/property_map/identity_property_map.hpp>
#include <boost/property_map/dummy_property_map.hpp>
+#include <boost/property_map/dynamic_property_map.hpp>
#include <boost/property_map/concepts.hpp>
#endif
Modified: sandbox/graph-v2/boost/property_map/identity_property_map.hpp
==============================================================================
--- sandbox/graph-v2/boost/property_map/identity_property_map.hpp (original)
+++ sandbox/graph-v2/boost/property_map/identity_property_map.hpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -37,7 +37,7 @@
};
template <typename Value>
- inline const Value&
+ inline typename property_traits< identity_property_map<Value> >::reference
get(const identity_property_map<Value>& pm, const Value& v)
{ return v; }
Modified: sandbox/graph-v2/boost/property_map/iterator_property_map.hpp
==============================================================================
--- sandbox/graph-v2/boost/property_map/iterator_property_map.hpp (original)
+++ sandbox/graph-v2/boost/property_map/iterator_property_map.hpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -90,7 +90,7 @@
// NOTE: The requirement that IndexMap model the ReadablePropertyMap concept
// is somewhat "recursive" since it both defines and the key type for the
// property map being constructed and provides its type for the function.
- template <class Iterator, class IndexMap>
+ template <typename Iterator, typename IndexMap>
inline iterator_property_map<
Iterator, IndexMap,
typename boost::detail::iterator_traits<Iterator>::value_type,
Modified: sandbox/graph-v2/libs/property_map/ChangeLog
==============================================================================
--- sandbox/graph-v2/libs/property_map/ChangeLog (original)
+++ sandbox/graph-v2/libs/property_map/ChangeLog 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -59,4 +59,9 @@
get functions, actually have them - even if they don't do anything.
Fixed #954 - added a copy constructor to the dynamic_properties. Also added
- a virtual constructor to dynamic_property_map to support the operation.
\ No newline at end of file
+ a virtual constructor to dynamic_property_map to support the operation.
+
+* Thoughts about vector_property_map...
+ This class needs to go. It doesn't follow the same pattern as other property
+ maps because it embeds its own vector within it. Property maps /abstract/ and
+ /decouple/ the read/write concepts, they shouldn't wrap them.
\ No newline at end of file
Modified: sandbox/graph-v2/libs/property_map/doc/concepts.qbk
==============================================================================
--- sandbox/graph-v2/libs/property_map/doc/concepts.qbk (original)
+++ sandbox/graph-v2/libs/property_map/doc/concepts.qbk 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -43,22 +43,15 @@
[variablelist Property Map Concepts
[
[[ReadablePropertyMap]]
- [
- The associated property data can be read using `get()`.
- ]
+ [The associated property data can be read using `get()`.]
]
[
[[WritablePropertyMap]]
- [
- The associated property can be written using `put()`.
- ]
+ [The associated property can be written using `put()`.]
]
[
[[ReadWritePropertyMap]]
- [
- The associated property can both be written and read using `get()`
- and `put()`.
- ]
+ [The associated property can both be written and read using `get()` and `put()`.]
]
[
[[LvaluePropertyMap]]
Added: sandbox/graph-v2/libs/property_map/doc/identity_property_map.qbk
==============================================================================
--- (empty file)
+++ sandbox/graph-v2/libs/property_map/doc/identity_property_map.qbk 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -0,0 +1,100 @@
+[/
+ / Copyright (c) 2007 Andrew Sutton
+ /
+ / 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)
+ /]
+
+[section Identity Property Map]
+
+ #include <boost/property_map/identity_property_map.hpp>
+
+ template <typename Value>
+ struct identity_property_map { ... };
+
+This property map applies the identity function to its key type, returning each
+the given key as the requested value.
+
+[heading Model Of]
+[ReadablePropertyMap]
+
+[heading Associated Types]
+[table
+ [[Associated Type] [Type]]
+ [
+ [Value Type]
+ [`property_traits<PropMap>::value_type`]
+ [
+ `Value`
+ ]
+ ]
+ [
+ [Reference Type]
+ [`property_traits<PropMap>::reference`]
+ [
+ `const Value&`.
+ ]
+ ]
+ [
+ [Key Type]
+ [`property_traits<PropMap>::key_type`]
+ [
+ `Value`
+ ]
+ ]
+ [
+ [Property Map Category]
+ [`property_traits<PropMap>::category`]
+ [
+ `readable_property_map_tag`
+ ]
+ ]
+]
+
+[heading Non-Member Functions]
+[table
+ [[Name] [Member] [Description]]
+ [
+ [Get Property Value]
+ [
+``
+template <typename Value>
+typename property_traits< identity_property_map<Value> >::reference
+get(const identity_property_map<Value>&, const Value&);
+``
+ ]
+ [
+ Return the identity of the given value, which is the value itself.
+ ]
+ ]
+]
+
+[heading Examples]
+This example shows the use of the `identity_property_map` to support an
+`iterator_property_map`. Specifically, the identity map provides a `get()` function
+that returns the indices into a vector. These indices are transformed into offsets
+from the beginning of the vector, to return the requested value.
+
+[import ../example/iterator_property_map.cpp]
+
+[code_iterator_property_map]
+
+The output of this program is:
+
+[pre
+Smith, Bob
+Thompson, Fred
+]
+
+[heading Design Notes]
+This class was originally written explicitly for unsigned integers, but was later
+made generic to a) be more generic and b) correctly identify the types used in
+association with the get() function.
+
+Although not documented here, this class also implements the syntactic requirements
+for the [WritablePropertyMap] and [LvaluePropertyMap] concepts. However, using
+`put()` with an `identity_property_map` does nothing, and the `operator[]` accessor
+returns the key as a non-mutable value. Preferred usage of this class is through
+the `get()` function.
+
+[endsect]
Modified: sandbox/graph-v2/libs/property_map/doc/property_map.qbk
==============================================================================
--- sandbox/graph-v2/libs/property_map/doc/property_map.qbk (original)
+++ sandbox/graph-v2/libs/property_map/doc/property_map.qbk 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -47,6 +47,26 @@
boost_property_map.concepts.lvalue_property_map
[^LvaluePropertyMap]]]
+[template identity_property_map[] [link
+ boost_property_map.reference.identity_property_map
+ [^identity_property_map]]]
+[template constant_property_map[] [link
+ boost_property_map.reference.constant_property_map
+ [^constant_property_map]]]
+[template reference_property_map[] [link
+ boost_property_map.reference.reference_property_map
+ [^reference_property_map]]]
+[template dummy_property_map[] [link
+ boost_property_map.reference.dummy_property_map
+ [^dummy_property_map]]]
+[template associative_property_map[] [link
+ boost_property_map.reference.associative_property_map
+ [^associative_property_map]]]
+[template iterator_property_map[] [link
+ boost_property_map.reference.iterator_property_map
+ [^iterator_property_map]]]
+
[include introduction.qbk]
[include concepts.qbk]
-[include bibliography.qbk]
\ No newline at end of file
+[include reference.qbk]
+[include bibliography.qbk]
Added: sandbox/graph-v2/libs/property_map/doc/reference.qbk
==============================================================================
--- (empty file)
+++ sandbox/graph-v2/libs/property_map/doc/reference.qbk 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -0,0 +1,51 @@
+[/
+ / Copyright (c) 2007 Andrew Sutton
+ /
+ / 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)
+ /]
+
+[section Reference]
+
+The Boost.Property_Map library provides a number of built-in implementations
+of various property maps. These are general purpose property maps that can be
+used off-the-shelf. They are:
+
+[table
+ [[Property Map] [Description]]
+ [
+ [[identity_property_map]]
+ [For any key, returns the given key as the requested value.]
+ ]
+ [
+ [[constant_property_map]]
+ [For all keys, returns the same value that the property map was initially construted with.]
+ ]
+ [
+ [[reference_property_map]]
+ [
+ For all keys, returns a reference to the same object. For any key, putting a
+ value, changes the value being returned.
+ ]
+ ]
+ [
+ [[dummy_property_map]]
+ [For all keys, putting a value does nothing.]
+ ]
+ [
+ [[associative_property_map]]
+ [A property map built over unique pair-associative containers such as `std::map`.]
+ ]
+ [
+ [[iterator_property_map]]
+ [
+ A property map built over forward containers that uses another property
+ map (an index) to provide an offset past iterator over which the map
+ was constructed.
+ ]
+ ]
+]
+
+[include identity_property_map.qbk]
+
+[endsect]
Added: sandbox/graph-v2/libs/property_map/example/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/graph-v2/libs/property_map/example/Jamfile 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -0,0 +1,16 @@
+# (C) Copyright Andrew Sutton 2007
+#
+# Use, modification and distribution is subject to 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)
+
+project
+ : requirements
+ <include>../../../
+ <include>$BOOST_ROOT
+ ;
+
+exe example1 : example1.cpp ;
+exe example2 : example2.cpp ;
+exe example3 : example3.cpp ;
+exe iterator_property_map : iterator_property_map.cpp ;
\ No newline at end of file
Modified: sandbox/graph-v2/libs/property_map/example/example1.cpp
==============================================================================
--- sandbox/graph-v2/libs/property_map/example/example1.cpp (original)
+++ sandbox/graph-v2/libs/property_map/example/example1.cpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -1,48 +1,51 @@
// (C) Copyright Jeremy Siek 2002.
+//
// 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)
+//[code_example_1
#include <iostream>
#include <map>
#include <string>
-#include <boost/property_map.hpp>
+#include <boost/cstdlib.hpp>
+#include <boost/property_map.hpp>
template <typename AddressMap>
void foo(AddressMap address)
{
- typedef typename boost::property_traits<AddressMap>::value_type value_type;
- typedef typename boost::property_traits<AddressMap>::key_type key_type;
+ typedef typename boost::property_traits<AddressMap>::value_type value_type;
+ typedef typename boost::property_traits<AddressMap>::key_type key_type;
- value_type old_address, new_address;
- key_type fred = "Fred";
- old_address = get(address, fred);
- new_address = "384 Fitzpatrick Street";
- put(address, fred, new_address);
-
- key_type joe = "Joe";
- value_type& joes_address = address[joe];
- joes_address = "325 Cushing Avenue";
+ value_type old_address, new_address;
+ key_type fred = "Fred";
+ old_address = get(address, fred);
+ new_address = "384 Fitzpatrick Street";
+ put(address, fred, new_address);
+
+ key_type joe = "Joe";
+ value_type& joes_address = address[joe];
+ joes_address = "325 Cushing Avenue";
}
int
main()
{
- std::map<std::string, std::string> name2address;
- boost::associative_property_map< std::map<std::string, std::string> >
- address_map(name2address);
-
- name2address.insert(make_pair(std::string("Fred"),
- std::string("710 West 13th Street")));
- name2address.insert(make_pair(std::string("Joe"),
- std::string("710 West 13th Street")));
-
- foo(address_map);
-
- for (std::map<std::string, std::string>::iterator i = name2address.begin();
- i != name2address.end(); ++i)
- std::cout << i->first << ": " << i->second << "\n";
+ typedef std::map<std::string, std::string> StringMap;
+ StringMap name2address;
+ boost::associative_property_map<StringMap> address_map(name2address);
+
+ name2address.insert(make_pair(std::string("Fred"), std::string("710 West 13th Street")));
+ name2address.insert(make_pair(std::string("Joe"), std::string("710 West 13th Street")));
+
+ foo(address_map);
+
+ StringMap::iterator i, end = name2address.end();
+ for(i = name2address.begin(); i != end; ++i) {
+ std::cout << i->first << ": " << i->second << "\n";
+ }
- return EXIT_SUCCESS;
+ return boost::exit_success;
}
+//]
Added: sandbox/graph-v2/libs/property_map/example/iterator_property_map.cpp
==============================================================================
--- (empty file)
+++ sandbox/graph-v2/libs/property_map/example/iterator_property_map.cpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -0,0 +1,64 @@
+// (C) Copyright Jeremy Siek 2002.
+//
+// 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)
+
+//[code_iterator_property_map
+#include <iostream>
+#include <vector>
+#include <string>
+
+#include <boost/cstdlib.hpp>
+#include <boost/property_map/identity_property_map.hpp>
+#include <boost/property_map/iterator_property_map.hpp>
+
+using namespace std;
+using namespace boost;
+using namespace boost::property_map;
+
+// This is a generic "algorithm" that uses a property map to compute
+// a person's name as "Last, First" for a given key.
+template <typename Key, typename FirstNameMap, typename LastNameMap>
+string last_name_first(const Key& key, FirstNameMap first, LastNameMap last)
+{
+ return get(last, key) + ", " + get(first, key);
+}
+
+int
+main()
+{
+ // Start by typedef'ing a bunch of stuff to make name shorter.
+ typedef vector<string> Vector;
+ typedef Vector::size_type Index;
+ typedef Vector::iterator Iterator;
+
+ // Define an identity map over the indices of the vector above.
+ typedef identity_property_map<Index> IndexMap;
+
+ // Define an iterator map over the Vector's iterator type and the
+ // IndexMap that we just defined. Indices from the IndexMap will
+ // provide offsets to an iterator from Vector.
+ typedef iterator_property_map<Iterator, IndexMap> IteratorMap;
+
+ // Allocaetd the storage of Person objects and configure a couple.
+ Vector first_names(2);
+ Vector last_names(2);
+ first_names[0] = "Bob";
+ first_names[1] = "Fred";
+ last_names[0] = "Smith";
+ last_names[1] = "Thompson";
+
+ // Create property maps so that we can abstractly access the
+ // Person objects stored in the vector above.
+ IndexMap indices;
+ IteratorMap first_map(first_names.begin(), indices);
+ IteratorMap last_map(last_names.begin(), indices);
+
+ // Print formatted names.
+ cout << last_name_first(0, first_names, last_names) << endl;
+ cout << last_name_first(1, first_names, last_names) << endl;
+
+ return boost::exit_success;
+}
+//]
Added: sandbox/graph-v2/libs/property_map/project-root.jam
==============================================================================
--- (empty file)
+++ sandbox/graph-v2/libs/property_map/project-root.jam 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -0,0 +1,66 @@
+#
+# Copyright (c) 2006 João Abecasis
+#
+# 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)
+#
+
+##
+## IMPORTANT NOTE: This file MUST NOT be copied over a boost installation
+##
+
+path-constant top : . ;
+
+import modules ;
+import path ;
+
+local boost-root = [ modules.peek : BOOST_ROOT ] ;
+local graph-header-include = $(top)/../.. ;
+
+# Try to find the boost-root. This is the top-level of the Boost source
+# directory and is used to reference most of the other libs.
+if ! $(boost-root)
+{
+ local boost-search-dirs = [ modules.peek : BOOST_BUILD_PATH ] ;
+
+ for local dir in $(boost-search-dirs)
+ {
+ if [ path.glob $(dir)/../../../ : boost/version.hpp ]
+ {
+ boost-root += $(dir)/../../../ ;
+ }
+ }
+
+ if $(boost-root)
+ {
+ boost-root = [ path.make $(boost-root[1]) ] ;
+ }
+ else
+ {
+ ECHO "Warning: couldn't find BOOST_ROOT in" $(boost-root) ;
+ }
+}
+
+## This is how we can alias other directories in the Boost distribution.
+# use-project /boost/regex : $(boost-root)/libs/regex/build ;
+# use-project /boost/unit_test : $(boost-root)/libs/test/build ;
+
+## Specifies some project-level globals for all subdirs in this
+## directory. Note that the buid-dir puts all of the build files
+## in the bin.v2 directory (for all subdirs!)
+# project math-toolkit
+# : requirements
+# <include>$(boost-root)
+# <include>$(math-header-include)
+# : # build everything in ./bin.v2
+# build-dir bin.v2
+# ;
+
+
+
+
+
+
+
+
Modified: sandbox/graph-v2/libs/property_map/test/compile/iterator_property_map.cpp
==============================================================================
--- sandbox/graph-v2/libs/property_map/test/compile/iterator_property_map.cpp (original)
+++ sandbox/graph-v2/libs/property_map/test/compile/iterator_property_map.cpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -6,6 +6,7 @@
#include <vector>
#include <boost/property_map/archetypes.hpp>
+#include <boost/property_map/identity_property_map.hpp>
#include <boost/property_map/iterator_property_map.hpp>
int main()
@@ -21,10 +22,10 @@
// It has something to do with the fact that the key type of the
// index map has to be addable to the iterator type of the underling
// vector. Bizarre.
- typedef null_archetype<> Key;
+ typedef unsigned Key;
typedef unsigned Value;
typedef vector<Value> Vector;
- typedef readable_property_map_archetype<Key, Value> IndexMap;
+ typedef identity_property_map<Key> IndexMap;
typedef iterator_property_map<Vector::iterator, IndexMap> IteratorMap;
Key& k = static_object<Key>::get();
Added: sandbox/graph-v2/libs/property_map/test/runtime/iterator_property_map.cpp
==============================================================================
--- (empty file)
+++ sandbox/graph-v2/libs/property_map/test/runtime/iterator_property_map.cpp 2007-09-07 12:50:21 EDT (Fri, 07 Sep 2007)
@@ -0,0 +1,68 @@
+// (C) Copyright Andrew Sutton 2007
+//
+// Use, modification and distribution is subject to 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)
+//
+// Author: Andrew Sutton
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <list>
+
+#include <boost/config.hpp>
+#include <boost/utility.hpp>
+#include <boost/test/minimal.hpp>
+#include <boost/property_map/identity_property_map.hpp>
+#include <boost/property_map/iterator_property_map.hpp>
+
+using namespace std;
+using namespace boost;
+using namespace boost::property_map;
+
+template <typename Sequence>
+void build_test(Sequence& seq)
+{
+ for(size_t i = 0; i < 10; ++i) {
+ seq.push_back(2 * i);
+ }
+}
+
+template <typename Sequence>
+void run_test(Sequence& seq)
+{
+ typedef typename Sequence::value_type Value;
+ typedef typename Sequence::size_type Key;
+ typedef typename Sequence::iterator Iterator;
+
+ typedef identity_property_map<Key> IdentityMap;
+ IdentityMap indices;
+
+ typedef iterator_property_map<Iterator, IdentityMap> IteratorMap;
+ IteratorMap values = make_iterator_property_map(seq.begin(), indices);
+
+ // do some stuff
+ cout << get(values, 3) << endl;
+ put(values, 2, 10);
+ cout << get(values, 2) << endl;
+}
+
+int test_main(int, char*[])
+{
+ {
+ typedef vector<int> Vector;
+ Vector v;
+ build_test(v);
+ run_test(v);
+ }
+
+ {
+ typedef list<int> List;
+ List l;
+ build_test(l);
+ run_test(l);
+ }
+
+ 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