Class: Roby::EventConstraints::UnboundTaskPredicate::SingleEvent

Inherits:
Roby::EventConstraints::UnboundTaskPredicate show all
Defined in:
lib/roby/event_constraints.rb

Overview

Subclass of UnboundTaskPredicate to handle single event generators

This is the class that is e.g. returned by UnboundPredicateSupport#to_unbound_task_predicate

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Roby::EventConstraints::UnboundTaskPredicate

#and, #compile, #evaluate, #negate, #or, #pretty_print, #to_unbound_task_predicate

Constructor Details

#initialize(event_name, deadline: nil) ⇒ SingleEvent

Returns a new instance of SingleEvent.



906
907
908
909
910
911
# File 'lib/roby/event_constraints.rb', line 906

def initialize(event_name, deadline: nil)
    @event_name = event_name
    @required_events = [event_name].to_set
    @deadline = deadline
    super()
end

Instance Attribute Details

#event_nameObject (readonly)

The generator name as a symbol



901
902
903
# File 'lib/roby/event_constraints.rb', line 901

def event_name
  @event_name
end

#required_eventsObject (readonly)

The set of events required to compute this predicate. This is used by UnboundTaskPredicate#compile



904
905
906
# File 'lib/roby/event_constraints.rb', line 904

def required_events
  @required_events
end

Instance Method Details

#==(other) ⇒ Object



913
914
915
# File 'lib/roby/event_constraints.rb', line 913

def ==(other)
    other.kind_of?(SingleEvent) && other.event_name == event_name
end

#codeObject

Code generation to create the overall evaluated predicate



918
919
920
921
922
923
924
925
926
# File 'lib/roby/event_constraints.rb', line 918

def code
    if @deadline
        "task_#{event_name} && ("\
            "task_#{event_name}.time.to_f > #{@deadline.to_f}"\
        ")"
    else
        "!!task_#{event_name}"
    end
end

#explain_false(task) ⇒ Object



938
939
940
941
# File 'lib/roby/event_constraints.rb', line 938

def explain_false(task)
    generator = task.event(event_name)
    Explanation.new(false, self, [generator]) unless generator.emitted?
end

#explain_static(task) ⇒ Object



943
944
945
946
947
948
949
950
# File 'lib/roby/event_constraints.rb', line 943

def explain_static(task)
    event = task.event(event_name)
    if event.last
        Explanation.new(true, self, [event.last])
    elsif event.unreachable?
        Explanation.new(nil, self, [event])
    end
end

#explain_true(task) ⇒ Object

Returns an Explanation object that explains why self is true. Note that it is valid only if evaluate(task) actually returned true (it will silently return an invalid explanation if evaluate(task) returns false).



932
933
934
935
936
# File 'lib/roby/event_constraints.rb', line 932

def explain_true(task)
    return unless (event = task.event(event_name).last)

    Explanation.new(true, self, [event])
end

#followed_by(event) ⇒ Object



969
970
971
# File 'lib/roby/event_constraints.rb', line 969

def followed_by(event)
    FollowedBy.new(self, event.to_unbound_task_predicate)
end

#from_nowObject



961
962
963
# File 'lib/roby/event_constraints.rb', line 961

def from_now
    self.class.new(@event_name, deadline: Time.now)
end

#neverObject



957
958
959
# File 'lib/roby/event_constraints.rb', line 957

def never
    Never.new(self)
end

#not_followed_by(event) ⇒ Object



965
966
967
# File 'lib/roby/event_constraints.rb', line 965

def not_followed_by(event)
    NotFollowedBy.new(self, event.to_unbound_task_predicate)
end

#static?(task) ⇒ Boolean

Returns:

  • (Boolean)


952
953
954
955
# File 'lib/roby/event_constraints.rb', line 952

def static?(task)
    event = task.event(event_name)
    evaluate(task) || event.unreachable?
end

#to_sObject



973
974
975
# File 'lib/roby/event_constraints.rb', line 973

def to_s
    "#{event_name}?"
end