GEOS 3.11.1
GeometryExtracter.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 * Copyright (C) 2006 Refractions Research Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: geom/util/GeometryExtracter.java r320 (JTS-1.12)
18 *
19 **********************************************************************/
20
21#pragma once
22
23#include <geos/export.h>
24#include <geos/geom/GeometryFilter.h>
25#include <geos/geom/GeometryCollection.h>
26#include <vector>
27
28namespace geos {
29namespace geom { // geos.geom
30namespace util { // geos.geom.util
31
35class GEOS_DLL GeometryExtracter {
36
37public:
38
46 template <class ComponentType, class TargetContainer>
47 static void
48 extract(const Geometry& geom, TargetContainer& lst)
49 {
50 if(const ComponentType* p_c = dynamic_cast<const ComponentType*>(&geom)) {
51 lst.push_back(p_c);
52 }
53 else if(const GeometryCollection* p_c1 =
54 dynamic_cast<const GeometryCollection*>(&geom)) {
55 GeometryExtracter::Extracter<ComponentType, TargetContainer> extracter(lst);
56 p_c1->apply_ro(&extracter);
57 }
58 }
59
60private:
61
62 template <class ComponentType, class TargetContainer>
63 struct Extracter: public GeometryFilter {
64
70 Extracter(TargetContainer& comps) : comps_(comps) {}
71
72 TargetContainer& comps_;
73
74 void
75 filter_ro(const Geometry* geom) override
76 {
77 if(const ComponentType* c = dynamic_cast<const ComponentType*>(geom)) {
78 comps_.push_back(c);
79 }
80 }
81
82 // Declare type as noncopyable
83 Extracter(const Extracter& other);
84 Extracter& operator=(const Extracter& rhs);
85 };
86
87 // Declare type as noncopyable
88 GeometryExtracter(const GeometryExtracter& other) = delete;
89 GeometryExtracter& operator=(const GeometryExtracter& rhs) = delete;
90};
91
92} // namespace geos.geom.util
93} // namespace geos.geom
94} // namespace geos
95
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:52
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:45
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: GeometryExtracter.h:35
static void extract(const Geometry &geom, TargetContainer &lst)
Definition: GeometryExtracter.h:48
Basic namespace for all GEOS functionalities.
Definition: geos.h:39