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