Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial_open_region.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 
16 #ifndef SPATIAL_OPEN_REGION_HPP
17 #define SPATIAL_OPEN_REGION_HPP
18 
19 #include "spatial_region.hpp"
20 
21 namespace spatial
22 {
40  template <typename Key, typename Compare>
42  : private Compare // empty member optimization
43  {
44  public:
49  : Compare(), _lower(), _upper() { }
50 
64  open_bounds(const Compare& compare, const Key& lower,
65  const Key& upper)
66  : Compare(compare), _lower(lower), _upper(upper)
67  { }
68 
82  operator()(dimension_type dim, dimension_type, const Key& key) const
83  {
84  return (!Compare::operator()(dim, _lower, key)
85  ? below
86  : (Compare::operator()(dim, key, _upper)
87  ? matching
88  : above));
89  }
90 
91  private:
95  Key _lower;
96 
100  Key _upper;
101  };
102 
121  template <typename Tp>
125  (const Tp& container,
126  const typename container_traits<Tp>::key_type& lower,
127  const typename container_traits<Tp>::key_type& upper)
128  {
129  except::check_open_bounds(container, lower, upper);
130  return open_bounds
133  (container.key_comp(), lower, upper);
134  }
135 
136  template<typename Ct>
139  <Ct, open_bounds<typename container_traits<Ct>::key_type,
140  typename container_traits<Ct>::key_compare> >
141  {
143 
147  typename container_traits<Ct>::key_compare> >& other)
151  (other) { }
152  };
153 
154  template<typename Ct>
155  struct open_region_iterator<const Ct>
157  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
158  typename container_traits<Ct>::key_compare> >
159  {
161 
164  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
166  other)
170  (other) { }
171 
175  typename container_traits<Ct>::key_compare> >& other)
177  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
179  (other) { }
180  };
181 
182  template<typename Ct>
185  <Ct, open_bounds<typename container_traits<Ct>::key_type,
186  typename container_traits<Ct>::key_compare> >
187  {
189 
193  typename container_traits<Ct>::key_compare> >& a,
194  const region_iterator
196  typename container_traits<Ct>::key_compare> >& b)
198  <Ct, open_bounds<typename container_traits<Ct>::key_type,
200  (a, b) { }
201  };
202 
203  template<typename Ct>
204  struct open_region_iterator_pair<const Ct>
206  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
207  typename container_traits<Ct>::key_compare> >
208  {
210 
213  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
214  typename container_traits<Ct>::key_compare> >& a,
215  const region_iterator
216  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
217  typename container_traits<Ct>::key_compare> >& b)
219  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
221  (a, b) { }
222 
226  typename container_traits<Ct>::key_compare> >& other)
228  <const Ct, open_bounds<typename container_traits<Ct>::key_type,
230  (other) { }
231  };
232 
233  template <typename Ct>
234  inline open_region_iterator<Ct>
235  open_region_end(Ct& container,
236  const typename container_traits<Ct>::key_type& lower,
237  const typename container_traits<Ct>::key_type& upper)
238  { return region_end(container, make_open_bounds(container, lower, upper)); }
239 
240  template <typename Ct>
241  inline open_region_iterator<const Ct>
242  open_region_end(const Ct& container,
243  const typename container_traits<Ct>::key_type& lower,
244  const typename container_traits<Ct>::key_type& upper)
245  { return region_end(container, make_open_bounds(container, lower, upper)); }
246 
247  template <typename Ct>
248  inline open_region_iterator<const Ct>
249  open_region_cend(const Ct& container,
250  const typename container_traits<Ct>::key_type& lower,
251  const typename container_traits<Ct>::key_type& upper)
252  { return region_cend(container, make_open_bounds(container, lower, upper)); }
253 
254  template <typename Ct>
255  inline open_region_iterator<Ct>
256  open_region_begin(Ct& container,
257  const typename container_traits<Ct>::key_type& lower,
258  const typename container_traits<Ct>::key_type& upper)
259  { return region_begin(container, make_open_bounds(container, lower, upper)); }
260 
261  template <typename Ct>
262  inline open_region_iterator<const Ct>
263  open_region_begin(const Ct& container,
264  const typename container_traits<Ct>::key_type& lower,
265  const typename container_traits<Ct>::key_type& upper)
266  { return region_begin(container, make_open_bounds(container, lower, upper)); }
267 
268  template <typename Ct>
269  inline open_region_iterator<const Ct>
270  open_region_cbegin(const Ct& container,
271  const typename container_traits<Ct>::key_type& lower,
272  const typename container_traits<Ct>::key_type& upper)
273  {
274  return region_cbegin(container, make_open_bounds(container, lower, upper));
275  }
276 
277  template <typename Ct>
278  inline open_region_iterator_pair<Ct>
279  open_region_range(Ct& container,
280  const typename container_traits<Ct>::key_type& lower,
281  const typename container_traits<Ct>::key_type& upper)
282  { return region_range(container, make_open_bounds(container, lower, upper)); }
283 
284  template <typename Ct>
285  inline open_region_iterator_pair<const Ct>
286  open_region_range(const Ct& container,
287  const typename container_traits<Ct>::key_type& lower,
288  const typename container_traits<Ct>::key_type& upper)
289  { return region_range(container, make_open_bounds(container, lower, upper)); }
290 
291  template <typename Ct>
292  inline open_region_iterator_pair<const Ct>
293  open_region_crange(const Ct& container,
294  const typename container_traits<Ct>::key_type& lower,
295  const typename container_traits<Ct>::key_type& upper)
296  {
297  return region_crange(container, make_open_bounds(container, lower, upper));
298  }
299 
300 } // namespace spatial
301 
302 #endif // SPATIAL_OPEN_REGION_HPP
This type provides both an iterator and a constant iterator to iterate through all elements of a tree...
A model of Region Predicate that checks if a value of type Key is contained within the open boundarie...
void check_open_bounds(const Tp &container, const typename container_traits< Tp >::key_type &lower, const typename container_traits< Tp >::key_type &upper)
Checks if all coordinates of lower are strictly less than these of higher along the same dimensions...
Tp::key_compare key_compare
Comparison functor used to compare two instances of key_type.
Definition: traits.hpp:98
open_region_iterator< const Ct > open_region_cend(const Ct &container, const typename container_traits< Ct >::key_type &lower, const typename container_traits< Ct >::key_type &upper)
open_region_iterator< Ct > open_region_end(Ct &container, const typename container_traits< Ct >::key_type &lower, const typename container_traits< Ct >::key_type &upper)
region_iterator< const Ct, Predicate > region_cend(const Ct &container, const Predicate &pred)
This structure defines a pair of mutable region iterator.
Tp::key_type key_type
The type representing the key managed by the container.
Definition: traits.hpp:48
open_region_iterator< const Ct > open_region_cbegin(const Ct &container, const typename container_traits< Ct >::key_type &lower, const typename container_traits< Ct >::key_type &upper)
open_region_iterator_pair< Ct > open_region_range(Ct &container, const typename container_traits< Ct >::key_type &lower, const typename container_traits< Ct >::key_type &upper)
Key _upper
The upper bound for the orthogonal region iterator.
region_iterator< Ct, Predicate > region_begin(Ct &container, const Predicate &pred)
open_bounds()
The default constructor leaves everything un-initialized.
region_iterator_pair< Ct, Predicate > region_range(Ct &container, const Predicate &pred)
Returns a spatial::region_iterator_pair where first points to the first element matching the predicat...
open_region_iterator< Ct > open_region_begin(Ct &container, const typename container_traits< Ct >::key_type &lower, const typename container_traits< Ct >::key_type &upper)
The traits type for all containers in the spatial namespace.
Definition: traits.hpp:42
region_iterator< const Ct, Predicate > region_cbegin(const Ct &container, const Predicate &pred)
relative_order
Defines values for relative ordering.
Definition: spatial.hpp:81
std::size_t dimension_type
Defines the type for the dimension as being a size.
Definition: spatial.hpp:71
region_iterator< Ct, Predicate > region_end(Ct &container, const Predicate &pred)
Key _lower
The lower bound for the orthogonal region iterator.
The main namespace used in the library.
Definition: algorithm.hpp:23
region_iterator_pair< const Ct, Predicate > region_crange(const Ct &container, const Predicate &pred)
This overload works only on constant containers and will return a set of constant iterators...
open_region_iterator_pair< const Ct > open_region_crange(const Ct &container, const typename container_traits< Ct >::key_type &lower, const typename container_traits< Ct >::key_type &upper)
open_bounds(const Compare &compare, const Key &lower, const Key &upper)
Set the lower and upper boundary for the orthogonal range search in the region.
open_bounds< typename container_traits< Tp >::key_type, typename container_traits< Tp >::key_compare > make_open_bounds(const Tp &container, const typename container_traits< Tp >::key_type &lower, const typename container_traits< Tp >::key_type &upper)
A open_bounds factory that takes in a container, a region defined by lower and upper, and returns a constructed open_bounds object.
relative_order operator()(dimension_type dim, dimension_type, const Key &key) const
The operator that returns wheather the point is in region or not.