Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

CoordinateList.h

00001 /**********************************************************************
00002  * $Id: CoordinateList.h 2556 2009-06-06 22:22:28Z strk $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2006 Refractions Research Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************/
00015 
00016 #ifndef GEOS_GEOM_COORDINATELIST_H
00017 #define GEOS_GEOM_COORDINATELIST_H
00018 
00019 #include <geos/export.h>
00020 #include <geos/geom/Coordinate.h> 
00021 
00022 #include <list>
00023 #include <ostream> // for operator<<
00024 #include <memory> // for auto_ptr 
00025 
00026 // Forward declarations
00027 namespace geos {
00028         namespace geom { 
00029                 //class Coordinate;
00030         }
00031 }
00032 
00033 
00034 namespace geos {
00035 namespace geom { // geos::geom
00036 
00045 class GEOS_DLL CoordinateList {
00046 
00047 public:
00048 
00049         typedef std::list<Coordinate>::iterator iterator;
00050         typedef std::list<Coordinate>::const_iterator const_iterator;
00051         typedef std::list<Coordinate>::size_type size_type;
00052 
00053         friend std::ostream& operator<< (std::ostream& os,
00054                 const CoordinateList& cl);
00055 
00056         CoordinateList(const std::vector<Coordinate>& v)
00057                 :
00058                 coords(v.begin(), v.end())
00059         {
00060         }
00061 
00062         size_type size() const
00063         {
00064                 return coords.size();
00065         }
00066 
00067         iterator begin()
00068         {
00069                 return coords.begin();
00070         }
00071 
00072         iterator end()
00073         {
00074                 return coords.end();
00075         }
00076 
00077         const_iterator begin() const
00078         {
00079                 return coords.begin();
00080         }
00081 
00082         const_iterator end() const
00083         {
00084                 return coords.end();
00085         }
00086 
00087         iterator insert(iterator pos, const Coordinate& c)
00088         {
00089                 return coords.insert(pos, c);
00090         }
00091 
00092         iterator erase(iterator pos)
00093         {
00094                 return coords.erase(pos);
00095         }
00096 
00097         iterator erase(iterator first, iterator last)
00098         {
00099                 return coords.erase(first, last);
00100         }
00101 
00102         std::auto_ptr<Coordinate::Vect> toCoordinateArray() const
00103         {
00104                 std::auto_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
00105                 ret->assign(coords.begin(), coords.end());
00106                 return ret;
00107         }
00108 
00109 private:
00110 
00111         std::list<Coordinate> coords;
00112 
00113 
00114 };
00115 
00116 inline
00117 std::ostream& operator<< (std::ostream& os, const CoordinateList& cl)
00118 {
00119         os << "(";
00120         for (CoordinateList::const_iterator
00121                 it=cl.begin(), end=cl.end();
00122                 it != end;
00123                 ++it)
00124         {
00125                 const Coordinate& c = *it;
00126                 if ( it != cl.begin() ) os << ", ";
00127                 os << c;
00128         }
00129         os << ")";
00130 
00131         return os;
00132 }
00133 
00134 } // namespace geos::geom
00135 } // namespace geos
00136 
00137 
00138 #endif // ndef GEOS_GEOM_COORDINATELIST_H
00139 
00140 /**********************************************************************
00141  * $Log$
00142  * Revision 1.2  2006/07/21 17:05:22  strk
00143  * added operator<< for CoordinateList class
00144  *
00145  * Revision 1.1  2006/07/21 14:53:12  strk
00146  * CoordinateList class re-introduced, for list-based ops
00147  * (not strictly mapped to JTS version, not yet at least)
00148  *
00149  **********************************************************************/

Generated on Thu Jun 11 06:17:01 2009 for GEOS by  doxygen 1.4.4