// file : cult/containers/graph.hxx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2010 Boris Kolpackov // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef CULT_CONTAINERS_GRAPH_HXX #define CULT_CONTAINERS_GRAPH_HXX #include #include #include namespace Cult { namespace Containers { template class Graph { public: typedef N Node; typedef E Edge; struct NoEdge: virtual EH::Exception {}; struct NoNode: virtual EH::Exception {}; public: template T& new_node (); template T& new_node (A0 const&); template T& new_node (A0 const&, A1 const&); template T& new_node (A0 const&, A1 const&, A2 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, A5 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, A5 const&, A6 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, A5 const&, A6 const&, A7 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, A5 const&, A6 const&, A7 const&, A8 const&); template T& new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, A5 const&, A6 const&, A7 const&, A8 const&, A9 const&); public: template T& new_edge (Left&, Right&); template T& new_edge (Left&, Right&, A0 const&); template T& new_edge (Left&, Right&, A0 const&, A1 const&); template T& new_edge (Left&, Right&, A0 const&, A1 const&, A2 const&); template T& new_edge (Left&, Right&, A0 const&, A1 const&, A2 const&, A3 const&); template T& new_edge (Left&, Right&, A0 const&, A1 const&, A2 const&, A3 const&, A4 const&); template T& new_edge (Left&, Right&, A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, A5 const&); // Functions to reset edge's nodes. // public: template Void reset_left_node (TE& edge, TN& node) { edge.set_left_node (node); } template Void reset_right_node (TE& edge, TN& node) { edge.set_right_node (node); } // Functions to add edges to a node. // public: template Void add_edge_left (TN& node, TE& edge) { node.add_edge_left (edge); } template Void add_edge_right (TN& node, TE& edge) { node.add_edge_right (edge); } // Functions to delete edges and nodes. In order to delete a // a node without leaving any dangling edges you need to make // sure that each edge pointing to it is either deleted or reset // to some other node. // public: template Void delete_edge (Left& left_node, Right& right_node, T& edge); Void delete_node (Node& node) { if (nodes_.erase (&node) == 0) throw NoNode (); } protected: typedef Shptr NodePtr; typedef Shptr EdgePtr; typedef Map Nodes; typedef Map Edges; Nodes nodes_; Edges edges_; }; } } #include #endif // CULT_CONTAINERS_GRAPH_HXX