class SPNet::Link

Form a connection between an OutPort and an InPort.

@author James Tunnell

Constants

ARG_SPECS

Define arg specs to use in processing hashed arguments during initialize.

Attributes

from[R]
to[R]

Public Class Methods

new(args = {}) click to toggle source

A new instance of Link. Link is not active by default (does not set from.link and to.link to self). @param [Hash] args Hashed arguments for initialization. See Link::ARG_SPECS

for details of which keys are required.
# File lib/spnet/core/link.rb, line 21
def initialize args = {}
  hash_make args, Link::ARG_SPECS
  
  raise ArgumentError, "from port class #{@from.class} is not a #{@to.matching_class}" unless @from.is_a?(@to.matching_class)
  raise ArgumentError, "to port class #{@to.class} is not a #{@from.matching_class}" unless @to.is_a?(@from.matching_class)
end

Public Instance Methods

activate() click to toggle source

Make the link active by setting from.link and to.link to self.

# File lib/spnet/core/link.rb, line 29
def activate
  @from.set_link self
  @to.set_link self
end
active?() click to toggle source

Return true if the link is active (from.link and to.link are set to to self).

# File lib/spnet/core/link.rb, line 41
def active?
  (@from.link == self) && (@to.link == self)
end
deactivate() click to toggle source

Make the link inactive by setting from.link and to.link to nil.

# File lib/spnet/core/link.rb, line 35
def deactivate
  @from.clear_link
  @to.clear_link
end
save_state(blocks) click to toggle source

Produce a LinkState object from the current Link object.

# File lib/spnet/core/link.rb, line 46
def save_state blocks
  from, to = nil, nil
  
  blocks.each do |block_name, block|
    block.out_ports.each do |port_name, port|
      if port == @from
        from = PortLocater.new(:block_name => block_name, :port_name => port_name)
        break
      end
    end
    
    block.in_ports.each do |port_name, port|
      if port == @to
        to = PortLocater.new(:block_name => block_name, :port_name => port_name)
        break
      end
    end
  end
  
  raise "could not find from port" if from.nil?
  raise "could not find to port" if to.nil?
  return LinkState.new(:from => from, :to => to)
end