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

# CoordinateList.h

    00001 /**********************************************************************
    00002  * $Id: CoordinateList.h 1820 2006-09-06 16:54:23Z mloskot $
    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/geom/Coordinate.h>
    00020
    00021 #include <list>
    00022 #include <ostream> // for operator<<
    00023 #include <memory> // for auto_ptr
    00024
    00025 // Forward declarations
    00026 namespace geos {
    00027         namespace geom {
    00028                 //class Coordinate;
    00029         }
    00030 }
    00031
    00032
    00033 namespace geos {
    00034 namespace geom { // geos::geom
    00035
    00044 class CoordinateList {
    00045
    00046 public:
    00047
    00048         typedef std::list<Coordinate>::iterator iterator;
    00049         typedef std::list<Coordinate>::const_iterator const_iterator;
    00050         typedef std::list<Coordinate>::size_type size_type;
    00051
    00052         friend std::ostream& operator<< (std::ostream& os,
    00053                 const CoordinateList& cl);
    00054
    00055         CoordinateList(const std::vector<Coordinate>& v)
    00056                 :
    00057                 coords(v.begin(), v.end())
    00058         {
    00059         }
    00060
    00061         size_type size() const
    00062         {
    00063                 return coords.size();
    00064         }
    00065
    00066         iterator begin()
    00067         {
    00068                 return coords.begin();
    00069         }
    00070
    00071         iterator end()
    00072         {
    00073                 return coords.end();
    00074         }
    00075
    00076         const_iterator begin() const
    00077         {
    00078                 return coords.begin();
    00079         }
    00080
    00081         const_iterator end() const
    00082         {
    00083                 return coords.end();
    00084         }
    00085
    00086         iterator insert(iterator pos, const Coordinate& c)
    00087         {
    00088                 return coords.insert(pos, c);
    00089         }
    00090
    00091         iterator erase(iterator pos)
    00092         {
    00093                 return coords.erase(pos);
    00094         }
    00095
    00096         iterator erase(iterator first, iterator last)
    00097         {
    00098                 return coords.erase(first, last);
    00099         }
    00100
    00101         std::auto_ptr<Coordinate::Vect> toCoordinateArray() const
    00102         {
    00103                 std::auto_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
    00104                 ret->assign(coords.begin(), coords.end());
    00105                 return ret;
    00106         }
    00107
    00108 private:
    00109
    00110         std::list<Coordinate> coords;
    00111
    00112
    00113 };
    00114
    00115 inline
    00116 std::ostream& operator<< (std::ostream& os, const CoordinateList& cl)
    00117 {
    00118         os << "(";
    00119         for (CoordinateList::const_iterator
    00120                 it=cl.begin(), end=cl.end();
    00121                 it != end;
    00122                 ++it)
    00123         {
    00124                 const Coordinate& c = *it;
    00125                 if ( it != cl.begin() ) os << ", ";
    00126                 os << c;
    00127         }
    00128         os << ")";
    00129
    00130         return os;
    00131 }
    00132
    00133 } // namespace geos::geom
    00134 } // namespace geos
    00135
    00136
    00137 #endif // ndef GEOS_GEOM_COORDINATELIST_H
    00138
    00139 /**********************************************************************
    00140  * $Log$
    00141  * Revision 1.2  2006/07/21 17:05:22  strk
    00142  * added operator<< for CoordinateList class
    00143  *
    00144  * Revision 1.1  2006/07/21 14:53:12  strk
    00145  * CoordinateList class re-introduced, for list-based ops
    00146  * (not strictly mapped to JTS version, not yet at least)
    00147  *
    00148  **********************************************************************/