Class: SOCMaker::IfcSpc

Inherits:
Object
  • Object
show all
Includes:
ERR, YAML_EXT
Defined in:
lib/soc_maker/ifc_spc.rb

Overview

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.

Instance Attribute Summary collapse

Attributes included from YAML_EXT

#src_dir

Instance Method Summary collapse

Methods included from YAML_EXT

#save_yaml

Methods included from ERR

#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if

Constructor Details

#initialize(name, id, optional = {}) ⇒ IfcSpc

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



67
68
69
70
# File 'lib/soc_maker/ifc_spc.rb', line 67

def initialize( name, id, optional = {} )
  init_with( { 'name' => name, 
               'id' => id }.merge( optional ) )
end

Instance Attribute Details

#idObject

ID of the interface



52
53
54
# File 'lib/soc_maker/ifc_spc.rb', line 52

def id
  @id
end

#multiplicityObject

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



59
60
61
# File 'lib/soc_maker/ifc_spc.rb', line 59

def multiplicity
  @multiplicity
end

#nameObject

name of the interface specification



49
50
51
# File 'lib/soc_maker/ifc_spc.rb', line 49

def name
  @name
end

#portsObject

Port hash



55
56
57
# File 'lib/soc_maker/ifc_spc.rb', line 55

def ports
  @ports
end

Instance Method Details

#==(o) ⇒ Object

Equality operator



170
171
172
173
174
175
# 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) ⇒ Object

Encoder method (to yaml)

coder

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



76
77
78
79
80
81
82
# 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) ⇒ Object

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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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) ⇒ Boolean

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

dir

direction (0 or 1)

n

number of desred connections

Returns:

  • (Boolean)


159
160
161
162
163
164
165
# 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