GEOS  3.3.1
CoordinateList.h
00001 /**********************************************************************
00002  * $Id: CoordinateList.h 3255 2011-03-01 17:56:10Z mloskot $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2010 Sandro Santilli <strk@keybit.net>
00008  * Copyright (C) 2006 Refractions Research Inc.
00009  *
00010  * This is free software; you can redistribute and/or modify it under
00011  * the terms of the GNU Lesser General Public Licence as published
00012  * by the Free Software Foundation. 
00013  * See the COPYING file for more information.
00014  *
00015  **********************************************************************
00016  *
00017  * Last port: geom/CoordinateList.java ?? (never been in complete sync)
00018  *
00019  **********************************************************************/
00020 
00021 #ifndef GEOS_GEOM_COORDINATELIST_H
00022 #define GEOS_GEOM_COORDINATELIST_H
00023 
00024 #include <geos/export.h>
00025 #include <geos/geom/Coordinate.h> 
00026 
00027 #include <list>
00028 #include <ostream> // for operator<<
00029 #include <memory> // for auto_ptr 
00030 
00031 #ifdef _MSC_VER
00032 #pragma warning(push)
00033 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00034 #endif
00035 
00036 // Forward declarations
00037 namespace geos {
00038         namespace geom { 
00039                 //class Coordinate;
00040         }
00041 }
00042 
00043 
00044 namespace geos {
00045 namespace geom { // geos::geom
00046 
00056 class GEOS_DLL CoordinateList {
00057 
00058 public:
00059 
00060         typedef std::list<Coordinate>::iterator iterator;
00061         typedef std::list<Coordinate>::const_iterator const_iterator;
00062         typedef std::list<Coordinate>::size_type size_type;
00063 
00064         friend std::ostream& operator<< (std::ostream& os,
00065                 const CoordinateList& cl);
00066 
00076         CoordinateList(const std::vector<Coordinate>& v)
00077                 :
00078                 coords(v.begin(), v.end())
00079         {
00080         }
00081 
00082         CoordinateList()
00083                 :
00084                 coords()
00085         {
00086         }
00087 
00088         size_type size() const
00089         {
00090                 return coords.size();
00091         }
00092 
00093         bool empty() const
00094         {
00095                 return coords.empty();
00096         }
00097 
00098         iterator begin()
00099         {
00100                 return coords.begin();
00101         }
00102 
00103         iterator end()
00104         {
00105                 return coords.end();
00106         }
00107 
00108         const_iterator begin() const
00109         {
00110                 return coords.begin();
00111         }
00112 
00113         const_iterator end() const
00114         {
00115                 return coords.end();
00116         }
00117 
00131         iterator insert(iterator pos, const Coordinate& c, bool allowRepeated)
00132         {
00133                 if ( !allowRepeated && pos != coords.begin() ) {
00134                         iterator prev = pos; --prev;
00135                         if ( c.equals2D(*prev) ) return prev;
00136                 }
00137                 return coords.insert(pos, c);
00138         }
00139 
00140         iterator insert(iterator pos, const Coordinate& c)
00141         {
00142                 return coords.insert(pos, c);
00143         }
00144 
00145         iterator erase(iterator pos)
00146         {
00147                 return coords.erase(pos);
00148         }
00149 
00150         iterator erase(iterator first, iterator last)
00151         {
00152                 return coords.erase(first, last);
00153         }
00154 
00155         std::auto_ptr<Coordinate::Vect> toCoordinateArray() const
00156         {
00157                 std::auto_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
00158                 ret->assign(coords.begin(), coords.end());
00159                 return ret;
00160         }
00161 
00162 private:
00163 
00164         std::list<Coordinate> coords;
00165 };
00166 
00167 inline
00168 std::ostream& operator<< (std::ostream& os, const CoordinateList& cl)
00169 {
00170         os << "(";
00171         for (CoordinateList::const_iterator
00172                 it=cl.begin(), end=cl.end();
00173                 it != end;
00174                 ++it)
00175         {
00176                 const Coordinate& c = *it;
00177                 if ( it != cl.begin() ) os << ", ";
00178                 os << c;
00179         }
00180         os << ")";
00181 
00182         return os;
00183 }
00184 
00185 } // namespace geos::geom
00186 } // namespace geos
00187 
00188 #ifdef _MSC_VER
00189 #pragma warning(pop)
00190 #endif
00191 
00192 #endif // ndef GEOS_GEOM_COORDINATELIST_H
00193 
00194 /**********************************************************************
00195  * $Log$
00196  * Revision 1.2  2006/07/21 17:05:22  strk
00197  * added operator<< for CoordinateList class
00198  *
00199  * Revision 1.1  2006/07/21 14:53:12  strk
00200  * CoordinateList class re-introduced, for list-based ops
00201  * (not strictly mapped to JTS version, not yet at least)
00202  *
00203  **********************************************************************/