00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
00022 #define GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
00023
00024 #include <geos/export.h>
00025 #include <geos/geom/GeometryFilter.h>
00026 #include <geos/geom/GeometryCollection.h>
00027 #include <geos/platform.h>
00028 #include <vector>
00029
00030 namespace geos {
00031 namespace geom {
00032 namespace util {
00033
00037 class GEOS_DLL GeometryExtracter {
00038
00039 public:
00040
00048 template <class ComponentType, class TargetContainer>
00049 static void extract(const Geometry& geom, TargetContainer& lst)
00050 {
00051 if ( const ComponentType* c = dynamic_cast<const ComponentType*>(&geom) )
00052 {
00053 lst.push_back(c);
00054 }
00055 else if ( const GeometryCollection* c =
00056 dynamic_cast<const GeometryCollection*>(&geom) )
00057 {
00058 GeometryExtracter::Extracter<ComponentType, TargetContainer> extracter(lst);
00059 c->apply_ro(&extracter);
00060 }
00061 }
00062
00063 private:
00064
00065 template <class ComponentType, class TargetContainer>
00066 struct Extracter: public GeometryFilter {
00067
00073 Extracter(TargetContainer& comps) : comps_(comps) {}
00074
00075 TargetContainer& comps_;
00076
00077 void filter_ro(const Geometry* geom)
00078 {
00079 if ( const ComponentType* c = dynamic_cast<const ComponentType*>(geom) ) {
00080 comps_.push_back(c);
00081 }
00082 }
00083
00084
00085 Extracter(const Extracter& other);
00086 Extracter& operator=(const Extracter& rhs);
00087 };
00088
00089
00090 GeometryExtracter(const GeometryExtracter& other);
00091 GeometryExtracter& operator=(const GeometryExtracter& rhs);
00092 };
00093
00094 }
00095 }
00096 }
00097
00098 #endif