GEOS  3.4.2
NodeMap.h
00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2005-2006 Refractions Research Inc.
00007  * Copyright (C) 2001-2002 Vivid Solutions 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  * Last port: geomgraph/NodeMap.java rev. 1.3 (JTS-1.10)
00017  *
00018  **********************************************************************/
00019 
00020 
00021 #ifndef GEOS_GEOMGRAPH_NODEMAP_H
00022 #define GEOS_GEOMGRAPH_NODEMAP_H
00023 
00024 #include <geos/export.h>
00025 #include <map>
00026 #include <vector>
00027 #include <string>
00028 
00029 #include <geos/geom/Coordinate.h> // for CoordinateLessThen
00030 #include <geos/geomgraph/Node.h> // for testInvariant
00031 
00032 #include <geos/inline.h>
00033 
00034 #ifdef _MSC_VER
00035 #pragma warning(push)
00036 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00037 #endif
00038 
00039 // Forward declarations
00040 namespace geos {
00041         namespace geomgraph {
00042                 class Node;
00043                 class EdgeEnd;
00044                 class NodeFactory;
00045         }
00046 }
00047 
00048 namespace geos {
00049 namespace geomgraph { // geos.geomgraph
00050 
00051 class GEOS_DLL NodeMap{
00052 public:
00053 
00054         typedef std::map<geom::Coordinate*,Node*,geom::CoordinateLessThen> container;
00055 
00056         typedef container::iterator iterator;
00057 
00058         typedef container::const_iterator const_iterator;
00059 
00060         typedef std::pair<geom::Coordinate*,Node*> pair;
00061 
00062         container nodeMap;
00063 
00064         const NodeFactory &nodeFact;
00065 
00069         NodeMap(const NodeFactory &newNodeFact);
00070 
00071         virtual ~NodeMap();
00072 
00073         Node* addNode(const geom::Coordinate& coord);
00074 
00075         Node* addNode(Node *n);
00076 
00077         void add(EdgeEnd *e);
00078 
00079         Node *find(const geom::Coordinate& coord) const;
00080 
00081         const_iterator begin() const { return nodeMap.begin(); }
00082 
00083         const_iterator end() const { return nodeMap.end(); }
00084 
00085         iterator begin() { return nodeMap.begin(); }
00086 
00087         iterator end() { return nodeMap.end(); }
00088 
00089         void getBoundaryNodes(int geomIndex,
00090                 std::vector<Node*>&bdyNodes) const;
00091 
00092         std::string print() const;
00093 
00094         void testInvariant()
00095         {
00096 #ifndef NDEBUG
00097                 // Each Coordinate key is a pointer inside the Node value
00098                 for (iterator it=begin(), itEnd=end(); it != itEnd; ++it)
00099                 {
00100                         pair p = *it;
00101                         geomgraph::Node* n = p.second;
00102                         geom::Coordinate* c = const_cast<geom::Coordinate*>(
00103                                 &(n->getCoordinate())
00104                         );
00105                         assert(p.first == c);
00106                 }
00107 #endif
00108         }
00109 
00110 private:
00111 
00112     // Declare type as noncopyable
00113     NodeMap(const NodeMap& other);
00114     NodeMap& operator=(const NodeMap& rhs);
00115 };
00116 
00117 } // namespace geos.geomgraph
00118 } // namespace geos
00119 
00120 #ifdef _MSC_VER
00121 #pragma warning(pop)
00122 #endif
00123 
00124 #endif // ifndef GEOS_GEOMGRAPH_NODEMAP_H