Distribute svn_repo_revision.sh
[geos.git] / src / geomgraph / EdgeList.cpp
bloba0a13f61a0cf26ddb8523346ea3abd037cb97ab4
1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
13 **********************************************************************
15 * Last port: geomgraph/EdgeList.java rev. 1.4 (JTS-1.10)
17 **********************************************************************/
19 #include <string>
20 #include <sstream>
21 #include <vector>
23 #include <geos/geomgraph/Edge.h>
24 #include <geos/geomgraph/EdgeList.h>
25 #include <geos/noding/OrientedCoordinateArray.h>
26 #include <geos/profiler.h>
28 #ifndef GEOS_DEBUG
29 #define GEOS_DEBUG 0
30 #endif
32 using namespace std;
33 using namespace geos::noding;
35 namespace geos {
36 namespace geomgraph { // geos.geomgraph
38 #if PROFILE
39 static Profiler *profiler = Profiler::instance();
40 #endif
42 /*public*/
43 void
44 EdgeList::add(Edge *e)
46 edges.push_back(e);
47 OrientedCoordinateArray* oca = new OrientedCoordinateArray(*(e->getCoordinates()));
48 ocaMap[oca] = e;
51 void
52 EdgeList::addAll(const vector<Edge*> &edgeColl)
54 for (std::size_t i=0, s=edgeColl.size(); i<s ; ++i)
56 add(edgeColl[i]);
60 /**
61 * If there is an edge equal to e already in the list, return it.
62 * Otherwise return null.
63 * @return equal edge, if there is one already in the list
64 * null otherwise
66 Edge *
67 EdgeList::findEqualEdge(Edge *e)
69 #if PROFILE
70 static Profile *prof = profiler->get("EdgeList::findEqualEdge(Edge *e)");
71 prof->start();
72 #endif
74 OrientedCoordinateArray oca(*(e->getCoordinates()));
76 EdgeMap::iterator it = ocaMap.find(&oca);
78 #if PROFILE
79 prof->stop();
80 #endif
82 if ( it != ocaMap.end() ) return it->second;
83 return 0;
86 Edge*
87 EdgeList::get(int i)
89 return edges[i];
92 /**
93 * If the edge e is already in the list, return its index.
94 * @return index, if e is already in the list
95 * -1 otherwise
97 int
98 EdgeList::findEdgeIndex(Edge *e)
100 for (int i=0, s=(int)edges.size(); i<s; ++i)
102 if ( edges[i]->equals(e) ) return i;
104 return -1;
107 string
108 EdgeList::print()
110 ostringstream ss;
111 ss << *this;
112 return ss.str();
113 #if 0
114 string out="EdgeList( ";
115 for(unsigned int j=0, s=edges.size(); j<s; ++j)
117 Edge *e=edges[j];
118 if (j) out+=",";
119 out += e->print();
121 out+=") ";
122 return out;
123 #endif
126 void
127 EdgeList::clearList()
129 for (unsigned int pos=0; pos < edges.size(); pos++)
130 delete *(&edges[pos]);
132 edges.clear();
135 std::ostream&
136 operator<< (std::ostream&os, const EdgeList& el)
138 os << "EdgeList: " << std::endl;
139 for(std::size_t j=0, s=el.edges.size(); j<s; ++j)
141 Edge *e=el.edges[j];
142 os << " " << *e << std::endl;
144 return os;
147 EdgeList::~EdgeList()
149 for (EdgeMap::iterator i=ocaMap.begin(), e=ocaMap.end(); i!=e; ++i)
151 delete i->first; // OrientedCoordinateArray
155 } // namespace geos.geomgraph
156 } // namespace geos