class Roby::Queries::Query
A query is a TaskMatcher
that applies on a plan. It should, in general, be preferred to TaskMatcher
as it uses task indexes to be more efficient.
Queries
cache their result. I.e. once each
has been called to get the query results, the query will always return the same results until reset
has been called.
Attributes
The plan this query acts on
Search scope for queries on transactions. If equal to :local, the query will apply only on the scope of the searched transaction, otherwise it applies on a virtual plan that is the result of the transaction stack being applied.
The default is :global.
See local_scope
and global_scope
Public Class Methods
For each name in names
, define the name and not_name methods on Query
objects. When one of these methods is called on a Query
object, plan.name?(task) must return true (resp. false) for the task to match.
# File lib/roby/queries/query.rb, line 98 def match_plan_predicates(names) names.each do |name, predicate_name| predicate_name ||= name class_eval <<-EOD, __FILE__, __LINE__+1 def #{name} if neg_plan_predicates.include?(:#{predicate_name}) raise ArgumentError, "trying to match (#{name} & !#{name})" end plan_predicates << :#{predicate_name} self end def not_#{name} if plan_predicates.include?(:#{predicate_name}) raise ArgumentError, "trying to match (#{name} & !#{name})" end neg_plan_predicates << :#{predicate_name} self end EOD end end
Create a query object on the given plan
Roby::Queries::TaskMatcher::new
# File lib/roby/queries/query.rb, line 14 def initialize(plan = nil) @scope = :global @plan = plan super() @plan_predicates = Set.new @neg_plan_predicates = Set.new end
Public Instance Methods
True if task
matches the query. Call result_set
to have the set of tasks which match in the given plan.
Roby::Queries::TaskMatcher#===
# File lib/roby/queries/query.rb, line 163 def ===(task) for pred in plan_predicates return unless plan.send(pred, task) end for neg_pred in neg_plan_predicates return if plan.send(neg_pred, task) end return unless super true end
Changes the scope of this query. See scope
.
# File lib/roby/queries/query.rb, line 42 def global_scope @scope = :global self end
Roby::Queries::PlanObjectMatcher#indexed_sets
# File lib/roby/queries/query.rb, line 59 def indexed_sets(index) positive_sets, negative_sets = super if plan_predicates.include?(:mission_task?) positive_sets << plan.mission_tasks elsif neg_plan_predicates.include?(:mission_task?) negative_sets << plan.mission_tasks end if plan_predicates.include?(:permanent_task?) positive_sets << plan.permanent_tasks elsif neg_plan_predicates.include?(:permanent_task?) negative_sets << plan.permanent_tasks end return positive_sets, negative_sets end
Changes the scope of this query. See scope
.
# File lib/roby/queries/query.rb, line 37 def local_scope @scope = :local self end
Filters missions
Matches tasks in plan that are missions
# File lib/roby/queries/query.rb, line 122
Filters out missions
Matches tasks in plan that are not missions
# File lib/roby/queries/query.rb, line 129
Filters out permanent tasks
Matches tasks in plan that are not declared as permanent tasks
# File lib/roby/queries/query.rb, line 149 match_plan_predicates mission: :mission_task?
Filters permanent tasks
Matches tasks in plan that are declared as permanent tasks.
# File lib/roby/queries/query.rb, line 136
Changes the plan this query works on. This calls reset
(obviously)
# File lib/roby/queries/query.rb, line 48 def plan=(new_plan) reset @plan = new_plan end
# File lib/roby/queries/query.rb, line 22 def query self end
The set of tasks which match in plan. This is a cached value, so use reset
to actually recompute this set.
# File lib/roby/queries/query.rb, line 55 def result_set @result_set ||= plan.query_result_set(self) end
Filters tasks which have no parents in the query itself.
Will filter out tasks which have parents in relation
that are included in the query result.
# File lib/roby/queries/query.rb, line 156 def roots(relation) @result_set = plan.query_roots(result_set, relation) self end