Class: Roby::Planning::MethodModel

Inherits:
Object
  • Object
show all
Includes:
MethodInheritance
Defined in:
lib/roby/planning/model.rb

Overview

The model of a planning method. This does not define an actual implementation of the method, only the model methods should abide to.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MethodInheritance

#validate

Constructor Details

#initialize(name, options = Hash.new) ⇒ MethodModel

Returns a new instance of MethodModel.



154
# File 'lib/roby/planning/model.rb', line 154

def initialize(name, options = Hash.new); @name, @options = name, options end

Instance Attribute Details

#nameObject (readonly)

The model name



150
151
152
# File 'lib/roby/planning/model.rb', line 150

def name
  @name
end

#optionsObject (readonly)

The model options, as a Hash



152
153
154
# File 'lib/roby/planning/model.rb', line 152

def options
  @options
end

Instance Method Details

#==(model) ⇒ Object



155
156
157
# File 'lib/roby/planning/model.rb', line 155

def ==(model)
    name == model.name && options == model.options
end

#freezeObject

Do not allow changing this model anymore



200
201
202
203
# File 'lib/roby/planning/model.rb', line 200

def freeze
    options.freeze
    super
end

#initialize_copy(from) ⇒ Object

:nodoc:



205
206
207
208
# File 'lib/roby/planning/model.rb', line 205

def initialize_copy(from) # :nodoc:
    @name    = from.name.dup
    @options = from.options.dup
end

#merge(new_options) ⇒ Object

call-seq:

merge(new_options)	    => self

Add new options in this model. Raises ArgumentError if the new options cannot be merged because they are incompatible with the current model definition



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/roby/planning/model.rb', line 165

def merge(new_options)
    validate_options(new_options, [:returns, :reuse])
    validate_option(new_options, :returns, false) do |rettype| 
        if options[:returns] && options[:returns] != rettype
            raise ArgumentError, "return type already specified for method #{name}"
        end
        options[:returns] = rettype
    end
    validate_option(new_options, :reuse, false) do |flag|
        if options.has_key?(:reuse) && options[:reuse] != flag
            raise ArgumentError, "the reuse flag is already set to #{options[:reuse]} on #{name}"
        end
        options[:reuse] = flag
        true
    end

    self
end

#overload(old_model) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/roby/planning/model.rb', line 184

def overload(old_model)
    if old_returns = old_model.returns
        if returns && !(returns < old_returns)
            raise ArgumentError, "new return type #{returns} is not a subclass of the old one #{old_returns}"
        elsif !returns
            options[:returns] = old_returns
        end
    end
    if options.has_key?(:reuse) && old_model.options.has_key?(:reuse) && options[:reuse] != old_model.reuse
        raise ArgumentError, "the reuse flag for #{name}h as already been set to #{options[:reuse]} on our parent model"
    elsif !options.has_key?(:reuse) && old_model.options.has_key?(:reuse)
        options[:reuse] = old_model.reuse
    end
end

#returnsObject

The return type the method model defines

If this is nil, methods of this model may return a task array or a task aggregation



145
# File 'lib/roby/planning/model.rb', line 145

def returns;    options[:returns] end

#reuse?Boolean

If the model allows reusing tasks already in the plan

Returns:

  • (Boolean)


147
# File 'lib/roby/planning/model.rb', line 147

def reuse?; !options.has_key?(:reuse) || options[:reuse] end

#to_sObject



210
# File 'lib/roby/planning/model.rb', line 210

def to_s; "#{name}(#{options})" end