Class: GObject::GObject
- Inherits:
-
Object
- Object
- GObject::GObject
- 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
Defined Under Namespace
Modules: GObjectLayout Classes: ManagedStruct, Struct
Class Method Summary collapse
Instance Method Summary collapse
-
#ffi_managed_struct ⇒ Object
access to the managed struct for this class.
-
#ffi_struct ⇒ Object
access to the casting struct for this class.
-
#initialize(ptr) ⇒ GObject
constructor
don't allow ptr == nil, we never want to allocate a GObject struct ourselves, we just want to wrap GLib-allocated GObjects.
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
75 76 77 78 |
# File 'lib/vips/gobject.rb', line 75 def initialize ptr # GLib::logger.debug("GObject::GObject.initialize") {"ptr = #{ptr}"} @struct = ffi_managed_struct.new ptr end |
Class Method Details
.ffi_managed_struct ⇒ Object
97 98 99 |
# File 'lib/vips/gobject.rb', line 97 def ffi_managed_struct self.const_get :ManagedStruct end |
.ffi_struct ⇒ Object
86 87 88 |
# File 'lib/vips/gobject.rb', line 86 def ffi_struct self.const_get :Struct end |
Instance Method Details
#ffi_managed_struct ⇒ Object
access to the managed struct for this class
92 93 94 |
# File 'lib/vips/gobject.rb', line 92 def ffi_managed_struct self.class.ffi_managed_struct end |
#ffi_struct ⇒ Object
access to the casting struct for this class
81 82 83 |
# File 'lib/vips/gobject.rb', line 81 def ffi_struct self.class.ffi_struct end |