GEOS  3.9.1dev
GeometryExtracter.h
Go to the documentation of this file.
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 #ifndef GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
22 #define GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
23 
24 #include <geos/export.h>
27 #include <vector>
28 
29 namespace geos {
30 namespace geom { // geos.geom
31 namespace util { // geos.geom.util
32 
37 
38 public:
39 
47  template <class ComponentType, class TargetContainer>
48  static void
49  extract(const Geometry& geom, TargetContainer& lst)
50  {
51  if(const ComponentType* p_c = dynamic_cast<const ComponentType*>(&geom)) {
52  lst.push_back(p_c);
53  }
54  else if(const GeometryCollection* p_c1 =
55  dynamic_cast<const GeometryCollection*>(&geom)) {
57  p_c1->apply_ro(&extracter);
58  }
59  }
60 
61 private:
62 
63  template <class ComponentType, class TargetContainer>
64  struct Extracter: public GeometryFilter {
65 
71  Extracter(TargetContainer& comps) : comps_(comps) {}
72 
73  TargetContainer& comps_;
74 
75  void
76  filter_ro(const Geometry* geom) override
77  {
78  if(const ComponentType* c = dynamic_cast<const ComponentType*>(geom)) {
79  comps_.push_back(c);
80  }
81  }
82 
83  // Declare type as noncopyable
84  Extracter(const Extracter& other);
85  Extracter& operator=(const Extracter& rhs);
86  };
87 
88  // Declare type as noncopyable
89  GeometryExtracter(const GeometryExtracter& other) = delete;
90  GeometryExtracter& operator=(const GeometryExtracter& rhs) = delete;
91 };
92 
93 } // namespace geos.geom.util
94 } // namespace geos.geom
95 } // namespace geos
96 
97 #endif
Geometry classes support the concept of applying a Geometry filter to the Geometry.
#define GEOS_DLL
Definition: export.h:28
void filter_ro(const Geometry *geom) override
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Represents a collection of heterogeneous Geometry objects.
Basic namespace for all GEOS functionalities.
static void extract(const Geometry &geom, TargetContainer &lst)