class SOCMaker::IfcDef

A small classes, used to group information and to verify, auto-correct and auto-complete this information: The class represents an interface definition containing

Note: instances of this class are used withing core-definitions. Different cores may use the same interface, but with a different naming of the ports. For this reason, the id is used to identify, which interface specification (SOCMaker::IfcSpc) is defined. The port-hash makes the relation between the core port-naming and the IfcSpc port-naming.

Attributes

dir[RW]

direction

id[RW]

id of the interface specification

name[RW]

name of interface definition

ports[RW]

the port hash, containing the IfcPort instances

Public Class Methods

new( name, id, dir, ports ) click to toggle source

The constructor expects a name, id, dir (direction) and ports as mandatory arguments.

# File lib/soc_maker/ifc_def.rb, line 72
def initialize( name, id, dir, ports )
  init_with( 'name'     => name,
             'dir'      => dir,
             'id'       => id,
             'ports'    => ports )
end

Public Instance Methods

==(o) click to toggle source

Equality operator

# File lib/soc_maker/ifc_def.rb, line 183
def ==(o)
  o.class         == self.class       && 
  o.name          == self.name        &&
  o.dir           == self.dir         &&
  o.id            == self.id     &&
  o.ports         == self.ports       
end
consistence_check() click to toggle source

Runs a consistence check: it ensures, that the port-reference is unique.

# File lib/soc_maker/ifc_def.rb, line 172
def consistence_check    
  tmp = {}
  ports.each {|k,v| tmp[v.spc_ref] = k}
  consistence_error "The port reference must be unique",
      name: @name if ports.size != tmp.size
end
encode_with( coder ) click to toggle source

Encoder method (to yaml)

coder

An instance of the Psych::Coder to encode this class to a YAML file

# File lib/soc_maker/ifc_def.rb, line 84
def encode_with( coder )
  init_error_if !coder.is_a?( Psych::Coder ), 
              'coder is not given as Psych::Coder'
  %w[ name dir ports ].
        each { |v| coder[ v ] = instance_variable_get "@#{v}" }
  coder[ "id" ] = @id.to_s
end
init_with( coder ) click to toggle source

Initialization method (from yaml)

coder

An instance of the Psych::Coder to init this class from a YAML file

# File lib/soc_maker/ifc_def.rb, line 98
def init_with( coder )

  init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 
              'coder is not given as Hash neither as Psych::Coder'

  # name
  init_error 'no name defined for this interface',
    field: 'name' if coder[ 'name' ] == nil

  @name = coder[ 'name' ]

  init_error 'Interface name is not defined as string', 
    instance: @name,
    field: 'name' if !@name.is_a?( String )


  init_error "Name has zero length",
      field: "name" if @name.size == 0

  # id
  init_error 'id is not given for interface',
    instance: @name,
    field:   'id' if coder[ 'id' ] == nil

  init_error 'Interface id is not defined as string',
    instance: @name,
    field:    'id' if !coder[ 'id' ].is_a?( String )

  init_error "Version has zero length",
      field: "name" if coder[ 'id' ].size == 0


  @id = coder[ 'id' ].to_sym


  # ports
  init_error "No ports are given for interface definition",
    field: 'ports' if coder[ 'ports' ] == nil

  @ports = coder[ 'ports' ]
  init_error 'no ports are given for this interface', 
    instance: @name,
    field:    'ports' if !@ports.is_a?( Hash )  || @ports.size == 0

  @ports.each do |name, port|
    init_error 'no interface port found',
      instance: @name + name.to_s,
      field:    'ports' if port == nil


    init_error 'Port is not of type SocMaker::IfcPort (use SOCM_PORT)',
      instance: @name + name.to_s,
      field:    'ports' if !port.is_a?( SOCMaker::IfcPort )

  end

  # direction
  init_error  'Interface direction is not given',
    instance: @name,
    field:    'dir' if coder[ 'dir' ] == nil

  @dir = coder[ 'dir' ]
  init_error 'Interface direction must be 0 or 1',
    instance: @name,
    value: coder['dir' ],
    field:    'dir' if @dir != 0 && @dir != 1



end