File: geometry_visitor.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (227 lines) | stat: -rw-r--r-- 8,680 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#ifndef SQL_GIS_GEOMETRY_VISITOR_H_INCLUDED
#define SQL_GIS_GEOMETRY_VISITOR_H_INCLUDED

// Copyright (c) 2017, 2025, Oracle and/or its affiliates.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, version 2.0,
// as published by the Free Software Foundation.
//
// This program is designed to work with certain software (including
// but not limited to OpenSSL) that is licensed under separate terms,
// as designated in a particular file or component or in included license
// documentation.  The authors of MySQL hereby grant you an additional
// permission to link the program and your derivative works with the
// separately licensed software that they have either included with
// the program or referenced in the documentation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License, version 2.0, for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.

/// @file
///
/// The geometries implement a hierarchical visitor pattern. This file declares
/// the interface for visitors.

#include "sql/gis/geometries.h"

namespace gis {

/// Abstract visitor class to be used on class Geometry and descendants.
///
/// A visitor will visit all elements of a compound geometry, always going down
/// to each point unless the geometry is empty. E.g., when visiting a
/// linestring, the visitor will descend into each point of the linestring.
///
/// The visitor can abort execution at any time. This is done by returning true
/// from a visit() or visit_leave() function. If these functions return false,
/// execution will continue. The accept() member function on geometries returns
/// true if the visitor aborted execution and false otherwise.
class Geometry_visitor {
 public:
  Geometry_visitor() = default;
  virtual ~Geometry_visitor() = default;

  /// Enters a compound geometry.
  ///
  /// This is called on entry to a compound geometry, i.e., all
  /// geometries except points.
  ///
  /// @param g The geometry to visit.
  ///
  /// @retval true Don't descend into children.
  /// @retval false Descend into children.
  virtual bool visit_enter(Geometry *g) = 0;
  virtual bool visit_enter(Curve *) = 0;
  virtual bool visit_enter(Linestring *) = 0;
  virtual bool visit_enter(Linearring *) = 0;
  virtual bool visit_enter(Surface *) = 0;
  virtual bool visit_enter(Polygon *) = 0;
  virtual bool visit_enter(Geometrycollection *) = 0;
  virtual bool visit_enter(Multipoint *) = 0;
  virtual bool visit_enter(Multicurve *) = 0;
  virtual bool visit_enter(Multilinestring *) = 0;
  virtual bool visit_enter(Multisurface *) = 0;
  virtual bool visit_enter(Multipolygon *) = 0;

  /// Visits a geometry.
  ///
  /// This is called on each non-compound geometry and between visiting
  /// descendants. E.g., visit(Linestring *) will be called after visiting the
  /// first point in the linestring, then after visiting the second, etc., but
  /// not after visiting the last point.
  ///
  /// @param g The geometry to visit.
  ///
  /// @retval true Abort visitor execution.
  /// @retval false Continue visitor execution.
  virtual bool visit(Geometry *g) = 0;
  virtual bool visit(Point *) = 0;
  virtual bool visit(Curve *) = 0;
  virtual bool visit(Linestring *) = 0;
  virtual bool visit(Linearring *) = 0;
  virtual bool visit(Surface *) = 0;
  virtual bool visit(Polygon *) = 0;
  virtual bool visit(Geometrycollection *) = 0;
  virtual bool visit(Multipoint *) = 0;
  virtual bool visit(Multicurve *) = 0;
  virtual bool visit(Multilinestring *) = 0;
  virtual bool visit(Multisurface *) = 0;
  virtual bool visit(Multipolygon *) = 0;

