query.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Boost.Geometry Index
  2. //
  3. // Query range adaptor
  4. //
  5. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_INDEX_ADAPTORS_QUERY_HPP
  11. #define BOOST_GEOMETRY_INDEX_ADAPTORS_QUERY_HPP
  12. /*!
  13. \defgroup adaptors Adaptors (boost::geometry::index::adaptors::)
  14. */
  15. namespace boost { namespace geometry { namespace index {
  16. namespace adaptors {
  17. namespace detail {
  18. template <typename Index>
  19. class query_range
  20. {
  21. BOOST_MPL_ASSERT_MSG(
  22. (false),
  23. NOT_IMPLEMENTED_FOR_THIS_INDEX,
  24. (query_range));
  25. typedef int* iterator;
  26. typedef const int* const_iterator;
  27. template <typename Predicates>
  28. inline query_range(
  29. Index const&,
  30. Predicates const&)
  31. {}
  32. inline iterator begin() { return 0; }
  33. inline iterator end() { return 0; }
  34. inline const_iterator begin() const { return 0; }
  35. inline const_iterator end() const { return 0; }
  36. };
  37. // TODO: awulkiew - consider removing reference from predicates
  38. template<typename Predicates>
  39. struct query
  40. {
  41. inline explicit query(Predicates const& pred)
  42. : predicates(pred)
  43. {}
  44. Predicates const& predicates;
  45. };
  46. template<typename Index, typename Predicates>
  47. index::adaptors::detail::query_range<Index>
  48. operator|(
  49. Index const& si,
  50. index::adaptors::detail::query<Predicates> const& f)
  51. {
  52. return index::adaptors::detail::query_range<Index>(si, f.predicates);
  53. }
  54. } // namespace detail
  55. /*!
  56. \brief The query index adaptor generator.
  57. \ingroup adaptors
  58. \param pred Predicates.
  59. */
  60. template <typename Predicates>
  61. detail::query<Predicates>
  62. queried(Predicates const& pred)
  63. {
  64. return detail::query<Predicates>(pred);
  65. }
  66. } // namespace adaptors
  67. }}} // namespace boost::geometry::index
  68. #endif // BOOST_GEOMETRY_INDEX_ADAPTORS_QUERY_HPP