GEOS 3.3.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

quadtree/NodeBase.h
1 /**********************************************************************
2 * $Id: NodeBase.h 3255 2011-03-01 17:56:10Z mloskot $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2006 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: index/quadtree/NodeBase.java rev 1.9 (JTS-1.10)
17 *
18 **********************************************************************/
19
20 #ifndef GEOS_IDX_QUADTREE_NODEBASE_H
21 #define GEOS_IDX_QUADTREE_NODEBASE_H
22
23 #include <geos/export.h>
24 #include <vector>
25 #include <string>
26
27 #ifdef _MSC_VER
28 #pragma warning(push)
29 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30 #endif
31
32 // Forward declarations
33 namespace geos {
34 namespace geom {
35 class Coordinate;
36 class Envelope;
37 }
38 namespace index {
39 class ItemVisitor;
40 namespace quadtree {
41 class Node;
42 }
43 }
44 }
45
46 namespace geos {
47 namespace index { // geos::index
48 namespace quadtree { // geos::index::quadtree
49
55 class GEOS_DLL NodeBase {
56
57 private:
58
59 void visitItems(const geom::Envelope* searchEnv,
60 ItemVisitor& visitor);
61
62 public:
63
64 static int getSubnodeIndex(const geom::Envelope *env,
65 const geom::Coordinate& centre);
66
67 NodeBase();
68
69 virtual ~NodeBase();
70
71 std::vector<void*>& getItems();
72
75 void add(void* item);
76
78 std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
79
80 virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
81 std::vector<void*>& resultItems) const;
82
83 unsigned int depth() const;
84
85 unsigned int size() const;
86
87 unsigned int getNodeCount() const;
88
89 virtual std::string toString() const;
90
91 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
92
100 bool remove(const geom::Envelope* itemEnv, void* item);
101
102 bool hasItems() const;
103
104 bool hasChildren() const;
105
106 bool isPrunable() const;
107
108 protected:
109
111 std::vector<void*> items;
112
123 Node* subnode[4];
124
125 virtual bool isSearchMatch(const geom::Envelope& searchEnv) const=0;
126 };
127
128
129 // INLINES, To be moved in NodeBase.inl
130
131 inline bool
132 NodeBase::hasChildren() const
133 {
134 for (int i = 0; i < 4; i++)
135 if (subnode[i]) return true;
136 return false;
137 }
138
139 inline bool
140 NodeBase::isPrunable() const
141 {
142 return ! (hasChildren() || hasItems());
143 }
144
145 inline bool
146 NodeBase::hasItems() const
147 {
148 return ! items.empty();
149 }
150
151 } // namespace geos::index::quadtree
152 } // namespace geos::index
153 } // namespace geos
154
155 #ifdef _MSC_VER
156 #pragma warning(pop)
157 #endif
158
159 #endif // GEOS_IDX_QUADTREE_NODEBASE_H
160
161 /**********************************************************************
162 * $Log$
163 * Revision 1.1 2006/03/22 12:22:50 strk
164 * indexQuadtree.h split
165 *
166 **********************************************************************/
167