Class: GirFFI::ClassBase

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gir_ffi/class_base.rb

Overview

Base class for all generated classes. Contains code for dealing with the generated Struct classes.

Direct Known Subclasses

ObjectBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._builderObject

Deprecated.

Compatibility function. Remove in version 0.5.0.



49
50
51
# File 'lib/gir_ffi/class_base.rb', line 49

def _builder
  gir_ffi_builder
end

._setup_instance_method(name) ⇒ Object

Deprecated.

Compatibility function. Remove in version 0.5.0.



67
68
69
# File 'lib/gir_ffi/class_base.rb', line 67

def _setup_instance_method name
  setup_instance_method name
end

._setup_method(name) ⇒ Object

Deprecated.

Compatibility function. Remove in version 0.5.0.



58
59
60
# File 'lib/gir_ffi/class_base.rb', line 58

def _setup_method name
  setup_method name
end

.allocateObject



93
94
95
96
97
# File 'lib/gir_ffi/class_base.rb', line 93

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.



86
87
88
89
90
91
# File 'lib/gir_ffi/class_base.rb', line 86

def direct_wrap ptr
  return nil if ptr.nil? or ptr.null?
  obj = _real_new
  obj.instance_variable_set :@struct, self::Struct.new(ptr.to_ptr)
  obj
end

.ffi_structureObject

Deprecated.

Compatibility function. Remove in version 0.5.0.



40
41
42
# File 'lib/gir_ffi/class_base.rb', line 40

def ffi_structure
  self::Struct
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.



102
103
104
# File 'lib/gir_ffi/class_base.rb', line 102

def from val
  val
end

.gir_ffi_builderObject



53
54
55
# File 'lib/gir_ffi/class_base.rb', line 53

def gir_ffi_builder
  self.const_get :GIR_FFI_BUILDER
end

.gir_infoObject



44
45
46
# File 'lib/gir_ffi/class_base.rb', line 44

def gir_info
  self.const_get :GIR_INFO
end

.setup_and_call(method, *arguments, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gir_ffi/class_base.rb', line 25

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



71
72
73
# File 'lib/gir_ffi/class_base.rb', line 71

def setup_instance_method name
  _builder.setup_instance_method name
end

.setup_method(name) ⇒ Object



62
63
64
# File 'lib/gir_ffi/class_base.rb', line 62

def setup_method name
  _builder.setup_method name
end

.wrap(ptr) ⇒ Object

Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.



80
81
82
# File 'lib/gir_ffi/class_base.rb', line 80

def wrap ptr
  direct_wrap ptr
end

Instance Method Details

#setup_and_call(method, *arguments, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gir_ffi/class_base.rb', line 12

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