GEOS: GeometryExtracter.h Source File

GEOS 3.3.8

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

- File List

GeometryExtracter.h
1 /**********************************************************************
2 * $Id$
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 * Copyright (C) 2006 Refractions Research Inc.
10 *
11 * This is free software; you can redistribute and/or modify it under
12 * the terms of the GNU Lesser General Public Licence as published
13 * by the Free Software Foundation.
14 * See the COPYING file for more information.
15 *
16 **********************************************************************
17 *
18 * Last port: geom/util/GeometryExtracter.java r320 (JTS-1.12)
19 *
20 **********************************************************************/
21
22 #ifndef GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
23 #define GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
24
25 #include <geos/export.h>
26 #include <geos/geom/GeometryFilter.h>
27 #include <geos/geom/GeometryCollection.h>
28 #include <geos/platform.h>
29 #include <vector>
30
31 namespace geos {
32 namespace geom { // geos.geom
33 namespace util { // geos.geom.util
34
38 class GEOS_DLL GeometryExtracter {
39
40 public:
41
49 template <class ComponentType, class TargetContainer>
50 static void extract(const Geometry& geom, TargetContainer& lst)
51 {
52 if ( const ComponentType* c = dynamic_cast<const ComponentType*>(&geom) )
53 {
54 lst.push_back(c);
55 }
56 else if ( const GeometryCollection* c =
57 dynamic_cast<const GeometryCollection*>(&geom) )
58 {
59 GeometryExtracter::Extracter<ComponentType, TargetContainer> extracter(lst);
60 c->apply_ro(&extracter);
61 }
62 }
63
64 private:
65
66 template <class ComponentType, class TargetContainer>
67 struct Extracter: public GeometryFilter {
68
74 Extracter(TargetContainer& comps) : comps_(comps) {}
75
76 TargetContainer& comps_;
77
78 void filter_ro(const Geometry* geom)
79 {
80 if ( const ComponentType* c = dynamic_cast<const ComponentType*>(geom) ) {
81 comps_.push_back(c);
82 }
83 }
84
85 // Declare type as noncopyable
86 Extracter(const Extracter& other);
87 Extracter& operator=(const Extracter& rhs);
88 };
89
90 // Declare type as noncopyable
91 GeometryExtracter(const GeometryExtracter& other);
92 GeometryExtracter& operator=(const GeometryExtracter& rhs);
93 };
94
95 } // namespace geos.geom.util
96 } // namespace geos.geom
97 } // namespace geos
98
99 #endif