Complete Note#1 in the http://wiki.osgeo.org/wiki/GEOS_Provenance_Review to get out...
[geos.git] / include / geos / operation / union / GeometryListHolder.h
blob1d21583fb1e211c72d024eb94f20d4afd177b443
1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2006 Refractions Research Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 **********************************************************************/
16 #ifndef GEOS_OP_UNION_GEOMETRYLISTHOLDER_H
17 #define GEOS_OP_UNION_GEOMETRYLISTHOLDER_H
19 // Forward declarations
20 namespace geos {
21 namespace geom {
22 class Geometry;
26 namespace geos {
27 namespace operation { // geos::operation
28 namespace geounion { // geos::operation::geounion
30 /**
31 * \brief Helper class holding Geometries, part of which are held by reference
32 * others are held exclusively.
34 class GeometryListHolder : public std::vector<geom::Geometry*>
36 private:
37 typedef std::vector<geom::Geometry*> base_type;
39 public:
40 GeometryListHolder() {}
41 ~GeometryListHolder()
43 std::for_each(ownedItems.begin(), ownedItems.end(),
44 &GeometryListHolder::deleteItem);
47 // items need to be deleted in the end
48 void push_back_owned(geom::Geometry* item)
50 this->base_type::push_back(item);
51 ownedItems.push_back(item);
54 geom::Geometry* getGeometry(std::size_t index)
56 if (index >= this->base_type::size())
57 return NULL;
58 return (*this)[index];
61 private:
62 static void deleteItem(geom::Geometry* item);
64 private:
65 std::vector<geom::Geometry*> ownedItems;
68 } // namespace geos::operation::union
69 } // namespace geos::operation
70 } // namespace geos
72 #endif