class Syskit::Models::CompositionSpecialization
Representation of a composition specialization
Attributes
Cache of compatibilities: this is a cache of other Specialization objects that can be applied at the same time that this one.
Two compositions are compatible if their specialization sets are either disjoints (they don't specialize on the same children) or if it is possible that a component provides both the required models.
The composition model that can be used to instanciate this specialization. This is a subclass of the composition that this specialization specializes.
The name of the composition model that is being specialized.
It is only used for display purposes
@return [String]
The set of blocks that have been passed to the corresponding specialize calls. These blocks are going to be evaluated in the task model that will be created (on demand) to create tasks of this specialization
The specialization constraints, as a map from child name to set of models (data services or components)
@return [{
Create a new composition specialization object which is the merge of all
the given specs @return [CompositionSpecialization] Add new specializations and blocks to Returns true if See compatibilities
for more information on compatible specializations True if this does not specialize on anything Returns true if Merge the specialization specification of Tests if this specialization could be used for the given selection. All the
children in the selection must have a corresponding entry in the
specialization for this to return true @param
[{String=>Array<Model<Component>,Model<DataService>>}]
selection @return [Boolean] @example @see weak_match? Tests if this specialization could be used for the given selection,
ignoring selections that do not have a corresponding entry in the
specialization @param
[{String=>Array<Model<Component>,Model<DataService>>}]
selection @return [Boolean] @example @see strong_match?Public Class Methods
# File lib/syskit/models/composition_specialization.rb, line 167
def self.merge(*specs)
composite_spec = CompositionSpecialization.new
specs.each do |spec|
composite_spec.merge(spec)
end
composite_spec
end
# File lib/syskit/models/composition_specialization.rb, line 98
def initialize(spec = Hash.new, block = nil)
@specialized_children = spec
@specialization_blocks = Array.new
if block
@specialization_blocks << block
end
@compatibilities = Set.new
end
Public Instance Methods
self without checking
for compatibility# File lib/syskit/models/composition_specialization.rb, line 152
def add(new_spec, new_blocks)
specialized_children.merge!(new_spec) do |child_name, models_a, models_b|
Models.merge_model_lists(models_a, models_b)
end
if new_blocks.respond_to?(:to_ary)
specialization_blocks.concat(new_blocks)
elsif new_blocks
specialization_blocks << new_blocks
end
end
spec is compatible with self# File lib/syskit/models/composition_specialization.rb, line 128
def compatible_with?(spec)
empty? || spec == self || spec.empty? || compatibilities.include?(spec)
end
# File lib/syskit/models/composition_specialization.rb, line 114
def empty?
specialized_children.empty?
end
# File lib/syskit/models/composition_specialization.rb, line 132
def find_specialization(child_name, model)
if selected_models = specialized_children[child_name]
if matches = selected_models.find_all { |m| m.fullfills?(model) }
if !matches.empty?
return matches
end
end
end
end
self specializes on child_name in
a way that is compatible with model# File lib/syskit/models/composition_specialization.rb, line 144
def has_specialization?(child_name, model)
if selected_models = specialized_children[child_name]
selected_models.any? { |m| m.fullfills?(model) }
end
end
# File lib/syskit/models/composition_specialization.rb, line 107
def initialize_copy(old)
@specialized_children = old.specialized_children.dup
@specialization_blocks = old.specialization_blocks.dup
@compatibilities = old.compatibilities.dup
end
other_spec into
self# File lib/syskit/models/composition_specialization.rb, line 177
def merge(other_spec)
@compatibilities =
if empty?
other_spec.compatibilities.dup
else
compatibilities & other_spec.compatibilities.dup
end
@compatibilities << other_spec
add(other_spec.specialized_children, other_spec.specialization_blocks)
self
end
spec = CompositionSpecialization.new 'srv' => component, 'child' => composition
spec.strong_match?('srv' => component) => false
spec.strong_match?('srv' => component, 'child' => composition) => true
# assuming that 'component' does not provide 'data_service'
spec.strong_match?('srv' => data_service, 'child' => composition) => false
# File lib/syskit/models/composition_specialization.rb, line 231
def strong_match?(selection)
specialized_children.all? do |child_name, child_models|
if this_selection = selection[child_name]
this_selection.fullfills?(child_models)
end
end
end
# File lib/syskit/models/composition_specialization.rb, line 118
def to_s
root_name.to_s + "/" + specialized_children.map do |child_name, child_models|
"#{child_name}.is_a?(#{child_models.map(&:short_name).join(",")})"
end.join(",")
end
spec = CompositionSpecialization.new 'srv' => component, 'child' => composition
spec.weak_match?('srv' => component) => true
# assuming that 'component' does not provide 'data_service'
spec.weak_match?('srv' => data_service) => false
# File lib/syskit/models/composition_specialization.rb, line 204
def weak_match?(selection)
has_match = false
result = specialized_children.all? do |child_name, child_models|
if this_selection = selection[child_name]
has_match = true
this_selection.fullfills?(child_models)
else true
end
end
has_match && result
end