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?, #matches?, #resolved_node, #resolved_type, #typeerror, #typename

Class Method Details

.bitsObject



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

def self.bits
  self::BITS
end

.is_unsigned?Boolean

Returns:



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

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

.newclass(range, bits) ⇒ Object



154
155
156
157
158
159
# File 'lib/ridl/type.rb', line 154

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:



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

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

#maxObject



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

def max
  self.class::Range.last
end

#minObject



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

def min
  self.class::Range.first
end

#narrow(obj) ⇒ Object



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

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

#next(val) ⇒ Object



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

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

#range_lengthObject



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

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