NodeMap.h

00001 /**********************************************************************
00002  * $Id: NodeMap.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) 2005-2006 Refractions Research Inc.
00008  * Copyright (C) 2001-2002 Vivid Solutions 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 
00018 #ifndef GEOS_GEOMGRAPH_NODEMAP_H
00019 #define GEOS_GEOMGRAPH_NODEMAP_H
00020 
00021 #include <map>
00022 #include <vector>
00023 #include <string>
00024 
00025 #include <geos/geom/Coordinate.h> // for CoordinateLessThen
00026 #include <geos/geomgraph/Node.h> // for testInvariant
00027 
00028 #include <geos/inline.h>
00029 
00030 // Forward declarations
00031 namespace geos {
00032         namespace geomgraph {
00033                 class Node;
00034                 class EdgeEnd;
00035                 class NodeFactory;
00036         }
00037 }
00038 
00039 namespace geos {
00040 namespace geomgraph { // geos.geomgraph
00041 
00042 class NodeMap{
00043 public:
00044 
00045         typedef std::map<geom::Coordinate*,Node*,geom::CoordinateLessThen> container;
00046 
00047         typedef container::iterator iterator;
00048 
00049         typedef container::const_iterator const_iterator;
00050 
00051         typedef std::pair<geom::Coordinate*,Node*> pair;
00052 
00053         container nodeMap;
00054 
00055         const NodeFactory &nodeFact;
00056 
00060         NodeMap(const NodeFactory &newNodeFact);
00061 
00062         virtual ~NodeMap();
00063 
00064         Node* addNode(const geom::Coordinate& coord);
00065 
00066         Node* addNode(Node *n);
00067 
00068         void add(EdgeEnd *e);
00069 
00070         Node *find(const geom::Coordinate& coord) const;
00071 
00072         const_iterator begin() const { return nodeMap.begin(); }
00073 
00074         const_iterator end() const { return nodeMap.end(); }
00075 
00076         iterator begin() { return nodeMap.begin(); }
00077 
00078         iterator end() { return nodeMap.end(); }
00079 
00080         void getBoundaryNodes(int geomIndex,
00081                 std::vector<Node*>&bdyNodes) const;
00082 
00083         std::string print() const;
00084 
00085         void testInvariant()
00086         {
00087 #ifndef NDEBUG
00088                 // Each Coordinate key is a pointer inside the Node value
00089                 for (iterator it=begin(), itEnd=end(); it != itEnd; ++it)
00090                 {
00091                         pair p = *it;
00092                         geomgraph::Node* n = p.second;
00093                         geom::Coordinate* c = const_cast<geom::Coordinate*>(
00094                                 &(n->getCoordinate())
00095                         );
00096                         assert(p.first == c);
00097                 }
00098 #endif
00099         }
00100 };
00101 
00102 } // namespace geos.geomgraph
00103 } // namespace geos
00104 
00105 //#ifdef GEOS_INLINE
00106 //# include "geos/geomgraph/NodeMap.inl"
00107 //#endif
00108 
00109 #endif // ifndef GEOS_GEOMGRAPH_NODEMAP_H
00110 
00111 /**********************************************************************
00112  * $Log$
00113  * Revision 1.3  2006/05/04 12:54:26  strk
00114  * Added invariant tester for NodeMap class, fixed comment about ownership of NodeFactory
00115  *
00116  * Revision 1.2  2006/03/24 09:52:41  strk
00117  * USE_INLINE => GEOS_INLINE
00118  *
00119  * Revision 1.1  2006/03/09 16:46:49  strk
00120  * geos::geom namespace definition, first pass at headers split
00121  *
00122  **********************************************************************/
00123 

Generated on Fri Mar 27 04:52:53 2009 for GEOS by  doxygen 1.5.4