  /// Leaves a compound geometry.
  ///
  /// Called after visiting the last child of a compound geometry. The return
  /// value is returned to the accept() function.
  ///
  /// @param g The geometry to visit.
  ///
  /// @retval true Abort visitor execution.
  /// @retval false Continue visitor execution.
  virtual bool visit_leave(Geometry *g) = 0;
  virtual bool visit_leave(Curve *) = 0;
  virtual bool visit_leave(Linestring *) = 0;
  virtual bool visit_leave(Linearring *) = 0;
  virtual bool visit_leave(Surface *) = 0;
  virtual bool visit_leave(Polygon *) = 0;
  virtual bool visit_leave(Geometrycollection *) = 0;
  virtual bool visit_leave(Multipoint *) = 0;
  virtual bool visit_leave(Multicurve *) = 0;
  virtual bool visit_leave(Multilinestring *) = 0;
  virtual bool visit_leave(Multisurface *) = 0;
  virtual bool visit_leave(Multipolygon *) = 0;
};

/// A visitor that implements the entire interface and does nothing.
class Nop_visitor : public Geometry_visitor {
 public:
  bool visit_enter(Geometry *) override { return false; }
  bool visit_enter(Curve *c) override {
    return visit_enter(static_cast<Geometry *>(c));
  }
  bool visit_enter(Linestring *ls) override {
    return visit_enter(static_cast<Curve *>(ls));
  }
  bool visit_enter(Linearring *lr) override {
    return visit_enter(static_cast<Linestring *>(lr));
  }
  bool visit_enter(Surface *s) override {
    return visit_enter(static_cast<Geometry *>(s));
  }
  bool visit_enter(Polygon *py) override {
    return visit_enter(static_cast<Surface *>(py));
  }
  bool visit_enter(Geometrycollection *gc) override {
    return visit_enter(static_cast<Geometry *>(gc));
  }
  bool visit_enter(Multipoint *mpt) override {
    return visit_enter(static_cast<Geometrycollection *>(mpt));
  }
  bool visit_enter(Multicurve *mc) override {
    return visit_enter(static_cast<Geometrycollection *>(mc));
  }
  bool visit_enter(Multilinestring *mls) override {
    return visit_enter(static_cast<Multicurve *>(mls));
  }
  bool visit_enter(Multisurface *ms) override {
    return visit_enter(static_cast<Geometrycollection *>(ms));
  }
  bool visit_enter(Multipolygon *mpy) override {
    return visit_enter(static_cast<Multisurface *>(mpy));
  }

  bool visit(Geometry *) override { return false; }
  bool visit(Point *pt) override { return visit(static_cast<Geometry *>(pt)); }
  bool visit(Curve *c) override { return visit(static_cast<Geometry *>(c)); }
  bool visit(Linestring *ls) override {
    return visit(static_cast<Curve *>(ls));
  }
  bool visit(Linearring *lr) override {
    return visit(static_cast<Linestring *>(lr));
  }
  bool visit(Surface *s) override { return visit(static_cast<Geometry *>(s)); }
  bool visit(Polygon *py) override { return visit(static_cast<Surface *>(py)); }
  bool visit(Geometrycollection *gc) override {
    return visit(static_cast<Geometry *>(gc));
  }
  bool visit(Multipoint *mpt) override {
    return visit(static_cast<Geometrycollection *>(mpt));
  }
  bool visit(Multicurve *mc) override {
    return visit(static_cast<Geometrycollection *>(mc));
  }
  bool visit(Multilinestring *mls) override {
    return visit(static_cast<Multicurve *>(mls));
  }
  bool visit(Multisurface *ms) override {
    return visit(static_cast<Geometrycollection *>(ms));
  }
  bool visit(Multipolygon *mpy) override {
    return visit(static_cast<Multisurface *>(mpy));
  }

  bool visit_leave(Geometry *) override { return false; }
  bool visit_leave(Curve *c) override {
    return visit_leave(static_cast<Geometry *>(c));
  }
  bool visit_leave(Linestring *ls) override {
    return visit_leave(static_cast<Curve *>(ls));
  }
  bool visit_leave(Linearring *lr) override {
    return visit_leave(static_cast<Linestring *>(lr));
  }
  bool visit_leave(Surface *s) override {
    return visit_leave(static_cast<Geometry *>(s));
  }
  bool visit_leave(Polygon *py) override {
    return visit_leave(static_cast<Surface *>(py));
  }
  bool visit_leave(Geometrycollection *gc) override {
    return visit_leave(static_cast<Geometry *>(gc));
  }
  bool visit_leave(Multipoint *mpt) override {
    return visit_leave(static_cast<Geometrycollection *>(mpt));
  }
  bool visit_leave(Multicurve *mc) override {
    return visit_leave(static_cast<Geometrycollection *>(mc));
  }
  bool visit_leave(Multilinestring *mls) override {
    return visit_leave(static_cast<Multicurve *>(mls));
  }
  bool visit_leave(Multisurface *ms) override {
    return visit_leave(static_cast<Geometrycollection *>(ms));
  }
  bool visit_leave(Multipolygon *mpy) override {
    return visit_leave(static_cast<Multisurface *>(mpy));
  }
};

}  // namespace gis

#endif  // SQL_GIS_GEOMETRY_VISITOR_H_INCLUDED