Class: IDL::Type::Integer

Inherits:
IDL::Type show all
Defined in:
lib/ridl/type.rb

Constant Summary

Constants inherited from IDL::Type

Long, LongLong, Octet, Short, ULong, ULongLong, UShort

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IDL::Type

#instantiate, #is_anonymous?, #is_complete?, #is_local?, #is_node?, #is_template?, #resolved_node, #resolved_type, #typeerror, #typename

Class Method Details

.bitsObject



125
126
127
# File 'lib/ridl/type.rb', line 125

def self.bits
  self::BITS
end

.is_unsigned?Boolean

Returns:



121
122
123
# File 'lib/ridl/type.rb', line 121

def self.is_unsigned?
  self::Range.first == 0
end

.newclass(range, bits) ⇒ Object



149
150
151
152
153
154
# File 'lib/ridl/type.rb', line 149

def Integer.newclass(range, bits)
  k = Class.new(self)
  k.const_set('Range', range)
  k.const_set('BITS', bits)
  k
end

Instance Method Details

#in_range?(val) ⇒ Boolean

Returns:



141
142
143
# File 'lib/ridl/type.rb', line 141

def in_range?(val)
  val >= self.min && val <= self.max
end

#maxObject



137
138
139
# File 'lib/ridl/type.rb', line 137

def max
  self.class::Range.last
end

#minObject



133
134
135
# File 'lib/ridl/type.rb', line 133

def min
  self.class::Range.first
end

#narrow(obj) ⇒ Object



115
116
117
118
119
# File 'lib/ridl/type.rb', line 115

def narrow(obj)
  typeerror(obj) unless ::Integer === obj
  typeerror(obj) unless self.class::Range === obj
  obj
end

#next(val) ⇒ Object



145
146
147
# File 'lib/ridl/type.rb', line 145

def next(val)
  val < self.max ? val + 1 : self.min
end

#range_lengthObject



129
130
131
# File 'lib/ridl/type.rb', line 129

def range_length
  1 + (self.class::Range.last - self.class::Range.first)
end