#
# These graph wrappers allow the client to attach triggers to
# various graph methods.
#
# -- Allen Leung
# Compiled by:
#
src/lib/graph/graphs.libstipulate
package odg = oop_digraph; # oop_digraph is from
src/lib/graph/oop-digraph.pkgherein
api Graph_Wrappers {
#
do_before_new_id: (Void -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G); # Here N,E,G stand stead for the types of client-package-supplied records associated with (respectively) nodes, edges and graphs.
do_after_new_id: (odg::Node_Id -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_add_node: (odg::Node( N ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_add_node: (odg::Node( N ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_add_edge: (odg::Edge( E ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_add_edge: (odg::Edge( E ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_remove_node: (odg::Node_Id -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_remove_node: (odg::Node_Id -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_set_in_edges: ((odg::Node_Id, List( odg::Edge( E ) )) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_set_in_edges: ((odg::Node_Id, List( odg::Edge( E ) )) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_set_out_edges: ((odg::Node_Id, List( odg::Edge( E ) )) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_set_out_edges: ((odg::Node_Id, List( odg::Edge( E ) )) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_set_entries: (List( odg::Node_Id ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_set_entries: (List( odg::Node_Id ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_set_exits: (List( odg::Node_Id ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_set_exits: (List( odg::Node_Id ) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_before_changed: (odg::Digraph(N,E,G) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
do_after_changed: (odg::Digraph(N,E,G) -> Void) -> odg::Digraph(N,E,G) -> odg::Digraph(N,E,G);
};
end;
stipulate
package odg = oop_digraph; # oop_digraph is from
src/lib/graph/oop-digraph.pkgherein
package graph_wrappers
: (weak) Graph_Wrappers # Graph_Wrappers is from
src/lib/graph/wrappers.pkg {
fun do_before_new_id f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => {. f(); graph.allot_node_id (); },
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_new_id f (odg::DIGRAPH graph)
=
odg::DIGRAPH {
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => {. x = graph.allot_node_id (); f x; x; },
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_add_node f (odg::DIGRAPH graph)
=
odg::DIGRAPH {
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => \\ n = { f n; graph.add_node n; },
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_add_node f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => \\ n = { graph.add_node n; f n; },
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_add_edge f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => \\ e = { f e; graph.add_edge e;},
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_add_edge f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => \\ e = { graph.add_edge e; f e;},
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_remove_node f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => \\ n = { f n; graph.remove_node n;},
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_remove_node f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => \\ n = { graph.remove_node n; f n;},
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_set_in_edges f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => \\ e = { f e; graph.set_in_edges e;},
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_set_in_edges f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => \\ e = { graph.set_in_edges e; f e;},
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_set_out_edges f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_out_edges => \\ e = { f e; graph.set_out_edges e;},
set_in_edges => graph.set_in_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_set_out_edges f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_out_edges => \\ e = { graph.set_out_edges e; f e;},
set_in_edges => graph.set_in_edges,
set_entries => graph.set_entries,
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_set_entries f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => \\ ns = { f ns; graph.set_entries ns;},
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_set_entries f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => \\ ns = { graph.set_entries ns; f ns;},
set_exits => graph.set_exits,
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_set_exits f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => \\ ns = { f ns; graph.set_exits ns;},
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_set_exits f (odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => graph.allot_node_id,
add_node => graph.add_node,
add_edge => graph.add_edge,
remove_node => graph.remove_node,
set_in_edges => graph.set_in_edges,
set_out_edges => graph.set_out_edges,
set_entries => graph.set_entries,
set_exits => \\ ns = { graph.set_exits ns; f ns;},
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_before_changed f (graph' as odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => (\\ x = { f graph'; graph.allot_node_id x;}),
add_node => (\\ x = { f graph'; graph.add_node x;}),
add_edge => (\\ x = { f graph'; graph.add_edge x;}),
remove_node => (\\ x = { f graph'; graph.remove_node x;}),
set_in_edges => (\\ x = { f graph'; graph.set_in_edges x;}),
set_out_edges => (\\ x = { f graph'; graph.set_out_edges x;}),
set_entries => (\\ x = { f graph'; graph.set_entries x;}),
set_exits => (\\ x = { f graph'; graph.set_exits x;}),
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
fun do_after_changed f (graph' as odg::DIGRAPH graph)
=
odg::DIGRAPH
{
name => graph.name,
graph_info => graph.graph_info,
allot_node_id => (\\ x = (graph.allot_node_id x then f graph')),
add_node => (\\ x = (graph.add_node x then f graph')),
add_edge => (\\ x = (graph.add_edge x then f graph')),
remove_node => (\\ x = (graph.remove_node x then f graph')),
set_out_edges => (\\ x = (graph.set_out_edges x then f graph')),
set_in_edges => (\\ x = (graph.set_in_edges x then f graph')),
set_entries => (\\ x = (graph.set_entries x then f graph')),
set_exits => (\\ x = (graph.set_exits x then f graph')),
garbage_collect => graph.garbage_collect,
nodes => graph.nodes,
edges => graph.edges,
order => graph.order,
size => graph.size,
capacity => graph.capacity,
out_edges => graph.out_edges,
in_edges => graph.in_edges,
next => graph.next,
prior => graph.prior,
has_edge => graph.has_edge,
has_node => graph.has_node,
node_info => graph.node_info,
entries => graph.entries,
exits => graph.exits,
entry_edges => graph.entry_edges,
exit_edges => graph.exit_edges,
forall_nodes => graph.forall_nodes,
forall_edges => graph.forall_edges
};
};
end;