Class: GirFFI::ClassBase
- Inherits:
-
Object
- Object
- GirFFI::ClassBase
- Extended by:
- Forwardable, InstanceMethodSetup, MethodSetup, RegisteredTypeBase
- Defined in:
- lib/gir_ffi/class_base.rb
Overview
Base class for all generated classes and structs. Contains code for dealing with the generated nested Struct classes.
Direct Known Subclasses
Constant Summary collapse
- GIR_FFI_BUILDER =
Builders::NullClassBuilder.new
Instance Attribute Summary collapse
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Class Method Summary collapse
-
.direct_wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class.
-
.from(val) ⇒ Object
Pass-through casting method.
- .setup_and_call(method, arguments, &block) ⇒ Object
- .to_callback_ffi_type ⇒ Object
- .to_ffi_type ⇒ Object
- .try_in_ancestors(method, *arguments) ⇒ Object
-
.wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.
Instance Method Summary collapse
Methods included from RegisteredTypeBase
Methods included from TypeBase
Methods included from MethodSetup
Methods included from InstanceMethodSetup
setup_instance_method, setup_instance_method!
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
20 21 22 |
# File 'lib/gir_ffi/class_base.rb', line 20 def struct @struct end |
Class Method Details
.direct_wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class. Will not do any casting to subtypes or additional processing.
70 71 72 73 74 75 76 |
# 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 |
.from(val) ⇒ Object
Pass-through casting method. This may become a type checking method. It is overridden by GValue to implement wrapping of plain Ruby objects.
81 82 83 |
# File 'lib/gir_ffi/class_base.rb', line 81 def self.from(val) val end |
.setup_and_call(method, arguments, &block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gir_ffi/class_base.rb', line 36 def self.setup_and_call(method, arguments, &block) method_name = try_in_ancestors(:setup_method, method.to_s) raise NoMethodError, "undefined method `#{method}' for #{self}" unless method_name send method_name, *arguments, &block end |
.to_callback_ffi_type ⇒ Object
58 59 60 |
# File 'lib/gir_ffi/class_base.rb', line 58 def self.to_callback_ffi_type :pointer end |
.to_ffi_type ⇒ Object
54 55 56 |
# File 'lib/gir_ffi/class_base.rb', line 54 def self.to_ffi_type self::Struct end |
.try_in_ancestors(method, *arguments) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# 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 |
.wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.
64 65 66 |
# File 'lib/gir_ffi/class_base.rb', line 64 def self.wrap(ptr) direct_wrap ptr end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 |
# File 'lib/gir_ffi/class_base.rb', line 32 def ==(other) other.class == self.class && to_ptr == other.to_ptr end |
#setup_and_call(method, arguments, &block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/gir_ffi/class_base.rb', line 24 def setup_and_call(method, arguments, &block) 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, &block end |