OpenCores
URL https://opencores.org/ocsvn/soc_maker/soc_maker/trunk

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [parameter.rb] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      parameter.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#
37
#     A small classes, used to group information
38
#     and to verify, auto-correct and auto-complete
39
#     this information:
40
#     This class represents an instance parameter for
41
#     a core with the following values:
42
#        - type (mandatory)
43
#        - default
44
#        - min
45
#        - max
46
#        - visible
47
#        - editable
48
#        - description
49
#     Most of the fields are reserved for future implementations.
50
#
51
###############################################################
52
 
53
 
54
module SOCMaker
55
class Parameter
56
  include ERR
57
  attr_accessor :type
58
  attr_accessor :default
59
  attr_accessor :min
60
  attr_accessor :max
61
  attr_accessor :visible
62
  attr_accessor :editable
63
  attr_accessor :description
64 8 feddischso
  attr_accessor :choice
65
 
66 9 feddischso
  def initialize( type, optional = {} )
67
    init_with( { 'type' => type }.merge( optional ) )
68 3 feddischso
  end
69
 
70
  def encode_with( coder )
71
    %w[ type default min max
72
        visible editable description ].
73
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
74
  end
75
  def init_with( coder )
76
 
77
    serr_if( coder[ 'type' ] == nil,
78
      'no parameter type specified',
79
      field: "type" )
80
    @type = coder[ 'type' ]
81
    verr_if( !@type.is_a?( String ),
82
      "Parameter type is not defined with string",
83
      field: "parameter" )
84
    verr_if( @type.size == 0,
85
      "Parameter type string has zero length",
86
      field: "parameter" )
87
 
88
    @default      = coder[ 'default'     ] || 0
89
    @min          = coder[ 'min'         ] || 0
90
    @max          = coder[ 'max'         ] || 0
91
    @visible      = coder[ 'visible'     ] || true
92
    @editable     = coder[ 'editable'    ] || false
93
    @description  = coder[ 'description' ] || ''
94 8 feddischso
    @choice       = coder[ 'choice'      ] || []
95 3 feddischso
  end
96
 
97
 
98
  def ==(o)
99
    o.class         == self.class       &&
100
      o.type        == self.type        &&
101
      o.default     == self.default     &&
102
      o.min         == self.min         &&
103
      o.max         == self.max         &&
104
      o.visible     == self.visible     &&
105
      o.editable    == self.editable    &&
106 8 feddischso
      o.description == self.description &&
107
      o.choice      == self.choice
108 3 feddischso
  end
109
 
110
 
111
end
112
end
113
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.