Class: Roby::Queries::TaskEventGeneratorMatcher

Inherits:
PlanObjectMatcher show all
Defined in:
lib/roby/queries/task_event_generator_matcher.rb

Overview

Object that allows to describe a task’s event generator and match it in the plan

It uses a task matcher to match the underlying task

Instance Attribute Summary collapse

Attributes inherited from PlanObjectMatcher

#children, #indexed_neg_predicates, #indexed_predicates, #instance, #model, #owners, #parents, #scope

Attributes inherited from MatcherBase

#neg_predicates, #predicates

Instance Method Summary collapse

Methods inherited from PlanObjectMatcher

#executable?, #global_scope, #global_scope?, #handle_parent_child_arguments, #handle_parent_child_match, #local_scope, #local_scope?, #matches_child_constraints?, #matches_parent_constraints?, #not_self_owned, #owned_by, #self_owned, #with_child, #with_instance, #with_model, #with_parent

Methods included from DRoby::V5::Queries::PlanObjectMatcherDumper

#droby_dump

Methods inherited from MatcherBase

#&, #add_neg_predicate, #add_predicate, declare_class_methods, #describe_failed_match, #each, #indexed_query?, #match, match_predicate, match_predicates, #negate, #reset, #to_a, #to_set, #|

Constructor Details

#initialize(task_matcher = Roby::Task.match, symbol = Queries.any) ⇒ TaskEventGeneratorMatcher



21
22
23
24
25
26
27
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 21

def initialize(task_matcher = Roby::Task.match, symbol = Queries.any)
    symbol = symbol.to_s if symbol.respond_to?(:to_sym)
    @symbol = symbol
    @task_matcher = task_matcher
    @generalized = false
    super()
end

Instance Attribute Details

#symbol#=== (readonly)



11
12
13
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 11

def symbol
  @symbol
end

#task_matcherTaskMatcher (readonly)



14
15
16
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 14

def task_matcher
  @task_matcher
end

Instance Method Details

#===(object) ⇒ Boolean

Tests whether the given task event generator matches self



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 61

def ===(object)
    return unless object.kind_of?(TaskEventGenerator)

    if match_not_generalized(object)
        true
    elsif generalized? && object.plan
        forwarding_graph = object.relation_graph_for(
            EventStructure::Forwarding
        )
        forwarding_graph.depth_first_visit(object) do |generator|
            return true if match_not_generalized(generator)
        end
        false
    end
end

#each_in_plan(plan) ⇒ Object

Enumerate the objects matching self in the plan



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 84

def each_in_plan(plan)
    if generalized?
        raise ArgumentError,
              "cannot resolve a generalized matcher in the plan"
    end

    return enum_for(__method__, plan) unless block_given?

    @task_matcher.each_in_plan(plan) do |task|
        event = task.event(symbol)
        yield(event) if self === event
    end
end

#generalizedObject

Makes this matcher a generalized matcher

See Also:



32
33
34
35
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 32

def generalized
    @generalized = true
    self
end

#generalized?Boolean



19
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 19

attr_predicate :generalized?

#match_not_generalized(object) ⇒ Object



77
78
79
80
81
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 77

def match_not_generalized(object)
    (symbol === object.symbol.to_s) &&
        plan_object_match(object) &&
        (task_matcher === object.task)
end

#plan_object_matchObject



55
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 55

alias plan_object_match ===

#to_sObject



51
52
53
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 51

def to_s
    "#{task_matcher}.#{symbol}"
end

#with_name(symbol) ⇒ Object

Adds a matching object for the event’s name



42
43
44
45
46
47
48
49
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 42

def with_name(symbol)
    @symbol =
        if symbol.respond_to?(:to_sym) then symbol.to_s
        else
            symbol
        end
    self
end