class SOCMaker::IfcSpc

This class represents an interface specification. It defines the data flow of individual ports as well as how much cores can be connected with this interface.

Attributes

id[RW]

ID of the interface

multiplicity[RW]

Multiplicity definition, must be a array with two entries. Each entry must be >=0 or a '*'

name[RW]

name of the interface specification

ports[RW]

Port hash

Public Class Methods

new( name, id, optional = {} ) click to toggle source

This constructor expects a name and an id as mandatory arguments. Everything else can be given as optinal arguments.

name

name of the interface specification

id

id of the interface specification

# File lib/soc_maker/ifc_spc.rb, line 67
def initialize( name, id, optional = {} )
  init_with( { 'name' => name, 
               'id' => id }.merge( optional ) )
end

Public Instance Methods

==(o) click to toggle source

Equality operator

# File lib/soc_maker/ifc_spc.rb, line 170
def ==(o)
  o.name                  == self.name                  && 
  o.id                    == self.id                    &&
  o.ports.to_yaml         == self.ports.to_yaml         &&
  o.multiplicity.to_yaml  == self.multiplicity.to_yaml  
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_spc.rb, line 76
def encode_with( coder )
  init_error_if !coder.is_a?( Psych::Coder ), 
              'coder is not given as Psych::Coder'
  %w[ name ports multiplicity ].
        each { |v| coder[ v ] = instance_variable_get "@#{v}" }
  coder[ "id" ] = @id.to_s
end
init_with( coder ) click to toggle source

Constructor: there is one mandatory attributes type and an optional one params.

type

The id of the core-definition, which is instanciated

params

Instanciation parameters

# File lib/soc_maker/ifc_spc.rb, line 91
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'

  init_error "Name is not defined",
      field: "name" if coder[ 'name' ] == nil
  @name = coder[ 'name' ]

  init_error "Name is not defined as string",
      field: "name" if !@name.is_a?( String )

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


  init_error "Id is not defined",
      field: "id"   if coder[ 'id' ] == nil

  @id = coder[ 'id' ]
  init_error "Version 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 = coder[ 'ports' ] || {}
  @ports.each do |pname, port| 

    init_error "Port field must be organized as a hash",
        instance: @name,
        field: "ports" if !port.is_a?( Hash )

    init_error "No port direction specified for #{pname}",
      instance: @name,
      field: "ports" if !port.has_key?( :dir )


    init_error_if(  !port[ :dir ].is_a?( Fixnum ) ||
                 ( port[ :dir ] != 0 && port[ :dir ] != 1 && port[ :dir ] != 2 ) ,
             "Port direction value for #{pname} is neither 0 nor 1 nor 3",
             instance: @name,
             field:    "ports" )

    port[ :mandatory ] = true if !port.has_key?( :mandatory )
    port[ :default ]   ||= '0'

  end

  @multiplicity = coder[ 'multiplicity' ] || [ 1, 1 ]

  init_error "multiplicity must contain exactly two entries " if @multiplicity.size != 2

  @multiplicity.each do |m|
    if !( m.is_a?( Fixnum ) && m >= 0 ||  m.is_a?( String ) && m == "*" )  
      init_error "multiplicity must be a fixnum or the string '*'"
    end
  end

end
n_connections_ok?( dir, n ) click to toggle source

Checks, if the number of connections for a direction is ok.

dir

direction (0 or 1)

n

number of desred connections

# File lib/soc_maker/ifc_spc.rb, line 159
def n_connections_ok?( dir, n )
  if @multiplicity[ dir ].is_a?( String ) && @multiplicity[ dir ] == "*"
    return true
  else
    return @multiplicity[ dir ] >=  n
  end
end