Class: GirFFI::ClassBase
- Inherits:
-
Object
show all
- Extended by:
- Forwardable, TypeBase
- Defined in:
- lib/gir_ffi/class_base.rb
Overview
Base class for all generated classes. Contains code for dealing with the generated Struct classes.
Constant Summary
collapse
- GIR_FFI_BUILDER =
NullBuilder.new
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from TypeBase
gir_ffi_builder, gir_info
Class Method Details
._allocate ⇒ Object
85
86
87
88
89
|
# File 'lib/gir_ffi/class_base.rb', line 85
def _allocate
obj = _real_new
obj.instance_variable_set :@struct, self::Struct.new
obj
end
|
.direct_wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class. Will not do any casting to subtypes.
78
79
80
81
82
83
|
# File 'lib/gir_ffi/class_base.rb', line 78
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
|
.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.
94
95
96
|
# File 'lib/gir_ffi/class_base.rb', line 94
def from val
val
end
|
.setup_and_call(method, *arguments, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/gir_ffi/class_base.rb', line 41
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
|
.setup_instance_method(name) ⇒ Object
63
64
65
|
# File 'lib/gir_ffi/class_base.rb', line 63
def setup_instance_method name
gir_ffi_builder.setup_instance_method name
end
|
.setup_method(name) ⇒ Object
59
60
61
|
# File 'lib/gir_ffi/class_base.rb', line 59
def setup_method name
gir_ffi_builder.setup_method name
end
|
.to_ffitype ⇒ Object
55
56
57
|
# File 'lib/gir_ffi/class_base.rb', line 55
def to_ffitype
self::Struct
end
|
.wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.
72
73
74
|
# File 'lib/gir_ffi/class_base.rb', line 72
def wrap ptr
direct_wrap ptr
end
|
Instance Method Details
#==(other) ⇒ Object
FIXME: JRuby should fix FFI::MemoryPointer#== to return true for equivalent FFI::Pointer.
32
33
34
|
# File 'lib/gir_ffi/class_base.rb', line 32
def ==(other)
other.class == self.class && self.to_ptr.address == other.to_ptr.address
end
|
#setup_and_call(method, *arguments, &block) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/gir_ffi/class_base.rb', line 16
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
|