variant_visitor.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Boost.Geometry Index
  2. //
  3. // R-tree nodes static visitor related code
  4. //
  5. // Copyright (c) 2011-2014 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_DETAIL_RTREE_NODE_VARIANT_VISITOR_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_VISITOR_HPP
  12. #include <boost/variant/apply_visitor.hpp>
  13. #include <boost/variant/get.hpp>
  14. #include <boost/variant/variant.hpp>
  15. namespace boost { namespace geometry { namespace index {
  16. namespace detail { namespace rtree {
  17. // nodes variants forward declarations
  18. template <typename Value, typename Parameters, typename Box, typename Allocators, typename Tag>
  19. struct variant_internal_node;
  20. template <typename Value, typename Parameters, typename Box, typename Allocators, typename Tag>
  21. struct variant_leaf;
  22. // nodes conversion
  23. template <typename V, typename Value, typename Parameters, typename Box, typename Allocators, typename Tag>
  24. inline V & get(
  25. boost::variant<
  26. variant_leaf<Value, Parameters, Box, Allocators, Tag>,
  27. variant_internal_node<Value, Parameters, Box, Allocators, Tag>
  28. > & v)
  29. {
  30. return boost::get<V>(v);
  31. }
  32. // apply visitor
  33. template <typename Visitor, typename Value, typename Parameters, typename Box, typename Allocators, typename Tag>
  34. inline void apply_visitor(Visitor & v,
  35. boost::variant<
  36. variant_leaf<Value, Parameters, Box, Allocators, Tag>,
  37. variant_internal_node<Value, Parameters, Box, Allocators, Tag>
  38. > & n)
  39. {
  40. boost::apply_visitor(v, n);
  41. }
  42. template <typename Visitor, typename Value, typename Parameters, typename Box, typename Allocators, typename Tag>
  43. inline void apply_visitor(Visitor & v,
  44. boost::variant<
  45. variant_leaf<Value, Parameters, Box, Allocators, Tag>,
  46. variant_internal_node<Value, Parameters, Box, Allocators, Tag>
  47. > const& n)
  48. {
  49. boost::apply_visitor(v, n);
  50. }
  51. }} // namespace detail::rtree
  52. }}} // namespace boost::geometry::index
  53. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_VARIANT_VISITOR_HPP