Base class for all generated classes. Contains code for dealing with the generated Struct classes.
# File lib/gir_ffi/class_base.rb, line 86 def _allocate obj = _real_new obj.instance_variable_set :@struct, self::Struct.new obj end
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
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
# 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
# File lib/gir_ffi/class_base.rb, line 64 def setup_instance_method name gir_ffi_builder.setup_instance_method name end
# File lib/gir_ffi/class_base.rb, line 60 def setup_method name gir_ffi_builder.setup_method name end
# File lib/gir_ffi/class_base.rb, line 56 def to_ffitype self::Struct end
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
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
# 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