Class: GirFFI::ClassBase
- Inherits:
-
Object
- Object
- GirFFI::ClassBase
- Extended by:
- Forwardable, 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
- .setup_instance_method(name) ⇒ Object
- .setup_method(name) ⇒ 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
-
#==(other) ⇒ Object
NOTE: JRuby should fix FFI::MemoryPointer#== to return true for equivalent FFI::Pointer.
- #setup_and_call(method, arguments, &block) ⇒ Object
Methods included from RegisteredTypeBase
Methods included from TypeBase
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
15 16 17 |
# File 'lib/gir_ffi/class_base.rb', line 15 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.
74 75 76 77 78 79 |
# File 'lib/gir_ffi/class_base.rb', line 74 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.
84 85 86 |
# File 'lib/gir_ffi/class_base.rb', line 84 def self.from(val) val end |
.setup_and_call(method, arguments, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/gir_ffi/class_base.rb', line 34 def self.setup_and_call(method, arguments, &block) method_name = try_in_ancestors(:setup_method, method.to_s) unless method_name raise NoMethodError, "undefined method `#{method}' for #{self}" end send method_name, *arguments, &block end |
.setup_instance_method(name) ⇒ Object
62 63 64 |
# File 'lib/gir_ffi/class_base.rb', line 62 def self.setup_instance_method(name) gir_ffi_builder.setup_instance_method name end |
.setup_method(name) ⇒ Object
58 59 60 |
# File 'lib/gir_ffi/class_base.rb', line 58 def self.setup_method(name) gir_ffi_builder.setup_method name 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.
68 69 70 |
# File 'lib/gir_ffi/class_base.rb', line 68 def self.wrap(ptr) direct_wrap ptr end |
Instance Method Details
#==(other) ⇒ Object
NOTE: JRuby should fix FFI::MemoryPointer#== to return true for equivalent FFI::Pointer. For now, user to_ptr.address
30 31 32 |
# File 'lib/gir_ffi/class_base.rb', line 30 def ==(other) other.class == self.class && to_ptr.address == other.to_ptr.address end |
#setup_and_call(method, arguments, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/gir_ffi/class_base.rb', line 18 def setup_and_call(method, arguments, &block) method_name = self.class.try_in_ancestors(:setup_instance_method, method.to_s) unless method_name raise NoMethodError, "undefined method `#{method}' for #{self}" end send method_name, *arguments, &block end |