class GirFFI::ClassBase
Base class for all generated classes and structs. Contains code for dealing with the generated nested Struct
classes.
Constants
- GIR_FFI_BUILDER
Attributes
Public Class Methods
Source
# File lib/gir_ffi/class_base.rb, line 70 def self.direct_wrap(ptr) return nil if !ptr || ptr.null? obj = allocate obj.__send__ :assign_pointer, ptr obj end
Wrap the passed pointer in an instance of the current class. Will not do any casting to subtypes or additional processing.
Source
# File lib/gir_ffi/class_base.rb, line 81 def self.from(val) val end
Pass-through casting method. This may become a type checking method. It is overridden by GValue to implement wrapping of plain Ruby objects.
Source
# File lib/gir_ffi/class_base.rb, line 36 def self.setup_and_call(method, arguments, &) method_name = try_in_ancestors(:setup_method, method.to_s) raise NoMethodError, "undefined method `#{method}' for #{self}" unless method_name send(method_name, *arguments, &) end
Source
# File lib/gir_ffi/class_base.rb, line 58 def self.to_callback_ffi_type :pointer end
Source
# File lib/gir_ffi/class_base.rb, line 54 def self.to_ffi_type self::Struct end
Source
# File lib/gir_ffi/class_base.rb, line 44 def self.try_in_ancestors(method, *arguments) ancestors.each do |klass| if klass.respond_to?(method) result = klass.send(method, *arguments) return result if result end end nil end
Source
# File lib/gir_ffi/class_base.rb, line 64 def self.wrap(ptr) direct_wrap ptr end
Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.
Public Instance Methods
Source
# File lib/gir_ffi/class_base.rb, line 32 def ==(other) other.class == self.class && to_ptr == other.to_ptr end
Source
# File lib/gir_ffi/class_base.rb, line 24 def setup_and_call(method, arguments, &) method_name = self.class.try_in_ancestors(:setup_instance_method, method.to_s) raise NoMethodError, "undefined method `#{method}' for #{self}" unless method_name send(method_name, *arguments, &) end
Private Instance Methods
Source
# File lib/gir_ffi/class_base.rb, line 99 def assign_pointer(ptr) @struct = self.class::Struct.new(ptr) end
Source
# File lib/gir_ffi/class_base.rb, line 95 def store_pointer(ptr) assign_pointer ptr end
Stores a pointer created by a constructor function. Derived classes may perform additional processing. For example, InitiallyUnowned overrides it to sink the floating object.
This method assumes the pointer will always be of the type corresponding to the current class, and never of a subtype.
@param ptr Pointer to the object’s C structure