aboutsummaryrefslogtreecommitdiff
path: root/cutl/container
diff options
context:
space:
mode:
Diffstat (limited to 'cutl/container')
-rw-r--r--cutl/container/graph.hxx53
1 files changed, 48 insertions, 5 deletions
diff --git a/cutl/container/graph.hxx b/cutl/container/graph.hxx
index 2b796a1..9244351 100644
--- a/cutl/container/graph.hxx
+++ b/cutl/container/graph.hxx
@@ -16,6 +16,7 @@ namespace cutl
namespace container
{
struct no_edge: exception {};
+ struct no_node: exception {};
template <typename N, typename E>
class graph
@@ -84,10 +85,6 @@ namespace cutl
new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&,
A5 const&, A6 const&, A7 const&, A8 const&, A9 const&);
- // template <typename T>
- // void
- // delete_node (T& node);
-
public:
template <typename T, typename L, typename R>
T&
@@ -127,10 +124,56 @@ namespace cutl
new_edge (L&, R&, A0 const&, A1 const&, A2 const&, A3 const&,
A4 const&, A5 const&);
+ // Functions to reset edge's nodes.
+ //
+ public:
+ template <typename TE, typename TN>
+ void
+ reset_left_node (TE& edge, TN& node)
+ {
+ edge.set_left_node (node);
+ }
+
+ template <typename TE, typename TN>
+ void
+ reset_right_node (TE& edge, TN& node)
+ {
+ edge.set_right_node (node);
+ }
+
+ // Functions to add edges to a node.
+ //
+ public:
+ template <typename TN, typename TE>
+ void
+ add_edge_left (TN& node, TE& edge)
+ {
+ node.add_edge_left (edge);
+ }
+
+ template <typename TN, typename TE>
+ 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 <typename T, typename L, typename R>
void
- delete_edge (L&, R&, T& edge);
+ delete_edge (L& left_node, R& right_node, T& edge);
+
+ void
+ delete_node (node_base& node)
+ {
+ if (nodes_.erase (&node) == 0)
+ throw no_node ();
+ }
public:
graph () {}