GEOS: CoordinateList.h Source File

GEOS 3.3.8

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

CoordinateList.h
1 /**********************************************************************
2 * $Id: CoordinateList.h 3255 2011-03-01 17:56:10Z mloskot $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2010 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 * Last port: geom/CoordinateList.java ?? (never been in complete sync)
18 *
19 **********************************************************************/
20
21 #ifndef GEOS_GEOM_COORDINATELIST_H
22 #define GEOS_GEOM_COORDINATELIST_H
23
24 #include <geos/export.h>
25 #include <geos/geom/Coordinate.h>
26
27 #include <list>
28 #include <ostream> // for operator<<
29 #include <memory> // for auto_ptr
30
31 #ifdef _MSC_VER
32 #pragma warning(push)
33 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34 #endif
35
36 // Forward declarations
37 namespace geos {
38 namespace geom {
39 //class Coordinate;
40 }
41 }
42
43
44 namespace geos {
45 namespace geom { // geos::geom
46
56 class GEOS_DLL CoordinateList {
57
58 public:
59
60 typedef std::list<Coordinate>::iterator iterator;
61 typedef std::list<Coordinate>::const_iterator const_iterator;
62 typedef std::list<Coordinate>::size_type size_type;
63
64 friend std::ostream& operator<< (std::ostream& os,
65 const CoordinateList& cl);
66
76 CoordinateList(const std::vector<Coordinate>& v)
77 :
78 coords(v.begin(), v.end())
79 {
80 }
81
82 CoordinateList()
83 :
84 coords()
85 {
86 }
87
88 size_type size() const
89 {
90 return coords.size();
91 }
92
93 bool empty() const
94 {
95 return coords.empty();
96 }
97
98 iterator begin()
99 {
100 return coords.begin();
101 }
102
103 iterator end()
104 {
105 return coords.end();
106 }
107
108 const_iterator begin() const
109 {
110 return coords.begin();
111 }
112
113 const_iterator end() const
114 {
115 return coords.end();
116 }
117
131 iterator insert(iterator pos, const Coordinate& c, bool allowRepeated)
132 {
133 if ( !allowRepeated && pos != coords.begin() ) {
134 iterator prev = pos; --prev;
135 if ( c.equals2D(*prev) ) return prev;
136 }
137 return coords.insert(pos, c);
138 }
139
140 iterator insert(iterator pos, const Coordinate& c)
141 {
142 return coords.insert(pos, c);
143 }
144
145 iterator erase(iterator pos)
146 {
147 return coords.erase(pos);
148 }
149
150 iterator erase(iterator first, iterator last)
151 {
152 return coords.erase(first, last);
153 }
154
155 std::auto_ptr<Coordinate::Vect> toCoordinateArray() const
156 {
157 std::auto_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
158 ret->assign(coords.begin(), coords.end());
159 return ret;
160 }
161
162 private:
163
164 std::list<Coordinate> coords;
165 };
166
167 inline
168 std::ostream& operator<< (std::ostream& os, const CoordinateList& cl)
169 {
170 os << "(";
171 for (CoordinateList::const_iterator
172 it=cl.begin(), end=cl.end();
173 it != end;
174 ++it)
175 {
176 const Coordinate& c = *it;
177 if ( it != cl.begin() ) os << ", ";
178 os << c;
179 }
180 os << ")";
181
182 return os;
183 }
184
185 } // namespace geos::geom
186 } // namespace geos
187
188 #ifdef _MSC_VER
189 #pragma warning(pop)
190 #endif
191
192 #endif // ndef GEOS_GEOM_COORDINATELIST_H
193
194 /**********************************************************************
195 * $Log$
196 * Revision 1.2 2006/07/21 17:05:22 strk
197 * added operator<< for CoordinateList class
198 *
199 * Revision 1.1 2006/07/21 14:53:12 strk
200 * CoordinateList class re-introduced, for list-based ops
201 * (not strictly mapped to JTS version, not yet at least)
202 *
203 **********************************************************************/