Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
box_multimap.hpp
1 // -*- C++ -*-
2 //
3 // Copyright Sylvain Bougerel 2009 - 2013.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file COPYING or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
13 #ifndef SPATIAL_BOX_MULTIMAP_HPP
14 #define SPATIAL_BOX_MULTIMAP_HPP
15 
16 #include <memory> // std::allocator
17 #include <utility> // std::pair
18 #include "function.hpp"
19 #include "bits/spatial_check_concept.hpp"
20 #include "bits/spatial_relaxed_kdtree.hpp"
21 
22 namespace spatial
23 {
24 
29  template<dimension_type Rank, typename Key, typename Mapped,
30  typename Compare = bracket_less<Key>,
31  typename BalancingPolicy = loose_balancing,
32  typename Alloc = std::allocator<std::pair<const Key, Mapped> > >
34  : public details::Relaxed_kdtree<details::Static_rank<Rank>, const Key,
35  std::pair<const Key, Mapped>,
36  Compare, BalancingPolicy, Alloc>
37  {
38  private:
39  typedef typename
41 
43  <details::Static_rank<Rank>, const Key, std::pair<const Key, Mapped>,
44  Compare, BalancingPolicy, Alloc> base_type;
45  typedef box_multimap<Rank, Key, Mapped, Compare,
46  BalancingPolicy, Alloc> Self;
47 
48  public:
49  typedef Mapped mapped_type;
50 
52 
53  explicit box_multimap(const Compare& compare)
54  : base_type(details::Static_rank<Rank>(), compare)
55  { }
56 
57  box_multimap(const Compare& compare, const BalancingPolicy& balancing)
58  : base_type(details::Static_rank<Rank>(), compare, balancing)
59  { }
60 
61  box_multimap(const Compare& compare, const BalancingPolicy& balancing,
62  const Alloc& alloc)
63  : base_type(details::Static_rank<Rank>(), compare, balancing, alloc)
64  { }
65 
66  box_multimap(const box_multimap& other)
67  : base_type(other)
68  { }
69 
71  operator=(const box_multimap& other)
72  { return static_cast<Self&>(base_type::operator=(other)); }
73  };
74 
89  template<typename Key, typename Mapped,
90  typename Compare,
91  typename BalancingPolicy,
92  typename Alloc>
93  struct box_multimap<0, Key, Mapped, Compare, BalancingPolicy, Alloc>
94  : details::Relaxed_kdtree<details::Dynamic_rank, const Key,
95  std::pair<const Key, Mapped>, Compare,
96  BalancingPolicy, Alloc>
97  {
98  private:
100  <details::Dynamic_rank, const Key, std::pair<const Key, Mapped>,
101  Compare, BalancingPolicy, Alloc> base_type;
102  typedef box_multimap<0, Key, Mapped, Compare,
103  BalancingPolicy, Alloc> Self;
104 
105  public:
106  typedef Mapped mapped_type;
107 
108  box_multimap() : base_type(details::Dynamic_rank(2)) { }
109 
111  : base_type(details::Dynamic_rank(dim))
112  { except::check_even_rank(dim); }
113 
114  box_multimap(dimension_type dim, const Compare& compare)
115  : base_type(details::Dynamic_rank(dim), compare)
116  { except::check_even_rank(dim); }
117 
118  box_multimap(dimension_type dim, const Compare& compare,
119  const BalancingPolicy& policy)
120  : base_type(details::Dynamic_rank(dim), compare, policy)
121  { except::check_even_rank(dim); }
122 
123  box_multimap(dimension_type dim, const Compare& compare,
124  const BalancingPolicy& policy, const Alloc& alloc)
125  : base_type(details::Dynamic_rank(dim), compare, policy, alloc)
126  { except::check_even_rank(dim); }
127 
128  explicit box_multimap(const Compare& compare)
129  : base_type(details::Dynamic_rank(2), compare)
130  { }
131 
132  box_multimap(const Compare& compare, const BalancingPolicy& policy)
133  : base_type(details::Dynamic_rank(2), compare, policy)
134  { }
135 
136  box_multimap(const Compare& compare, const BalancingPolicy& policy,
137  const Alloc& alloc)
138  : base_type(details::Dynamic_rank(2), compare, policy, alloc)
139  { }
140 
141  box_multimap(const box_multimap& other)
142  : base_type(other)
143  { }
144 
145  box_multimap&
146  operator=(const box_multimap& other)
147  { return static_cast<Self&>(base_type::operator=(other)); }
148  };
149 
150 }
151 
152 #endif // SPATIAL_BOX_MULTIMAP_HPP
box_multimap(dimension_type dim, const Compare &compare, const BalancingPolicy &policy)
Detailed implementation of the kd-tree.
details::Relaxed_kdtree< details::Dynamic_rank, const Key, std::pair< const Key, Mapped >, Compare, BalancingPolicy, Alloc > base_type
The dimension value is stored by a member of the object, but can be modified at run time...
A mapped containers to store values in space that can be represented as boxes.
box_multimap(const Compare &compare, const BalancingPolicy &policy, const Alloc &alloc)
void check_even_rank(dimension_type rank)
Checks that rank is not null and that it is a multiple of 2.
box_multimap(const Compare &compare, const BalancingPolicy &balancing)
enable_if_c<(Rank &1u)==0 >::type check_concept_dimension_is_even
std::size_t dimension_type
Defines the type for the dimension as being a size.
Definition: spatial.hpp:71
box_multimap< 0, Key, Mapped, Compare, BalancingPolicy, Alloc > Self
If B is true, spatial::enable_if has a public member typedef type, equal to Tp; otherwise, there is no member typedef.
The dimension value is set by a template value, thus consuming no memory.
The main namespace used in the library.
Definition: algorithm.hpp:23
box_multimap(const Compare &compare, const BalancingPolicy &balancing, const Alloc &alloc)
box_multimap(const Compare &compare, const BalancingPolicy &policy)
details::Relaxed_kdtree< details::Static_rank< Rank >, const Key, std::pair< const Key, Mapped >, Compare, BalancingPolicy, Alloc > base_type
box_multimap(dimension_type dim, const Compare &compare, const BalancingPolicy &policy, const Alloc &alloc)
box_multimap(const box_multimap &other)
box_multimap(const Compare &compare)
box_multimap< Rank, Key, Mapped, Compare, BalancingPolicy, Alloc > Self
box_multimap & operator=(const box_multimap &other)