MySQL 9.0.0
Source Code Documentation
geometry_visitor.h
Go to the documentation of this file.
1#ifndef SQL_GIS_GEOMETRY_VISITOR_H_INCLUDED
2#define SQL_GIS_GEOMETRY_VISITOR_H_INCLUDED
3
4// Copyright (c) 2017, 2024, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is designed to work with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27/// @file
28///
29/// The geometries implement a hierarchical visitor pattern. This file declares
30/// the interface for visitors.
31
32#include "sql/gis/geometries.h"
33
34namespace gis {
35
36/// Abstract visitor class to be used on class Geometry and descendants.
37///
38/// A visitor will visit all elements of a compound geometry, always going down
39/// to each point unless the geometry is empty. E.g., when visiting a
40/// linestring, the visitor will descend into each point of the linestring.
41///
42/// The visitor can abort execution at any time. This is done by returning true
43/// from a visit() or visit_leave() function. If these functions return false,
44/// execution will continue. The accept() member function on geometries returns
45/// true if the visitor aborted execution and false otherwise.
47 public:
48 Geometry_visitor() = default;
49 virtual ~Geometry_visitor() = default;
50
51 /// Enters a compound geometry.
52 ///
53 /// This is called on entry to a compound geometry, i.e., all
54 /// geometries except points.
55 ///
56 /// @param g The geometry to visit.
57 ///
58 /// @retval true Don't descend into children.
59 /// @retval false Descend into children.
60 virtual bool visit_enter(Geometry *g) = 0;
61 virtual bool visit_enter(Curve *) = 0;
62 virtual bool visit_enter(Linestring *) = 0;
63 virtual bool visit_enter(Linearring *) = 0;
64 virtual bool visit_enter(Surface *) = 0;
65 virtual bool visit_enter(Polygon *) = 0;
66 virtual bool visit_enter(Geometrycollection *) = 0;
67 virtual bool visit_enter(Multipoint *) = 0;
68 virtual bool visit_enter(Multicurve *) = 0;
69 virtual bool visit_enter(Multilinestring *) = 0;
70 virtual bool visit_enter(Multisurface *) = 0;
71 virtual bool visit_enter(Multipolygon *) = 0;
72
73 /// Visits a geometry.
74 ///
75 /// This is called on each non-compound geometry and between visiting
76 /// descendants. E.g., visit(Linestring *) will be called after visiting the
77 /// first point in the linestring, then after visiting the second, etc., but
78 /// not after visiting the last point.
79 ///
80 /// @param g The geometry to visit.
81 ///
82 /// @retval true Abort visitor execution.
83 /// @retval false Continue visitor execution.
84 virtual bool visit(Geometry *g) = 0;
85 virtual bool visit(Point *) = 0;
86 virtual bool visit(Curve *) = 0;
87 virtual bool visit(Linestring *) = 0;
88 virtual bool visit(Linearring *) = 0;
89 virtual bool visit(Surface *) = 0;
90 virtual bool visit(Polygon *) = 0;
91 virtual bool visit(Geometrycollection *) = 0;
92 virtual bool visit(Multipoint *) = 0;
93 virtual bool visit(Multicurve *) = 0;
94 virtual bool visit(Multilinestring *) = 0;
95 virtual bool visit(Multisurface *) = 0;
96 virtual bool visit(Multipolygon *) = 0;
97
98 /// Leaves a compound geometry.
99 ///
100 /// Called after visiting the last child of a compound geometry. The return
101 /// value is returned to the accept() function.
102 ///
103 /// @param g The geometry to visit.
104 ///
105 /// @retval true Abort visitor execution.
106 /// @retval false Continue visitor execution.
107 virtual bool visit_leave(Geometry *g) = 0;
108 virtual bool visit_leave(Curve *) = 0;
109 virtual bool visit_leave(Linestring *) = 0;
110 virtual bool visit_leave(Linearring *) = 0;
111 virtual bool visit_leave(Surface *) = 0;
112 virtual bool visit_leave(Polygon *) = 0;
113 virtual bool visit_leave(Geometrycollection *) = 0;
114 virtual bool visit_leave(Multipoint *) = 0;
115 virtual bool visit_leave(Multicurve *) = 0;
116 virtual bool visit_leave(Multilinestring *) = 0;
117 virtual bool visit_leave(Multisurface *) = 0;
118 virtual bool visit_leave(Multipolygon *) = 0;
119};
120
121/// A visitor that implements the entire interface and does nothing.
123 public:
124 bool visit_enter(Geometry *) override { return false; }
125 bool visit_enter(Curve *c) override {
126 return visit_enter(static_cast<Geometry *>(c));
127 }
128 bool visit_enter(Linestring *ls) override {
129 return visit_enter(static_cast<Curve *>(ls));
130 }
131 bool visit_enter(Linearring *lr) override {
132 return visit_enter(static_cast<Linestring *>(lr));
133 }
134 bool visit_enter(Surface *s) override {
135 return visit_enter(static_cast<Geometry *>(s));
136 }
137 bool visit_enter(Polygon *py) override {
138 return visit_enter(static_cast<Surface *>(py));
139 }
140 bool visit_enter(Geometrycollection *gc) override {
141 return visit_enter(static_cast<Geometry *>(gc));
142 }
143 bool visit_enter(Multipoint *mpt) override {
144 return visit_enter(static_cast<Geometrycollection *>(mpt));
145 }
146 bool visit_enter(Multicurve *mc) override {
147 return visit_enter(static_cast<Geometrycollection *>(mc));
148 }
149 bool visit_enter(Multilinestring *mls) override {
150 return visit_enter(static_cast<Multicurve *>(mls));
151 }
152 bool visit_enter(Multisurface *ms) override {
153 return visit_enter(static_cast<Geometrycollection *>(ms));
154 }
155 bool visit_enter(Multipolygon *mpy) override {
156 return visit_enter(static_cast<Multisurface *>(mpy));
157 }
158
159 bool visit(Geometry *) override { return false; }
160 bool visit(Point *pt) override { return visit(static_cast<Geometry *>(pt)); }
161 bool visit(Curve *c) override { return visit(static_cast<Geometry *>(c)); }
162 bool visit(Linestring *ls) override {
163 return visit(static_cast<Curve *>(ls));
164 }
165 bool visit(Linearring *lr) override {
166 return visit(static_cast<Linestring *>(lr));
167 }
168 bool visit(Surface *s) override { return visit(static_cast<Geometry *>(s)); }
169 bool visit(Polygon *py) override { return visit(static_cast<Surface *>(py)); }
170 bool visit(Geometrycollection *gc) override {
171 return visit(static_cast<Geometry *>(gc));
172 }
173 bool visit(Multipoint *mpt) override {
174 return visit(static_cast<Geometrycollection *>(mpt));
175 }
176 bool visit(Multicurve *mc) override {
177 return visit(static_cast<Geometrycollection *>(mc));
178 }
179 bool visit(Multilinestring *mls) override {
180 return visit(static_cast<Multicurve *>(mls));
181 }
182 bool visit(Multisurface *ms) override {
183 return visit(static_cast<Geometrycollection *>(ms));
184 }
185 bool visit(Multipolygon *mpy) override {
186 return visit(static_cast<Multisurface *>(mpy));
187 }
188
189 bool visit_leave(Geometry *) override { return false; }
190 bool visit_leave(Curve *c) override {
191 return visit_leave(static_cast<Geometry *>(c));
192 }
193 bool visit_leave(Linestring *ls) override {
194 return visit_leave(static_cast<Curve *>(ls));
195 }
196 bool visit_leave(Linearring *lr) override {
197 return visit_leave(static_cast<Linestring *>(lr));
198 }
199 bool visit_leave(Surface *s) override {
200 return visit_leave(static_cast<Geometry *>(s));
201 }
202 bool visit_leave(Polygon *py) override {
203 return visit_leave(static_cast<Surface *>(py));
204 }
205 bool visit_leave(Geometrycollection *gc) override {
206 return visit_leave(static_cast<Geometry *>(gc));
207 }
208 bool visit_leave(Multipoint *mpt) override {
209 return visit_leave(static_cast<Geometrycollection *>(mpt));
210 }
211 bool visit_leave(Multicurve *mc) override {
212 return visit_leave(static_cast<Geometrycollection *>(mc));
213 }
214 bool visit_leave(Multilinestring *mls) override {
215 return visit_leave(static_cast<Multicurve *>(mls));
216 }
217 bool visit_leave(Multisurface *ms) override {
218 return visit_leave(static_cast<Geometrycollection *>(ms));
219 }
220 bool visit_leave(Multipolygon *mpy) override {
221 return visit_leave(static_cast<Multisurface *>(mpy));
222 }
223};
224
225} // namespace gis
226
227#endif // SQL_GIS_GEOMETRY_VISITOR_H_INCLUDED
An abstract 2d curve.
Definition: geometries.h:242
Abstract visitor class to be used on class Geometry and descendants.
Definition: geometry_visitor.h:46
virtual bool visit_leave(Polygon *)=0
virtual bool visit(Linestring *)=0
virtual bool visit_leave(Linestring *)=0
virtual bool visit_leave(Multipoint *)=0
virtual bool visit_leave(Multipolygon *)=0
virtual bool visit_enter(Multilinestring *)=0
virtual bool visit_enter(Multicurve *)=0
virtual bool visit_enter(Polygon *)=0
virtual bool visit_enter(Multisurface *)=0
virtual bool visit_leave(Surface *)=0
virtual bool visit_leave(Multilinestring *)=0
virtual bool visit_enter(Curve *)=0
virtual bool visit_leave(Multicurve *)=0
virtual bool visit(Linearring *)=0
virtual bool visit_leave(Multisurface *)=0
virtual bool visit(Multipolygon *)=0
virtual bool visit_enter(Linestring *)=0
virtual bool visit_leave(Geometry *g)=0
Leaves a compound geometry.
virtual ~Geometry_visitor()=default
virtual bool visit(Point *)=0
virtual bool visit_enter(Surface *)=0
virtual bool visit(Multisurface *)=0
virtual bool visit_enter(Geometrycollection *)=0
virtual bool visit_leave(Linearring *)=0
virtual bool visit_leave(Curve *)=0
virtual bool visit(Geometrycollection *)=0
virtual bool visit_enter(Linearring *)=0
virtual bool visit(Polygon *)=0
virtual bool visit(Multilinestring *)=0
virtual bool visit(Multipoint *)=0
virtual bool visit(Surface *)=0
virtual bool visit(Curve *)=0
virtual bool visit_enter(Geometry *g)=0
Enters a compound geometry.
Geometry_visitor()=default
virtual bool visit_leave(Geometrycollection *)=0
virtual bool visit_enter(Multipoint *)=0
virtual bool visit_enter(Multipolygon *)=0
virtual bool visit(Multicurve *)=0
virtual bool visit(Geometry *g)=0
Visits a geometry.
Abstract superclass for all geometric objects.
Definition: geometries.h:100
A collection of geometries.
Definition: geometries.h:410
A ring-shaped linestring.
Definition: geometries.h:320
A string of connected line segments.
Definition: geometries.h:256
An abstract collection of curves.
Definition: geometries.h:514
A collection of linestrings.
Definition: geometries.h:523
A collection of points.
Definition: geometries.h:484
A collection of polygons.
Definition: geometries.h:564
An abstract collection of surfaces.
Definition: geometries.h:555
A visitor that implements the entire interface and does nothing.
Definition: geometry_visitor.h:122
bool visit_enter(Linearring *lr) override
Definition: geometry_visitor.h:131
bool visit_enter(Multilinestring *mls) override
Definition: geometry_visitor.h:149
bool visit_leave(Multipolygon *mpy) override
Definition: geometry_visitor.h:220
bool visit_enter(Geometrycollection *gc) override
Definition: geometry_visitor.h:140
bool visit_leave(Multisurface *ms) override
Definition: geometry_visitor.h:217
bool visit_enter(Multicurve *mc) override
Definition: geometry_visitor.h:146
bool visit(Linearring *lr) override
Definition: geometry_visitor.h:165
bool visit_leave(Curve *c) override
Definition: geometry_visitor.h:190
bool visit_enter(Polygon *py) override
Definition: geometry_visitor.h:137
bool visit_leave(Multicurve *mc) override
Definition: geometry_visitor.h:211
bool visit_enter(Multipolygon *mpy) override
Definition: geometry_visitor.h:155
bool visit_enter(Surface *s) override
Definition: geometry_visitor.h:134
bool visit_leave(Geometry *) override
Leaves a compound geometry.
Definition: geometry_visitor.h:189
bool visit_enter(Geometry *) override
Enters a compound geometry.
Definition: geometry_visitor.h:124
bool visit(Multipoint *mpt) override
Definition: geometry_visitor.h:173
bool visit_leave(Linearring *lr) override
Definition: geometry_visitor.h:196
bool visit(Linestring *ls) override
Definition: geometry_visitor.h:162
bool visit_leave(Multipoint *mpt) override
Definition: geometry_visitor.h:208
bool visit_leave(Polygon *py) override
Definition: geometry_visitor.h:202
bool visit(Point *pt) override
Definition: geometry_visitor.h:160
bool visit(Multicurve *mc) override
Definition: geometry_visitor.h:176
bool visit(Surface *s) override
Definition: geometry_visitor.h:168
bool visit(Geometry *) override
Visits a geometry.
Definition: geometry_visitor.h:159
bool visit(Polygon *py) override
Definition: geometry_visitor.h:169
bool visit_leave(Multilinestring *mls) override
Definition: geometry_visitor.h:214
bool visit(Multilinestring *mls) override
Definition: geometry_visitor.h:179
bool visit(Multipolygon *mpy) override
Definition: geometry_visitor.h:185
bool visit_leave(Surface *s) override
Definition: geometry_visitor.h:199
bool visit(Multisurface *ms) override
Definition: geometry_visitor.h:182
bool visit_enter(Linestring *ls) override
Definition: geometry_visitor.h:128
bool visit_leave(Geometrycollection *gc) override
Definition: geometry_visitor.h:205
bool visit_enter(Curve *c) override
Definition: geometry_visitor.h:125
bool visit_enter(Multisurface *ms) override
Definition: geometry_visitor.h:152
bool visit(Curve *c) override
Definition: geometry_visitor.h:161
bool visit(Geometrycollection *gc) override
Definition: geometry_visitor.h:170
bool visit_enter(Multipoint *mpt) override
Definition: geometry_visitor.h:143
bool visit_leave(Linestring *ls) override
Definition: geometry_visitor.h:193
A 2d point.
Definition: geometries.h:150
A polygon consisting of an outer ring and zero or more interior rings defining holes in the polygon.
Definition: geometries.h:349
An abstract 2d surface.
Definition: geometries.h:335
This file declares the geometry class hierarchy used by the server as the internal representation of ...
Definition: area.cc:47
plugin_messages_callback mc
Definition: webauthn_client_plugin.cc:55