Module: Roby::DirectedRelationSupport

Includes:
BGL::Vertex
Included in:
PlanObject
Defined in:
lib/roby/relations.rb

Overview

Base support for relations. It is mixed-in objects that are part of relation networks (like Task and EventGenerator)

Instance Method Summary collapse

Instance Method Details

#add_child_object(child, relation, info = nil) ⇒ Object

Add a new child object in the relation relation. This calls

  • #adding_child_object on self and #adding_parent_object on child just before the relation is added

  • #added_child_object on self and #added_parent_object on child just after



54
55
56
57
# File 'lib/roby/relations.rb', line 54

def add_child_object(child, relation, info = nil)
    check_is_relation(relation)
    relation.add_relation(self, child, info)
end

#add_parent_object(parent, relation, info = nil) ⇒ Object

Add a new parent object in the relation relation

  • #adding_child_object on parent and #adding_parent_object on self just before the relation is added

  • #added_child_object on parent and #added_child_object on self just after



64
65
66
# File 'lib/roby/relations.rb', line 64

def add_parent_object(parent, relation, info = nil)
    parent.add_child_object(self, relation, info)
end

#check_is_relation(type) ⇒ Object

Raises if type does not look like a relation



151
152
153
154
155
# File 'lib/roby/relations.rb', line 151

def check_is_relation(type) # :nodoc:
    if type && !(RelationGraph === type)
	raise ArgumentError, "#{type} (of class #{type.class}) is not a relation type"
    end
end

Computes and returns the set of objects related with this one (parent or child). If relation is given, enumerate only for this relation, otherwise enumerate for all relations. If result is given, it is a ValueSet in which the related objects are added



33
34
35
36
37
38
39
40
41
42
# File 'lib/roby/relations.rb', line 33

def related_objects(relation = nil, result = nil)
    result ||= ValueSet.new
    if relation
	result.merge(parent_objects(relation).to_value_set)
	result.merge(child_objects(relation).to_value_set)
    else
	each_relation { |rel| related_objects(rel, result) }
    end
    result
end

#relationsObject

The array of relations this object is part of



27
# File 'lib/roby/relations.rb', line 27

def relations; enum_relations.to_a end

#remove_child_object(child, relation = nil) ⇒ Object

Remove the relation between self and child. If relation is given, remove only a relations in this relation kind.



86
87
88
89
90
91
# File 'lib/roby/relations.rb', line 86

def remove_child_object(child, relation = nil)
    check_is_relation(relation)
    apply_selection(relation, (relation || enum_relations)) do |relation|
	relation.remove_relation(self, child)
    end
end

#remove_children(relation = nil) ⇒ Object

Remove relations where self is a parent. If relation is given, remove only the relations in this relation graph.



95
96
97
98
99
100
101
# File 'lib/roby/relations.rb', line 95

def remove_children(relation = nil)
    apply_selection(relation, (relation || enum_relations)) do |relation|
	self.each_child_object(relation) do |child|
	    remove_child_object(child, relation)
	end
    end
end

#remove_parent_object(parent, relation = nil) ⇒ Object

Remove relations where self is a child. If relation is given, remove only the relations in this relation graph



105
106
107
# File 'lib/roby/relations.rb', line 105

def remove_parent_object(parent, relation = nil)
    parent.remove_child_object(self, relation)
end

#remove_parents(relation = nil) ⇒ Object

Remove all parents of self. If relation is given, remove only the parents in this relation graph



110
111
112
113
114
115
116
117
# File 'lib/roby/relations.rb', line 110

def remove_parents(relation = nil)
    check_is_relation(relation)
    apply_selection(relation, (relation || enum_relations)) do |relation|
	relation.each_parent_object(self) do |parent|
	    remove_parent_object(relation, parent)
	end
    end
end

#remove_relations(to = nil, relation = nil) ⇒ Object

Remove all relations that point to or come from to If to is nil, it removes all relations of self



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/roby/relations.rb', line 137

def remove_relations(to = nil, relation = nil)
    check_is_relation(relation)
    if to
	remove_parent_object(to, relation)
	remove_child_object(to, relation)
    else
	apply_selection(relation, (relation || enum_relations)) do |relation|
	    each_parent_object(relation) { |parent| remove_parent_object(parent, relation) }
	    each_child_object(relation) { |child| remove_child_object(child, relation) }
	end
    end
end