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.
-
#initialize ⇒ ClassBase
constructor
A new instance of ClassBase.
- #setup_and_call(method, arguments, &block) ⇒ Object
Methods included from RegisteredTypeBase
Methods included from TypeBase
Constructor Details
#initialize ⇒ ClassBase
Returns a new instance of ClassBase.
33 34 35 |
# File 'lib/gir_ffi/class_base.rb', line 33 def initialize raise NoMethodError end |
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
14 15 16 |
# File 'lib/gir_ffi/class_base.rb', line 14 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.
77 78 79 80 81 82 |
# File 'lib/gir_ffi/class_base.rb', line 77 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.
87 88 89 |
# File 'lib/gir_ffi/class_base.rb', line 87 def self.from(val) val end |
.setup_and_call(method, arguments, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/gir_ffi/class_base.rb', line 37 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
65 66 67 |
# File 'lib/gir_ffi/class_base.rb', line 65 def self.setup_instance_method(name) gir_ffi_builder.setup_instance_method name end |
.setup_method(name) ⇒ Object
61 62 63 |
# File 'lib/gir_ffi/class_base.rb', line 61 def self.setup_method(name) gir_ffi_builder.setup_method name end |
.to_ffi_type ⇒ Object
57 58 59 |
# File 'lib/gir_ffi/class_base.rb', line 57 def self.to_ffi_type self::Struct end |
.try_in_ancestors(method, *arguments) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/gir_ffi/class_base.rb', line 47 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.
71 72 73 |
# File 'lib/gir_ffi/class_base.rb', line 71 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
29 30 31 |
# File 'lib/gir_ffi/class_base.rb', line 29 def ==(other) other.class == self.class && to_ptr.address == other.to_ptr.address end |
#setup_and_call(method, arguments, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/gir_ffi/class_base.rb', line 17 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 |