module Roby::Relations::DirectedRelationSupport
Base support for relations. It is mixed in objects on which a Relations::Space
applies on, like Task
for TaskStructure
and EventGenerator
for EventStructure
.
See also the definition of Relations::Graph#add_relation
and Relations::Graph#remove_relation
for the possibility to define hooks that get called when a new edge involving self
as a vertex gets added and removed
Attributes
Public Instance Methods
# File lib/roby/relations/directed_relation_support.rb, line 259 def [](object, graph) relation_graphs[graph].edge_info(self, object) end
# File lib/roby/relations/directed_relation_support.rb, line 263 def []=(object, relation, value) relation_graphs[relation].set_edge_info(self, object, value) end
Add a new child object in the relation
relation. This calls
-
adding_child_object on
self
and adding_parent_object onchild
just before the relation is added -
added_child_object on
self
and added_parent_object onchild
just after
# File lib/roby/relations/directed_relation_support.rb, line 171 def add_child_object(child, relation, info = nil) relation_graphs[relation].add_relation(self, child, info) end
Add a new parent object in the relation
relation
-
adding_child_object on
parent
and adding_parent_object onself
just before the relation is added -
added_child_object on
parent
and added_child_object onself
just after
# File lib/roby/relations/directed_relation_support.rb, line 180 def add_parent_object(parent, relation, info = nil) relation_graphs[parent].add_child_object(self, relation, info) end
# File lib/roby/relations/directed_relation_support.rb, line 68 def child_object?(object, relation = nil) relation_graphs[relation].has_edge?(self, object) end
# File lib/roby/relations/directed_relation_support.rb, line 162 def child_objects(relation) relation_graphs[relation].out_neighbours(self) end
Removes self
from all the graphs it is included in.
# File lib/roby/relations/directed_relation_support.rb, line 110 def clear_vertex(remove_strong: true) for rel in sorted_relations graph = relation_graphs[rel] if remove_strong || !graph.strong? if graph.remove_vertex(self) removed = true end end end removed end
# File lib/roby/relations/directed_relation_support.rb, line 88 def each_child_object(graph, &block) relation_graphs[graph].each_out_neighbour(self, &block) end
# File lib/roby/relations/directed_relation_support.rb, line 84 def each_in_neighbour(graph, &block) relation_graphs[graph].each_in_neighbour(self, &block) end
# File lib/roby/relations/directed_relation_support.rb, line 92 def each_out_neighbour(graph, &block) relation_graphs[graph].each_out_neighbour(self, &block) end
# File lib/roby/relations/directed_relation_support.rb, line 80 def each_parent_object(graph, &block) relation_graphs[graph].each_in_neighbour(self, &block) end
Enumerate all relations that are relevant for this plan object
Unlike {#each_relation_graph}, which enumerate only the graphs that include self, it enumerates all possible relations for self
@yieldparam [Class<Graph>]
# File lib/roby/relations/directed_relation_support.rb, line 24 def each_relation return enum_for(__method__) if !block_given? relation_graphs.each do |k, g| yield(k) if k != g end end
Enumerate the relation graphs that include this vertex
@yieldparam [Graph]
# File lib/roby/relations/directed_relation_support.rb, line 34 def each_relation_graph return enum_for(__method__) if !block_given? relation_graphs.each do |k, g| yield(g) if g.has_vertex?(self) && (k == g) end end
Yields each relation this vertex is part of, starting with the most specialized relations
# File lib/roby/relations/directed_relation_support.rb, line 105 def each_relation_sorted(&block) sorted_relations.each(&block) end
Enumerate the relation graphs that include this vertex and that are subgraphs of no other graphs
@yieldparam [Graph]
# File lib/roby/relations/directed_relation_support.rb, line 45 def each_root_relation_graph return enum_for(__method__) if !block_given? each_relation_graph do |g| yield(g) if g.root_relation? end end
# File lib/roby/relations/directed_relation_support.rb, line 157 def enum_child_objects(relation) Roby.warn_deprecated "#enum_child_objects is deprecated, use #parent_objects or #each_parent_object instead" child_objects(relation) end
# File lib/roby/relations/directed_relation_support.rb, line 148 def enum_parent_objects(relation) Roby.warn_deprecated "#enum_parent_objects is deprecated, use #parent_objects or #each_parent_object instead" parent_objects(relation) end
# File lib/roby/relations/directed_relation_support.rb, line 123 def enum_relations Roby.warn_deprecated "DirectedRelationSupport#enum_relations is deprecated, use #each_relation instead" each_relation end
# File lib/roby/relations/directed_relation_support.rb, line 60 def leaf?(relation = nil) if relation relation_graphs[relation].leaf?(self) else each_relation_graph.all? { |g| g.leaf?(self) } end end
# File lib/roby/relations/directed_relation_support.rb, line 72 def parent_object?(object, relation = nil) relation_graphs[relation].has_edge?(object, self) end
# File lib/roby/relations/directed_relation_support.rb, line 153 def parent_objects(relation) relation_graphs[relation].in_neighbours(self) end
# File lib/roby/relations/directed_relation_support.rb, line 14 def relation_graph_for(rel) relation_graphs.fetch(rel) end
The array of relations this object is part of
# File lib/roby/relations/directed_relation_support.rb, line 129 def relations; each_relation.to_a end
Remove all edges in which self
is the source and child
the target. If relation
is given, it removes only the edge in that relation graph.
# File lib/roby/relations/directed_relation_support.rb, line 187 def remove_child_object(child, relation = nil) if !relation for rel in sorted_relations rel.remove_relation(self, child) end else relation_graphs[relation].remove_relation(self, child) end end
Remove all edges in which self
is the source. If relation
is given, it removes only the edges in that relation graph.
# File lib/roby/relations/directed_relation_support.rb, line 199 def remove_children(relation = nil) if !relation for rel in sorted_relations remove_children(rel) end return end children = child_objects(relation).to_a for child in children remove_child_object(child, relation) end end
Remove all edges in which child
is the source and self
the target. If relation
is given, it removes only the edge in that relation graph.
# File lib/roby/relations/directed_relation_support.rb, line 216 def remove_parent_object(parent, relation = nil) parent.remove_child_object(self, relation) end
Remove all edges in which self
is the target. If relation
is given, it removes only the edges in that relation graph.
# File lib/roby/relations/directed_relation_support.rb, line 222 def remove_parents(relation = nil) if !relation for rel in sorted_relations remove_parents(rel) end return end parents = parent_objects(relation).to_a for parent in parents remove_parent_object(relation, parent) end end
Remove all relations that point to or come from to
If to
is nil, it removes all edges in which self
is involved.
If relation
is not nil, only edges of that relation graph are removed.
# File lib/roby/relations/directed_relation_support.rb, line 240 def remove_relations(relation = nil) if !relation for rel in sorted_relations remove_relations(rel) end return end relation = relation_graphs[relation] return if !relation.has_vertex?(self) each_parent_object(relation).to_a.each do |parent| relation.remove_relation(parent, self) end each_child_object(relation).to_a.each do |child| relation.remove_relation(self, child) end end
# File lib/roby/relations/directed_relation_support.rb, line 52 def root?(relation = nil) if relation relation_graphs[relation].root?(self) else each_relation_graph.all? { |g| g.root?(self) } end end
# File lib/roby/relations/directed_relation_support.rb, line 96 def sorted_relations Relations.all_relations. find_all do |rel| (rel = relation_graphs.fetch(rel, nil)) && rel.has_vertex?(self) end end