GEOS  3.3.3
GeometryListHolder.h
1 /**********************************************************************
2  * $Id$
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
8  * Copyright (C) 2006 Refractions Research Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************/
16 
17 #ifndef GEOS_OP_UNION_GEOMETRYLISTHOLDER_H
18 #define GEOS_OP_UNION_GEOMETRYLISTHOLDER_H
19 
20 // Forward declarations
21 namespace geos {
22  namespace geom {
23  class Geometry;
24  }
25 }
26 
27 namespace geos {
28 namespace operation { // geos::operation
29 namespace geounion { // geos::operation::geounion
30 
35 class GeometryListHolder : public std::vector<geom::Geometry*>
36 {
37 private:
38  typedef std::vector<geom::Geometry*> base_type;
39 
40 public:
43  {
44  std::for_each(ownedItems.begin(), ownedItems.end(),
45  &GeometryListHolder::deleteItem);
46  }
47 
48  // items need to be deleted in the end
49  void push_back_owned(geom::Geometry* item)
50  {
51  this->base_type::push_back(item);
52  ownedItems.push_back(item);
53  }
54 
55  geom::Geometry* getGeometry(std::size_t index)
56  {
57  if (index >= this->base_type::size())
58  return NULL;
59  return (*this)[index];
60  }
61 
62 private:
63  static void deleteItem(geom::Geometry* item);
64 
65 private:
66  std::vector<geom::Geometry*> ownedItems;
67 };
68 
69 } // namespace geos::operation::union
70 } // namespace geos::operation
71 } // namespace geos
72 
73 #endif