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