1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/**********************************************************************
* $Id: GeometryCollectionIterator.cpp,v 1.12 2004/07/02 13:28:26 strk Exp $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
* $Log: GeometryCollectionIterator.cpp,v $
* Revision 1.12 2004/07/02 13:28:26 strk
* Fixed all #include lines to reflect headers layout change.
* Added client application build tips in README.
*
* Revision 1.11 2003/11/07 01:23:42 pramsey
* Add standard CVS headers licence notices and copyrights to all cpp and h
* files.
*
*
**********************************************************************/
#include <geos/geom.h>
#include <geos/util.h>
#include <typeinfo>
namespace geos {
GeometryCollectionIterator::GeometryCollectionIterator(){
parent=NULL;
subcollectionIterator=NULL;
atStart=true;
index=0;
max=0;
}
GeometryCollectionIterator::GeometryCollectionIterator(const GeometryCollectionIterator &gci) {
subcollectionIterator=gci.subcollectionIterator;
parent=gci.parent;
atStart=gci.atStart;
index=gci.index;
max=gci.max;
}
GeometryCollectionIterator::GeometryCollectionIterator(
const GeometryCollection *newParent){
parent=newParent;
subcollectionIterator=NULL;
atStart=true;
index=0;
max=newParent->getNumGeometries();
}
bool GeometryCollectionIterator::hasNext() const {
if (atStart) {
return true;
}
if (subcollectionIterator!=NULL) {
if (subcollectionIterator->hasNext()) {
return true;
}
//subcollectionIterator=NULL;
}
if (index>=max) {
return false;
}
return true;
}
const Geometry* GeometryCollectionIterator::next() {
// the parent GeometryCollection is the first object returned
if (atStart) {
atStart=false;
return parent;
}
if (subcollectionIterator!=NULL) {
if (subcollectionIterator->hasNext()) {
return subcollectionIterator->next();
} else {
delete subcollectionIterator;
subcollectionIterator=NULL; // is this automatic ?
}
}
if (index>=max) {
if ( subcollectionIterator ) delete subcollectionIterator;
throw new UnsupportedOperationException("No more elements");
}
const Geometry *obj=parent->getGeometryN(index++);
if ((typeid(*obj)==typeid(GeometryCollection)) ||
(typeid(*obj)==typeid(MultiPoint)) ||
(typeid(*obj)==typeid(MultiLineString)) ||
(typeid(*obj)==typeid(MultiPolygon))) {
subcollectionIterator=new GeometryCollectionIterator((GeometryCollection *)obj);
// there will always be at least one element in the sub-collection
return subcollectionIterator->next();
}
return obj;
}
/**
* Not implemented.
*
*@throws UnsupportedOperationException This method is not implemented.
*/
void GeometryCollectionIterator::remove() {
delete subcollectionIterator;
throw new UnsupportedOperationException();
}
GeometryCollectionIterator::~GeometryCollectionIterator(){
delete subcollectionIterator;
}
}
|