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

Attributes inherited from MatcherBase

#neg_predicates, #predicates

Instance Method Summary collapse

Methods inherited from PlanObjectMatcher

#executable?, #handle_parent_child_arguments, #handle_parent_child_match, #indexed_query?, #indexed_sets, match_predicate, #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

#&, declare_class_methods, #describe_failed_match, #each, #indexed_query?, #match, match_predicate, match_predicates, #negate, #|

Constructor Details

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

Returns a new instance of TaskEventGeneratorMatcher.



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

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

Instance Attribute Details

#symbol#=== (readonly)

Returns the required event name.

Returns:

  • (#===)

    the required event name



9
10
11
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 9

def symbol
  @symbol
end

#task_matcherTaskMatcher (readonly)

Returns the task matcher that describes this event’s task.

Returns:

  • (TaskMatcher)

    the task matcher that describes this event’s task



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

def task_matcher
  @task_matcher
end

Instance Method Details

#===(object) ⇒ Boolean

Tests whether the given task event generator matches self

Parameters:

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 65

def ===(object)
    return if !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

#filter(initial_set, index) ⇒ Object

Raises:

  • (NotImplementedError)

    Cannot yet do plan queries on task event generators



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

def filter(initial_set, index)
    raise NotImplementedError
end

#generalizedObject

Makes this matcher a generalized matcher

Returns:

  • self

See Also:



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

def generalized
    @generalized = true
    self
end

#generalized?Boolean

Returns if true, self will match the specified generator as well as any other generator that is forwarded to it. If false (the default) only the specified generator will match.

Returns:

  • (Boolean)

    if true, self will match the specified generator as well as any other generator that is forwarded to it. If false (the default) only the specified generator will match



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

attr_predicate :generalized?

#match_not_generalized(object) ⇒ Object



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

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



57
58
59
# File 'lib/roby/queries/task_event_generator_matcher.rb', line 57

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

#with_name(symbol) ⇒ Object

Adds a matching object for the event’s name

Parameters:

  • symbol (Regexp, Symbol, String, #===)

    an object that will allow to match the event’s name

Returns:

  • self



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

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