annotate DEPENDENCIES/generic/include/boost/geometry/index/detail/rtree/utilities/print.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost.Geometry Index
Chris@16 2 //
Chris@16 3 // R-tree ostreaming visitor implementation
Chris@16 4 //
Chris@16 5 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
Chris@16 6 //
Chris@16 7 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 9 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 10
Chris@16 11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_PRINT_HPP
Chris@16 12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_PRINT_HPP
Chris@16 13
Chris@16 14 #include <iostream>
Chris@16 15
Chris@16 16 namespace boost { namespace geometry { namespace index { namespace detail {
Chris@16 17
Chris@16 18 namespace utilities {
Chris@16 19
Chris@16 20 namespace dispatch {
Chris@16 21
Chris@16 22 template <typename Point, size_t Dimension>
Chris@16 23 struct print_point
Chris@16 24 {
Chris@16 25 BOOST_STATIC_ASSERT(0 < Dimension);
Chris@16 26
Chris@16 27 static inline void apply(std::ostream & os, Point const& p)
Chris@16 28 {
Chris@16 29 print_point<Point, Dimension - 1>::apply(os, p);
Chris@16 30
Chris@16 31 os << ", " << geometry::get<Dimension - 1>(p);
Chris@16 32 }
Chris@16 33 };
Chris@16 34
Chris@16 35 template <typename Point>
Chris@16 36 struct print_point<Point, 1>
Chris@16 37 {
Chris@16 38 static inline void apply(std::ostream & os, Point const& p)
Chris@16 39 {
Chris@16 40 os << geometry::get<0>(p);
Chris@16 41 }
Chris@16 42 };
Chris@16 43
Chris@16 44 template <typename Box, size_t Corner, size_t Dimension>
Chris@16 45 struct print_corner
Chris@16 46 {
Chris@16 47 BOOST_STATIC_ASSERT(0 < Dimension);
Chris@16 48
Chris@16 49 static inline void apply(std::ostream & os, Box const& b)
Chris@16 50 {
Chris@16 51 print_corner<Box, Corner, Dimension - 1>::apply(os, b);
Chris@16 52
Chris@16 53 os << ", " << geometry::get<Corner, Dimension - 1>(b);
Chris@16 54 }
Chris@16 55 };
Chris@16 56
Chris@16 57 template <typename Box, size_t Corner>
Chris@16 58 struct print_corner<Box, Corner, 1>
Chris@16 59 {
Chris@16 60 static inline void apply(std::ostream & os, Box const& b)
Chris@16 61 {
Chris@16 62 os << geometry::get<Corner, 0>(b);
Chris@16 63 }
Chris@16 64 };
Chris@16 65
Chris@16 66 template <typename Indexable, typename Tag>
Chris@16 67 struct print_indexable
Chris@16 68 {
Chris@101 69 BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_TAG, (Tag));
Chris@16 70 };
Chris@16 71
Chris@16 72 template <typename Indexable>
Chris@16 73 struct print_indexable<Indexable, box_tag>
Chris@16 74 {
Chris@16 75 static const size_t dimension = geometry::dimension<Indexable>::value;
Chris@16 76
Chris@16 77 static inline void apply(std::ostream &os, Indexable const& i)
Chris@16 78 {
Chris@16 79 os << '(';
Chris@16 80 print_corner<Indexable, min_corner, dimension>::apply(os, i);
Chris@16 81 os << ")x(";
Chris@16 82 print_corner<Indexable, max_corner, dimension>::apply(os, i);
Chris@16 83 os << ')';
Chris@16 84 }
Chris@16 85 };
Chris@16 86
Chris@16 87 template <typename Indexable>
Chris@16 88 struct print_indexable<Indexable, point_tag>
Chris@16 89 {
Chris@16 90 static const size_t dimension = geometry::dimension<Indexable>::value;
Chris@16 91
Chris@16 92 static inline void apply(std::ostream &os, Indexable const& i)
Chris@16 93 {
Chris@16 94 os << '(';
Chris@16 95 print_point<Indexable, dimension>::apply(os, i);
Chris@16 96 os << ')';
Chris@16 97 }
Chris@16 98 };
Chris@16 99
Chris@101 100 template <typename Indexable>
Chris@101 101 struct print_indexable<Indexable, segment_tag>
Chris@101 102 {
Chris@101 103 static const size_t dimension = geometry::dimension<Indexable>::value;
Chris@101 104
Chris@101 105 static inline void apply(std::ostream &os, Indexable const& i)
Chris@101 106 {
Chris@101 107 os << '(';
Chris@101 108 print_corner<Indexable, 0, dimension>::apply(os, i);
Chris@101 109 os << ")-(";
Chris@101 110 print_corner<Indexable, 1, dimension>::apply(os, i);
Chris@101 111 os << ')';
Chris@101 112 }
Chris@101 113 };
Chris@101 114
Chris@16 115 } // namespace dispatch
Chris@16 116
Chris@16 117 template <typename Indexable> inline
Chris@16 118 void print_indexable(std::ostream & os, Indexable const& i)
Chris@16 119 {
Chris@16 120 dispatch::print_indexable<
Chris@16 121 Indexable,
Chris@16 122 typename tag<Indexable>::type
Chris@16 123 >::apply(os, i);
Chris@16 124 }
Chris@16 125
Chris@16 126 } // namespace utilities
Chris@16 127
Chris@16 128 namespace rtree { namespace utilities {
Chris@16 129
Chris@16 130 namespace visitors {
Chris@16 131
Chris@16 132 template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
Chris@16 133 struct print : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
Chris@16 134 {
Chris@16 135 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
Chris@16 136 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
Chris@16 137
Chris@16 138 inline print(std::ostream & o, Translator const& t)
Chris@16 139 : os(o), tr(t), level(0)
Chris@16 140 {}
Chris@16 141
Chris@16 142 inline void operator()(internal_node const& n)
Chris@16 143 {
Chris@16 144 typedef typename rtree::elements_type<internal_node>::type elements_type;
Chris@16 145 elements_type const& elements = rtree::elements(n);
Chris@16 146
Chris@16 147 spaces(level) << "INTERNAL NODE - L:" << level << " Ch:" << elements.size() << " @:" << &n << '\n';
Chris@16 148
Chris@16 149 for (typename elements_type::const_iterator it = elements.begin();
Chris@16 150 it != elements.end(); ++it)
Chris@16 151 {
Chris@16 152 spaces(level);
Chris@16 153 detail::utilities::print_indexable(os, it->first);
Chris@16 154 os << " ->" << it->second << '\n';
Chris@16 155 }
Chris@16 156
Chris@16 157 size_t level_backup = level;
Chris@16 158 ++level;
Chris@16 159
Chris@16 160 for (typename elements_type::const_iterator it = elements.begin();
Chris@16 161 it != elements.end(); ++it)
Chris@16 162 {
Chris@16 163 rtree::apply_visitor(*this, *it->second);
Chris@16 164 }
Chris@16 165
Chris@16 166 level = level_backup;
Chris@16 167 }
Chris@16 168
Chris@16 169 inline void operator()(leaf const& n)
Chris@16 170 {
Chris@16 171 typedef typename rtree::elements_type<leaf>::type elements_type;
Chris@16 172 elements_type const& elements = rtree::elements(n);
Chris@16 173
Chris@16 174 spaces(level) << "LEAF - L:" << level << " V:" << elements.size() << " @:" << &n << '\n';
Chris@16 175 for (typename elements_type::const_iterator it = elements.begin();
Chris@16 176 it != elements.end(); ++it)
Chris@16 177 {
Chris@16 178 spaces(level);
Chris@16 179 detail::utilities::print_indexable(os, tr(*it));
Chris@16 180 os << '\n';
Chris@16 181 }
Chris@16 182 }
Chris@16 183
Chris@16 184 inline std::ostream & spaces(size_t level)
Chris@16 185 {
Chris@16 186 for ( size_t i = 0 ; i < 2 * level ; ++i )
Chris@16 187 os << ' ';
Chris@16 188 return os;
Chris@16 189 }
Chris@16 190
Chris@16 191 std::ostream & os;
Chris@16 192 Translator const& tr;
Chris@16 193
Chris@16 194 size_t level;
Chris@16 195 };
Chris@16 196
Chris@16 197 } // namespace visitors
Chris@16 198
Chris@16 199 template <typename Rtree> inline
Chris@16 200 void print(std::ostream & os, Rtree const& tree)
Chris@16 201 {
Chris@16 202 typedef utilities::view<Rtree> RTV;
Chris@16 203 RTV rtv(tree);
Chris@16 204
Chris@16 205 visitors::print<
Chris@16 206 typename RTV::value_type,
Chris@16 207 typename RTV::options_type,
Chris@16 208 typename RTV::translator_type,
Chris@16 209 typename RTV::box_type,
Chris@16 210 typename RTV::allocators_type
Chris@16 211 > print_v(os, rtv.translator());
Chris@16 212 rtv.apply_visitor(print_v);
Chris@16 213 }
Chris@16 214
Chris@16 215 }} // namespace rtree::utilities
Chris@16 216
Chris@16 217 }}}} // namespace boost::geometry::index::detail
Chris@16 218
Chris@16 219 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_PRINT_HPP