class RCGTK::ConstantInteger
All integer constants inherit from this class.
@abstract
Attributes
@return [Boolean] If the integer is signed or not.
Public Class Methods
The constructor for ConstantInteger’s various sub-classes. This constructor is a bit complicated due to having two overloaded parameters, but once you see the valid combinations it is a bit simpler.
@example Constant
(signed) integer from Ruby Integer:
Int32.new(128)
@example Constant
(signed) base 8 integer from Ruby String:
Int32.new('72', 8)
@example Constant
integer of all 1s:
Int32.new
@param [FFI::Pointer, Integer, String, nil] overloaded0 Pointer to a ConstantInteger
, value, or string representing value. @param [Boolean, Integer] overloaded1 Signed or unsigned (when overloaded0 is Integer) or base used to
decode string value.
@param [Integer] size Optional length of string to use.
# File lib/rcgtk/value.rb, line 575 def initialize(overloaded0 = nil, overloaded1 = nil, size = nil) @ptr = case overloaded0 when FFI::Pointer overloaded0 when Integer @signed = overloaded1 or true Bindings.const_int(self.type, overloaded0, @signed.to_i) when String base = overloaded1 or 10 if size Bindings.const_int_of_string_and_size(self.type, overloaded0, size, base) else Bindings.const_int_of_string(self.type, overloaded0, base) end else @signed = true Bindings.const_all_ones(self.type) end end
Public Instance Methods
Modulo this value by another value. Uses signed modulo.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 734 def %(rhs) self.class.new(Bindings.const_s_rem(@ptr, rhs)) end
Multiply this value with another value.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 674 def *(rhs) self.class.new(Bindings.const_mul(@ptr, rhs)) end
Add this value with another value.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 612 def +(rhs) self.class.new(Bindings.const_add(@ptr, rhs)) end
Subtract a value from this value.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 643 def -(rhs) self.class.new(Bindings.const_sub(@ptr, rhs)) end
Negate this value.
@return [ConstantInteger] Instance of the same class
# File lib/rcgtk/value.rb, line 752 def -@ self.class.new(Bindings.const_neg(@ptr)) end
Divide this value by another value. Uses signed division.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 705 def /(rhs) self.class.new(Bindings.const_s_div(@ptr, rhs)) end
Bitwise AND this value with another.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 837 def and(rhs) self.class.new(Bindings.const_and(@ptr, rhs)) end
Arithmetic right shift.
@param [Integer] bits Number of bits to shift.
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 818 def ashr(bits) self.class.new(Bindings.const_a_shr(@ptr, bits)) end
Cast this constant integer to another number type.
@param [NumberType] type Desired type to cast to. @param [Boolean] signed Is the value signed or not.
@return [ConstantNumber] This value as as the given type.
# File lib/rcgtk/value.rb, line 876 def cast(type, signed = true) type.value_class.new(Bindings.const_int_cast(@ptr, check_cg_type(type, NumberType), signed.to_i)) end
Compare this value to another value.
@see Bindings
.enum_int_predicate
@param [Symbol] pred An integer predicate. @param [ConstantInteger] rhs Value
to compare to.
@return [Int1] Value
used to represent a Boolean value.
# File lib/rcgtk/value.rb, line 888 def cmp(pred, rhs) Int1.new(Bindings.const_i_cmp(pred, @ptr, rhs)) end
Divide this value by another value. Uses exact signed division.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 714 def extact_sdiv(rhs) self.class.new(Bindings.const_extact_s_div(@ptr, rhs)) end
Logical right shift.
@param [Integer] bits Number of bits to shift.
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 828 def lshr(bits) self.class.new(Bindings.const_l_shr(@ptr, bits)) end
Bitwise NOT this value.
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 862 def not self.class.new(Bindings.const_not(@ptr)) end
Add this value with another value. Performs no signed wrap addition.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 622 def nsw_add(rhs) self.class.new(Bindings.const_nsw_add(@ptr, rhs)) end
Multiply this value with another value. Perform no signed wrap multiplication.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 684 def nsw_mul(rhs) self.class.new(Bindings.const_nsw_mul(@ptr, rhs)) end
Negate this value. Uses no signed wrap negation.
@return [ConstantInteger] Instance of the same class
# File lib/rcgtk/value.rb, line 759 def nsw_neg self.class.new(Bindings.const_nsw_neg(@ptr)) end
Subtract a value from this value. Performs no signed wrap subtraction.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 653 def nsw_sub(rhs) self.class.new(Bindings.const_nsw_sub(@ptr, rhs)) end
Add this value with another value. Performs no unsigned wrap addition.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 632 def nuw_add(rhs) self.class.new(Bindings.const_nuw_add(@ptr, rhs)) end
Multiply this value with another value. Perform no unsigned wrap multiplication.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 694 def nuw_mul(rhs) self.class.new(Bindings.const_nuw_mul(@ptr, rhs)) end
Negate this value. Uses no unsigned wrap negation.
@return [ConstantInteger] Instance of the same class
# File lib/rcgtk/value.rb, line 766 def nuw_neg self.class.new(Bindings.const_nuw_neg(@ptr)) end
Subtract a value from this value. Performs no unsigned wrap subtraction.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 663 def nuw_sub(rhs) self.class.new(Bindings.const_nuw_sub(@ptr, rhs)) end
Bitwise OR this value with another.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 846 def or(rhs) self.class.new(Bindings.const_or(@ptr, rhs)) end
A wrapper method around the {#shift_left} and {#shift_right} methods.
@param [:left, :right] dir The direction to shift. @param [Integer] bits Number of bits to shift. @param [:arithmetic, :logical] mode Shift mode for right shifts.
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 782 def shift(dir, bits, mode = :arithmetic) case dir when :left then shift_left(bits) when :right then shift_right(bits, mode) end end
Shift the value left a specific number of bits.
@param [Integer] bits Number of bits to shift.
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 794 def shift_left(bits) self.class.new(Bindings.const_shl(@ptr, bits)) end
Shift the value right a specific number of bits.
@param [Integer] bits Number of bits to shift. @param [:arithmetic, :logical] mode Shift mode.
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 806 def shift_right(bits, mode = :arithmetic) case mode when :arithmetic then ashr(bits) when :logical then lshr(bits) end end
Convert this integer to a float.
@param [RealType] type Type
of float to convert to.
@return [ConstantReal] This value as a floating point value of the given type.
# File lib/rcgtk/value.rb, line 897 def to_f(type) type.value_class.new(Bindings.send(@signed ? :const_si_to_fp : :const_ui_to_fp, @ptr, check_cg_type(type, FloatingPointType))) end
Divide this value by another value. Uses unsigned division.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 723 def udiv(rhs) self.class.new(Bindings.const_u_div(@ptr, rhs)) end
Modulo this value by another value. Uses unsigned modulo.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 743 def urem(rhs) self.class.new(Bindings.const_u_rem(@ptr, rhs)) end
Get the value of this constant as a signed or unsigned long long.
@param [:sign, :zero] extension Extension method.
@return [Integer]
# File lib/rcgtk/value.rb, line 906 def value(extension = :sign) case extension when :sign then Bindings.const_int_get_s_ext_value(@ptr) when :zero then Bindings.const_int_get_z_ext_value(@ptr) end end
Bitwise XOR this value with another.
@param [ConstantInteger] rhs
@return [ConstantInteger] Instance of the same class.
# File lib/rcgtk/value.rb, line 855 def xor(rhs) self.class.new(Bindings.const_xor(@ptr, rhs)) end