Chris@16
|
1 // Copyright (C) 2013 Eurodecision
|
Chris@16
|
2 // Authors: Guillaume Pinot
|
Chris@16
|
3 //
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
5 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 //
|
Chris@16
|
8 // See http://www.boost.org/libs/property_map for documentation.
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP
|
Chris@16
|
11 #define BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/property_map/property_map.hpp>
|
Chris@16
|
14 #include <boost/type_traits.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost {
|
Chris@16
|
17
|
Chris@16
|
18 // A compose property map: make_compose_property_map(f, g)[x] == f[g[x]]
|
Chris@16
|
19 //
|
Chris@16
|
20 // g must be a readable property map.
|
Chris@16
|
21 // The category of compose_property_map(f, g) is the category of f.
|
Chris@16
|
22
|
Chris@16
|
23 template <typename FPMap, typename GPMap>
|
Chris@16
|
24 class compose_property_map
|
Chris@16
|
25 {
|
Chris@16
|
26 public:
|
Chris@16
|
27 typedef typename boost::property_traits<FPMap>::category category;
|
Chris@16
|
28 typedef typename boost::property_traits<GPMap>::key_type key_type;
|
Chris@16
|
29 typedef typename boost::property_traits<FPMap>::value_type value_type;
|
Chris@16
|
30 typedef typename boost::property_traits<FPMap>::reference reference;
|
Chris@16
|
31
|
Chris@16
|
32 inline compose_property_map(const FPMap &f_p, const GPMap &g_p):
|
Chris@16
|
33 f(f_p), g(g_p)
|
Chris@16
|
34 {}
|
Chris@16
|
35
|
Chris@16
|
36 inline compose_property_map() {}
|
Chris@16
|
37
|
Chris@16
|
38 inline reference
|
Chris@16
|
39 operator[](const key_type &v) const {
|
Chris@16
|
40 return f[get(g, v)];
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 // return type of get():
|
Chris@16
|
44 // if (reference is not a ref)
|
Chris@16
|
45 // value_type
|
Chris@16
|
46 // else if (reference is const)
|
Chris@16
|
47 // reference
|
Chris@16
|
48 // else
|
Chris@16
|
49 // const value_type&
|
Chris@16
|
50 inline friend typename boost::mpl::if_<
|
Chris@16
|
51 boost::mpl::not_< boost::is_reference<reference> >,
|
Chris@16
|
52 value_type,
|
Chris@16
|
53 typename boost::mpl::if_<
|
Chris@16
|
54 boost::is_const<reference>,
|
Chris@16
|
55 reference,
|
Chris@16
|
56 const value_type&
|
Chris@16
|
57 >::type
|
Chris@16
|
58 >::type
|
Chris@16
|
59 get(const compose_property_map &m, const key_type &k) {
|
Chris@16
|
60 return get(m.f, get(m.g, k));
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 inline friend void
|
Chris@16
|
64 put(const compose_property_map &m, const key_type &k, const value_type &v) {
|
Chris@16
|
65 put(m.f, get(m.g, k), v);
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 private:
|
Chris@16
|
69 FPMap f;
|
Chris@16
|
70 GPMap g;
|
Chris@16
|
71 };
|
Chris@16
|
72
|
Chris@16
|
73 template <class FPMap, class GPMap>
|
Chris@16
|
74 inline compose_property_map<FPMap, GPMap>
|
Chris@16
|
75 make_compose_property_map(const FPMap &f, const GPMap &g) {
|
Chris@16
|
76 return compose_property_map<FPMap, GPMap>(f, g);
|
Chris@16
|
77 }
|
Chris@16
|
78
|
Chris@16
|
79 } // namespace boost
|
Chris@16
|
80
|
Chris@16
|
81 #endif // BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP
|