class GirFFI::ClassBase

Base class for all generated classes. Contains code for dealing with the generated Struct classes.

Constants

GIR_FFI_BUILDER

Public Class Methods

_allocate() click to toggle source
# File lib/gir_ffi/class_base.rb, line 86
def _allocate
  obj = _real_new
  obj.instance_variable_set :@struct, self::Struct.new
  obj
end
direct_wrap(ptr) click to toggle source

Wrap the passed pointer in an instance of the current class. Will not do any casting to subtypes.

# File lib/gir_ffi/class_base.rb, line 79
def direct_wrap ptr
  return nil if !ptr or ptr.null?
  obj = _real_new
  obj.instance_variable_set :@struct, self::Struct.new(ptr.to_ptr)
  obj
end
from(val) click to toggle source

Pass-through casting method. This may become a type checking method. It is overridden by GValue to implement wrapping of plain Ruby objects.

# File lib/gir_ffi/class_base.rb, line 95
def from val
  val
end
setup_and_call(method, *arguments, &block) click to toggle source
# File lib/gir_ffi/class_base.rb, line 42
def self.setup_and_call method, *arguments, &block
  result = self.ancestors.any? do |klass|
    klass.respond_to?(:setup_method) &&
      klass.setup_method(method.to_s)
  end

  unless result
    raise RuntimeError, "Unable to set up method #{method} in #{self}"
  end

  self.send method, *arguments, &block
end
setup_instance_method(name) click to toggle source
# File lib/gir_ffi/class_base.rb, line 64
def setup_instance_method name
  gir_ffi_builder.setup_instance_method name
end
setup_method(name) click to toggle source
# File lib/gir_ffi/class_base.rb, line 60
def setup_method name
  gir_ffi_builder.setup_method name
end
to_ffitype() click to toggle source
# File lib/gir_ffi/class_base.rb, line 56
def to_ffitype
  self::Struct
end
wrap(ptr) click to toggle source

Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.

# File lib/gir_ffi/class_base.rb, line 73
def wrap ptr
  direct_wrap ptr
end

Public Instance Methods

==(other) click to toggle source

FIXME: JRuby should fix FFI::MemoryPointer#== to return true for equivalent FFI::Pointer.

# File lib/gir_ffi/class_base.rb, line 33
def ==(other)
  other.class == self.class && self.to_ptr.address == other.to_ptr.address
end
setup_and_call(method, *arguments, &block) click to toggle source
# File lib/gir_ffi/class_base.rb, line 17
def setup_and_call method, *arguments, &block
  result = self.class.ancestors.any? do |klass|
    klass.respond_to?(:setup_instance_method) &&
      klass.setup_instance_method(method.to_s)
  end

  unless result
    raise RuntimeError, "Unable to set up instance method #{method} in #{self}"
  end

  self.send method, *arguments, &block
end