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 7

Go to most recent revision | 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
 
65
  def initialize( type, options = {} )
66
    init_with( { 'type' => type }.merge( options ) )
67
  end
68
 
69
  def encode_with( coder )
70
    %w[ type default min max
71
        visible editable description ].
72
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
73
  end
74
  def init_with( coder )
75
 
76
    serr_if( coder[ 'type' ] == nil,
77
      'no parameter type specified',
78
      field: "type" )
79
    @type = coder[ 'type' ]
80
    verr_if( !@type.is_a?( String ),
81
      "Parameter type is not defined with string",
82
      field: "parameter" )
83
    verr_if( @type.size == 0,
84
      "Parameter type string has zero length",
85
      field: "parameter" )
86
 
87
    @default      = coder[ 'default'     ] || 0
88
    @min          = coder[ 'min'         ] || 0
89
    @max          = coder[ 'max'         ] || 0
90
    @visible      = coder[ 'visible'     ] || true
91
    @editable     = coder[ 'editable'    ] || false
92
    @description  = coder[ 'description' ] || ''
93
 
94
  end
95
 
96
 
97
  def ==(o)
98
    o.class         == self.class       &&
99
      o.type        == self.type        &&
100
      o.default     == self.default     &&
101
      o.min         == self.min         &&
102
      o.max         == self.max         &&
103
      o.visible     == self.visible     &&
104
      o.editable    == self.editable    &&
105
      o.description == self.description
106
  end
107
 
108
 
109
end
110
end
111
 

powered by: WebSVN 2.1.0

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