GEOS
3.4.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net> 00007 * Copyright (C) 2001-2002 Vivid Solutions Inc. 00008 * Copyright (C) 2006 Refractions Research Inc. 00009 * 00010 * This is free software; you can redistribute and/or modify it under 00011 * the terms of the GNU Lesser General Public Licence as published 00012 * by the Free Software Foundation. 00013 * See the COPYING file for more information. 00014 * 00015 ********************************************************************** 00016 * 00017 * Last port: geom/util/GeometryExtracter.java r320 (JTS-1.12) 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 { // geos.geom 00032 namespace util { // geos.geom.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 // Declare type as noncopyable 00085 Extracter(const Extracter& other); 00086 Extracter& operator=(const Extracter& rhs); 00087 }; 00088 00089 // Declare type as noncopyable 00090 GeometryExtracter(const GeometryExtracter& other); 00091 GeometryExtracter& operator=(const GeometryExtracter& rhs); 00092 }; 00093 00094 } // namespace geos.geom.util 00095 } // namespace geos.geom 00096 } // namespace geos 00097 00098 #endif