GEOS  3.4.2
CoordinateList.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2010 Sandro Santilli <strk@keybit.net>
7  * Copyright (C) 2006 Refractions Research Inc.
8  *
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.
13  *
14  **********************************************************************
15  *
16  * Last port: geom/CoordinateList.java ?? (never been in complete sync)
17  *
18  **********************************************************************/
19 
20 #ifndef GEOS_GEOM_COORDINATELIST_H
21 #define GEOS_GEOM_COORDINATELIST_H
22 
23 #include <geos/export.h>
24 #include <geos/geom/Coordinate.h>
25 
26 #include <list>
27 #include <ostream> // for operator<<
28 #include <memory> // for auto_ptr
29 
30 #ifdef _MSC_VER
31 #pragma warning(push)
32 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33 #endif
34 
35 // Forward declarations
36 namespace geos {
37  namespace geom {
38  //class Coordinate;
39  }
40 }
41 
42 
43 namespace geos {
44 namespace geom { // geos::geom
45 
55 class GEOS_DLL CoordinateList {
56 
57 public:
58 
59  typedef std::list<Coordinate>::iterator iterator;
60  typedef std::list<Coordinate>::const_iterator const_iterator;
61  typedef std::list<Coordinate>::size_type size_type;
62 
63  friend std::ostream& operator<< (std::ostream& os,
64  const CoordinateList& cl);
65 
75  CoordinateList(const std::vector<Coordinate>& v)
76  :
77  coords(v.begin(), v.end())
78  {
79  }
80 
82  :
83  coords()
84  {
85  }
86 
87  size_type size() const
88  {
89  return coords.size();
90  }
91 
92  bool empty() const
93  {
94  return coords.empty();
95  }
96 
97  iterator begin()
98  {
99  return coords.begin();
100  }
101 
102  iterator end()
103  {
104  return coords.end();
105  }
106 
107  const_iterator begin() const
108  {
109  return coords.begin();
110  }
111 
112  const_iterator end() const
113  {
114  return coords.end();
115  }
116 
130  iterator insert(iterator pos, const Coordinate& c, bool allowRepeated)
131  {
132  if ( !allowRepeated && pos != coords.begin() ) {
133  iterator prev = pos; --prev;
134  if ( c.equals2D(*prev) ) return prev;
135  }
136  return coords.insert(pos, c);
137  }
138 
139  iterator insert(iterator pos, const Coordinate& c)
140  {
141  return coords.insert(pos, c);
142  }
143 
144  iterator erase(iterator pos)
145  {
146  return coords.erase(pos);
147  }
148 
149  iterator erase(iterator first, iterator last)
150  {
151  return coords.erase(first, last);
152  }
153 
154  std::auto_ptr<Coordinate::Vect> toCoordinateArray() const
155  {
156  std::auto_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
157  ret->assign(coords.begin(), coords.end());
158  return ret;
159  }
160  void closeRing()
161  {
162  if(!coords.empty() && ! (*(coords.begin())).equals(*(coords.rbegin())))
163  {
164  const Coordinate &c = *(coords.begin());
165  coords.insert(coords.end(),c);
166  }
167  }
168 
169 
170 private:
171 
172  std::list<Coordinate> coords;
173 };
174 
175 inline
176 std::ostream& operator<< (std::ostream& os, const CoordinateList& cl)
177 {
178  os << "(";
179  for (CoordinateList::const_iterator
180  it=cl.begin(), end=cl.end();
181  it != end;
182  ++it)
183  {
184  const Coordinate& c = *it;
185  if ( it != cl.begin() ) os << ", ";
186  os << c;
187  }
188  os << ")";
189 
190  return os;
191 }
192 
193 } // namespace geos::geom
194 } // namespace geos
195 
196 #ifdef _MSC_VER
197 #pragma warning(pop)
198 #endif
199 
200 #endif // ndef GEOS_GEOM_COORDINATELIST_H
iterator insert(iterator pos, const Coordinate &c, bool allowRepeated)
Inserts the specified coordinate at the specified position in this list.
Definition: CoordinateList.h:130
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
CoordinateList(const std::vector< Coordinate > &v)
Constructs a new list from an array of Coordinates, allowing repeated points.
Definition: CoordinateList.h:75
std::vector< Coordinate > Vect
A vector of Coordinate objects (real object, not pointers)
Definition: Coordinate.h:77
A list of Coordinates, which may be set to prevent repeated coordinates from occuring in the list...
Definition: CoordinateList.h:55