diff -r a34203867181 -r 269f0cbfbcc8 lemon/grid_graph.h --- a/lemon/grid_graph.h Fri Sep 30 13:13:42 2005 +0000 +++ b/lemon/grid_graph.h Fri Sep 30 13:15:28 2005 +0000 @@ -27,8 +27,21 @@ #include +#include + +///\ingroup graphs +///\file +///\brief GridGraph class. + namespace lemon { + /// \brief Base graph for GridGraph. + /// + /// Base graph for grid graph. It describes some member functions + /// which can be used in the GridGraph. + /// + /// \warning Always use the GridGraph instead of this. + /// \see GridGraph class GridGraphBase { public: @@ -356,9 +369,91 @@ /// "Undirected Graph" concept. /// /// \author Balazs Dezso + /// \see GridGraphBase class GridGraph : public ExtendedGridGraphBase { public: - + + /// \brief Map to get the indices of the nodes as xy. + /// + /// Map to get the indices of the nodes as xy. + class IndexMap { + public: + typedef True NeedCopy; + /// \brief The key type of the map + typedef GridGraph::Node Key; + /// \brief The value type of the map + typedef xy Value; + + /// \brief Constructor + /// + /// Constructor + IndexMap(const GridGraph& _graph) : graph(_graph) {} + + /// \brief The subscript operator + /// + /// The subscript operator. + Value operator[](Key key) const { + return xy(graph.row(key), graph.col(key)); + } + + private: + const GridGraph& graph; + }; + + /// \brief Map to get the row of the nodes. + /// + /// Map to get the row of the nodes. + class RowMap { + public: + typedef True NeedCopy; + /// \brief The key type of the map + typedef GridGraph::Node Key; + /// \brief The value type of the map + typedef int Value; + + /// \brief Constructor + /// + /// Constructor + RowMap(const GridGraph& _graph) : graph(_graph) {} + + /// \brief The subscript operator + /// + /// The subscript operator. + Value operator[](Key key) const { + return graph.row(key); + } + + private: + const GridGraph& graph; + }; + + /// \brief Map to get the column of the nodes. + /// + /// Map to get the column of the nodes. + class ColMap { + public: + typedef True NeedCopy; + /// \brief The key type of the map + typedef GridGraph::Node Key; + /// \brief The value type of the map + typedef int Value; + + /// \brief Constructor + /// + /// Constructor + ColMap(const GridGraph& _graph) : graph(_graph) {} + + /// \brief The subscript operator + /// + /// The subscript operator. + Value operator[](Key key) const { + return graph.col(key); + } + + private: + const GridGraph& graph; + }; + GridGraph(int n, int m) { construct(n, m); } /// \brief Gives back the edge goes down from the node. @@ -398,5 +493,26 @@ } }; + + /// \brief Index map of the grid graph + /// + /// Just returns an IndexMap for the grid graph. + GridGraph::IndexMap indexMap(const GridGraph& graph) { + return GridGraph::IndexMap(graph); + } + + /// \brief Row map of the grid graph + /// + /// Just returns an RowMap for the grid graph. + GridGraph::RowMap rowMap(const GridGraph& graph) { + return GridGraph::RowMap(graph); + } + + /// \brief Coloumn map of the grid graph + /// + /// Just returns an ColMap for the grid graph. + GridGraph::ColMap colMap(const GridGraph& graph) { + return GridGraph::ColMap(graph); + } } #endif