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