7#include "mdds/global.hpp"
11#include <boost/intrusive_ptr.hpp>
15#ifdef MDDS_DEBUG_NODE_BASE
16size_t node_instance_count = 0;
17inline size_t get_node_instance_count()
19 return node_instance_count;
44enum search_region_space_t
74inline node_quadrant_t opposite(node_quadrant_t quad)
79 return quad_southwest;
81 return quad_southeast;
83 return quad_northwest;
85 return quad_northeast;
86 case quad_unspecified:
89 return quad_unspecified;
92template<
typename _NodePtr,
typename _NodeType,
typename _Key>
95 typedef _Key key_type;
96 typedef _NodePtr node_ptr;
97 typedef _NodeType node_type;
110 quad_node_base(key_type _x, key_type _y)
111 : refcount(0), parent(
nullptr), northeast(
nullptr), northwest(
nullptr), southeast(
nullptr), southwest(
nullptr),
114#ifdef MDDS_DEBUG_NODE_BASE
115 ++node_instance_count;
124 : refcount(0), parent(nullptr), northeast(nullptr), northwest(nullptr), southeast(nullptr), southwest(nullptr),
127#ifdef MDDS_DEBUG_NODE_BASE
128 ++node_instance_count;
134 return !northeast && !northwest && !southeast && !southwest;
137 bool operator==(
const quad_node_base& r)
const
139 return x == r.x && y == r.y;
158#ifdef MDDS_DEBUG_NODE_BASE
159 --node_instance_count;
161 static_cast<node_type*
>(
this)->dispose();
174 return other_y < y ? quad_northwest : quad_southwest;
177 return other_y < y ? quad_northeast : quad_southeast;
180 bool has_quadrant_node(node_quadrant_t quad)
const
185 return northeast.get() !=
nullptr;
187 return northwest.get() !=
nullptr;
189 return southeast.get() !=
nullptr;
191 return southwest.get() !=
nullptr;
198 node_ptr get_quadrant_node(node_quadrant_t quad)
const
216 throw general_error(
"unknown quadrant type");
222template<
typename _NodePtr,
typename _NodeType,
typename _Key>
223inline void intrusive_ptr_add_ref(::mdds::quad_node_base<_NodePtr, _NodeType, _Key>* p)
228template<
typename _NodePtr,
typename _NodeType,
typename _Key>
229inline void intrusive_ptr_release(::mdds::quad_node_base<_NodePtr, _NodeType, _Key>* p)
236template<
typename _NodePtr>
237void disconnect_node_from_parent(_NodePtr p)
239 if (!p || !p->parent)
243 _NodePtr& parent = p->parent;
244 if (parent->northeast && parent->northeast == p)
246 parent->northeast.reset();
248 else if (parent->northwest && parent->northwest == p)
250 parent->northwest.reset();
252 else if (parent->southwest && parent->southwest == p)
254 parent->southwest.reset();
256 else if (parent->southeast && parent->southeast == p)
258 parent->southeast.reset();
261 throw general_error(
"parent node doesn't lead to the deleted node.");
264template<
typename _NodePtr>
265void disconnect_all_nodes(_NodePtr p)
272 disconnect_all_nodes(p->northeast);
273 p->northeast.reset();
278 disconnect_all_nodes(p->northwest);
279 p->northwest.reset();
284 disconnect_all_nodes(p->southeast);
285 p->southeast.reset();
290 disconnect_all_nodes(p->southwest);
291 p->southwest.reset();
297template<
typename _NodeType,
typename _Key>
298search_region_space_t get_search_region_space(_NodeType* p, _Key x1, _Key y1, _Key x2, _Key y2)
300 typedef _Key key_type;
302 key_type x = p->x, y = p->y;
308 return region_northwest;
310 else if (y1 <= y && y <= y2)
316 return region_southwest;
318 else if (x1 <= x && x <= x2)
325 else if (y1 <= y && y <= y2)
327 return region_center;
338 return region_northeast;
340 else if (y1 <= y && y <= y2)
346 return region_southeast;
Definition quad_node.hpp:94
quad_node_base(const quad_node_base &r)
Definition quad_node.hpp:123
quad_node_base & operator=(const quad_node_base &r)
Definition quad_node.hpp:145
node_quadrant_t get_quadrant(key_type other_x, key_type other_y) const
Definition quad_node.hpp:170