Class: VPI::S_vpi_value
- Inherits:
-
Object
- Object
- VPI::S_vpi_value
- Defined in:
- lib/ruby-vpi/core/struct.rb
Class Method Summary collapse
-
.detect_format(aValue) ⇒ Object
Attempts to detect the format of the given value.
Instance Method Summary collapse
-
#read(aFormat = self.format) ⇒ Object
Returns the value in the given format.
-
#write(aValue, aFormat) ⇒ Object
Writes the given value, which has the given format.
Class Method Details
.detect_format(aValue) ⇒ Object
Attempts to detect the format of the given value. Returns nil if detection is not possible.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby-vpi/core/struct.rb', line 28 def self.detect_format aValue if aValue.respond_to? :to_int VpiIntVal elsif aValue.respond_to? :to_float VpiRealVal elsif aValue.respond_to? :to_str VpiStringVal elsif aValue.is_a? S_vpi_time VpiTimeVal elsif aValue.is_a? S_vpi_vecval VpiVectorVal elsif aValue.is_a? S_vpi_strengthval VpiStrengthVal end end |
Instance Method Details
#read(aFormat = self.format) ⇒ Object
Returns the value in the given format.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby-vpi/core/struct.rb', line 79 def read aFormat = self.format case aFormat when VpiBinStrVal, VpiOctStrVal, VpiDecStrVal, VpiHexStrVal, VpiStringVal value.str.to_s when VpiScalarVal value.scalar.to_i when VpiIntVal value.integer.to_i when VpiRealVal value.real.to_f when VpiTimeVal value.time when VpiVectorVal value.vector when VpiStrengthVal value.strength else raise "unknown format: #{aFormat.inspect}" end end |
#write(aValue, aFormat) ⇒ Object
Writes the given value, which has the given format.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruby-vpi/core/struct.rb', line 50 def write aValue, aFormat case aFormat when VpiBinStrVal, VpiOctStrVal, VpiDecStrVal, VpiHexStrVal, VpiStringVal value.str = aValue.to_s when VpiScalarVal value.scalar = aValue.to_i when VpiIntVal value.integer = aValue.to_i when VpiRealVal value.real = aValue.to_f when VpiTimeVal value.time = aValue when VpiVectorVal value.vector = aValue when VpiStrengthVal value.strength = aValue else raise "unknown format: #{aFormat.inspect}" end end |