Class: Roby::Queries::OrMatcher

Inherits:
MatcherBase show all
Includes:
DRoby::V5::Queries::OrMatcherDumper
Defined in:
lib/roby/queries/or_matcher.rb,
lib/roby/droby/enable.rb

Overview

Combines multiple task matching predicates through a OR boolean operator. I.e. it will match if any of the underlying predicates match.

Direct Known Subclasses

Tasks

Defined Under Namespace

Classes: Tasks

Instance Attribute Summary

Attributes inherited from MatcherBase

#neg_predicates, #predicates

Instance Method Summary collapse

Methods included from DRoby::V5::Queries::OrMatcherDumper

#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(*ops) ⇒ OrMatcher

Create a new OrMatcher object combining the given predicates.



9
10
11
12
13
# File 'lib/roby/queries/or_matcher.rb', line 9

def initialize(*ops)
    super()

    @ops = ops
end

Instance Method Details

#<<(op) ⇒ Object

Add a new predicate to the combination



16
17
18
19
# File 'lib/roby/queries/or_matcher.rb', line 16

def <<(op)
    @ops << op
    self
end

#===(task) ⇒ Object



26
27
28
# File 'lib/roby/queries/or_matcher.rb', line 26

def ===(task)
    @ops.any? { |op| op === task }
end

#each_in_plan(plan) ⇒ Object

Enumerate the objects matching self in the plan



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/roby/queries/or_matcher.rb', line 31

def each_in_plan(plan)
    return enum_for(__method__, plan) unless block_given?

    seen = Set.new
    seen.compare_by_identity
    @ops.each do |op|
        op.each_in_plan(plan) do |obj|
            next unless seen.add?(obj)

            yield(obj)
        end
    end
end

#merge(other) ⇒ Object



21
22
23
24
# File 'lib/roby/queries/or_matcher.rb', line 21

def merge(other)
    @ops.concat(other.instance_variable_get(:@ops))
    self
end