GEOS: GeometryExtracter.h Source File

GEOS 3.5.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

GeometryExtracter.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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>
25 #include <geos/geom/GeometryFilter.h>
26 #include <geos/geom/GeometryCollection.h>
27 #include <geos/platform.h>
28 #include <vector>
29
30 namespace geos {
31 namespace geom { // geos.geom
32 namespace util { // geos.geom.util
33
37 class GEOS_DLL GeometryExtracter {
38
39 public:
40
48 template <class ComponentType, class TargetContainer>
49 static void extract(const Geometry& geom, TargetContainer& lst)
50 {
51 if ( const ComponentType* c = dynamic_cast<const ComponentType*>(&geom) )
52 {
53 lst.push_back(c);
54 }
55 else if ( const GeometryCollection* c =
56 dynamic_cast<const GeometryCollection*>(&geom) )
57 {
58 GeometryExtracter::Extracter<ComponentType, TargetContainer> extracter(lst);
59 c->apply_ro(&extracter);
60 }
61 }
62
63 private:
64
65 template <class ComponentType, class TargetContainer>
66 struct Extracter: public GeometryFilter {
67
73 Extracter(TargetContainer& comps) : comps_(comps) {}
74
75 TargetContainer& comps_;
76
77 void filter_ro(const Geometry* geom)
78 {
79 if ( const ComponentType* c = dynamic_cast<const ComponentType*>(geom) ) {
80 comps_.push_back(c);
81 }
82 }
83
84 // Declare type as noncopyable
85 Extracter(const Extracter& other);
86 Extracter& operator=(const Extracter& rhs);
87 };
88
89 // Declare type as noncopyable
90 GeometryExtracter(const GeometryExtracter& other);
91 GeometryExtracter& operator=(const GeometryExtracter& rhs);
92 };
93
94 } // namespace geos.geom.util
95 } // namespace geos.geom
96 } // namespace geos
97
98 #endif
geos::geom::GeometryFilter
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:48
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:167
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:56
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::util::GeometryExtracter
Definition: GeometryExtracter.h:37
geos::geom::util::GeometryExtracter::extract
static void extract(const Geometry &geom, TargetContainer &lst)
Definition: GeometryExtracter.h:49