Class: GObject::GObject

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, SingleForwardable
Defined in:
lib/vips/gobject.rb

Overview

we have a number of things we need to inherit in different ways:

  • we want to be able to subclass GObject in Ruby in a simple way
  • the layouts of the nested structs need to inherit
  • we need to be able to cast between structs which share a base struct without creating new wrappers or messing up refcounting
  • we need automatic gobject refcounting

the solution is to split the class into four areas which we treat differently:

  • we have a "wrapper" Ruby class to allow easy subclassing ... this has a @struct member which holds the actual pointer
  • we use "forwardable" to forward the various ffi methods on to the @struct member ... we arrange things so that subclasses do not need to do the forwarding themselves
  • we have two versions of the struct: a plain one which we can use for casting that will not change the refcounts
  • and a managed one with an unref which we just use for .new
  • we separate the struct layout into a separate module to avoid repeating ourselves

Direct Known Subclasses

Vips::Object

Defined Under Namespace

Modules: GObjectLayout Classes: ManagedStruct, Struct

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ GObject

don't allow ptr == nil, we never want to allocate a GObject struct ourselves, we just want to wrap GLib-allocated GObjects

here we use ManagedStruct, not Struct, since this is the ref that will need the unref


73
74
75
76
# File 'lib/vips/gobject.rb', line 73

def initialize ptr
  # GLib::logger.debug("GObject::GObject.initialize") {"ptr = #{ptr}"}
  @struct = ffi_managed_struct.new ptr
end

Class Method Details

.ffi_managed_structObject


95
96
97
# File 'lib/vips/gobject.rb', line 95

def ffi_managed_struct
  self.const_get :ManagedStruct
end

.ffi_structObject


84
85
86
# File 'lib/vips/gobject.rb', line 84

def ffi_struct
  self.const_get :Struct
end

Instance Method Details

#ffi_managed_structObject

access to the managed struct for this class


90
91
92
# File 'lib/vips/gobject.rb', line 90

def ffi_managed_struct
  self.class.ffi_managed_struct
end

#ffi_structObject

access to the casting struct for this class


79
80
81
# File 'lib/vips/gobject.rb', line 79

def ffi_struct
  self.class.ffi_struct
end