Class: GObject::Value
- Inherits:
-
Object
- Object
- GObject::Value
- Defined in:
- lib/ffi-gobject/value.rb
Overview
Overrides for GValue, GObject’s generic value container structure.
Constant Summary collapse
- METHOD_MAP =
{ TYPE_INVALID => [:get_none, :set_none], # TYPE_NONE is skipped TYPE_INTERFACE => [:get_object, :set_instance_enhanced], TYPE_CHAR => [:get_schar, :set_schar], TYPE_UCHAR => [:get_uchar, :set_uchar], TYPE_BOOLEAN => [:get_boolean, :set_boolean], TYPE_INT => [:get_int, :set_int], TYPE_UINT => [:get_uint, :set_uint], TYPE_LONG => [:get_long, :set_long], TYPE_ULONG => [:get_ulong, :set_ulong], TYPE_INT64 => [:get_int64, :set_int64], TYPE_UINT64 => [:get_uint64, :set_uint64], TYPE_ENUM => [:get_enum_enhanced, :set_enum_enhanced], TYPE_FLAGS => [:get_flags, :set_flags], TYPE_FLOAT => [:get_float, :set_float], TYPE_DOUBLE => [:get_double, :set_double], TYPE_STRING => [:get_string, :set_string], TYPE_POINTER => [:get_pointer, :set_pointer], TYPE_BOXED => [:get_boxed, :set_boxed], TYPE_PARAM => [:get_param, :set_param], TYPE_OBJECT => [:get_object, :set_instance_enhanced], TYPE_GTYPE => [:get_gtype, :set_gtype], TYPE_VARIANT => [:get_variant, :set_variant] }.freeze
Class Method Summary collapse
- .copy_value_to_pointer(value, pointer, offset = 0) ⇒ Object
- .for_gtype(gtype) ⇒ Object
- .from(val) ⇒ Object
- .make_finalizer(struct) ⇒ Object
-
.wrap_instance(instance) ⇒ Object
TODO: Combine with wrap_ruby_value.
-
.wrap_ruby_value(val) ⇒ Object
TODO: Give more generic name.
Instance Method Summary collapse
- #current_fundamental_type ⇒ Object
- #current_gtype ⇒ Object
- #current_gtype_name ⇒ Object
- #get_value ⇒ Object
- #get_value_plain ⇒ Object
- #init(type) ⇒ Object
-
#initialize ⇒ Value
constructor
A new instance of Value.
- #set_value(val) ⇒ Object (also: #value=)
- #uninitialized? ⇒ Boolean
Constructor Details
#initialize ⇒ Value
Returns a new instance of Value.
9 10 11 12 13 |
# File 'lib/ffi-gobject/value.rb', line 9 def initialize super struct.owned = true to_ptr.autorelease = nil end |
Class Method Details
.copy_value_to_pointer(value, pointer, offset = 0) ⇒ Object
117 118 119 120 121 |
# File 'lib/ffi-gobject/value.rb', line 117 def self.copy_value_to_pointer(value, pointer, offset = 0) target = wrap(pointer + offset) target.init(value.current_gtype) Lib.g_value_copy value, target unless value.uninitialized? end |
.for_gtype(gtype) ⇒ Object
103 104 105 106 107 |
# File 'lib/ffi-gobject/value.rb', line 103 def self.for_gtype(gtype) new.tap do |it| it.init gtype end end |
.from(val) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/ffi-gobject/value.rb', line 94 def self.from(val) case val when self val else wrap_ruby_value val end end |
.make_finalizer(struct) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ffi-gobject/value.rb', line 20 def self.make_finalizer(struct) proc do if struct.owned? ptr = struct.to_ptr unless struct[:g_type] == TYPE_INVALID Lib.g_value_unset ptr end GObject.boxed_free gtype, ptr end end end |
.wrap_instance(instance) ⇒ Object
TODO: Combine with wrap_ruby_value
110 111 112 113 114 115 |
# File 'lib/ffi-gobject/value.rb', line 110 def self.wrap_instance(instance) new.tap do |it| it.init GObject.type_from_instance instance it.set_instance instance end end |
.wrap_ruby_value(val) ⇒ Object
TODO: Give more generic name
90 91 92 |
# File 'lib/ffi-gobject/value.rb', line 90 def self.wrap_ruby_value(val) new.tap { |gv| gv.__send__ :set_ruby_value, val } end |
Instance Method Details
#current_fundamental_type ⇒ Object
68 69 70 |
# File 'lib/ffi-gobject/value.rb', line 68 def current_fundamental_type GObject.type_fundamental current_gtype end |
#current_gtype ⇒ Object
64 65 66 |
# File 'lib/ffi-gobject/value.rb', line 64 def current_gtype @struct[:g_type] end |
#current_gtype_name ⇒ Object
72 73 74 |
# File 'lib/ffi-gobject/value.rb', line 72 def current_gtype_name GObject.type_name current_gtype end |
#get_value ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/ffi-gobject/value.rb', line 76 def get_value value = get_value_plain if current_fundamental_type == TYPE_BOXED wrap_boxed value else value end end |
#get_value_plain ⇒ Object
85 86 87 |
# File 'lib/ffi-gobject/value.rb', line 85 def get_value_plain send get_method end |
#init(type) ⇒ Object
15 16 17 18 |
# File 'lib/ffi-gobject/value.rb', line 15 def init(type) Lib.g_value_init self, type unless [TYPE_NONE, TYPE_INVALID].include? type self end |
#set_value(val) ⇒ Object Also known as: value=
58 59 60 |
# File 'lib/ffi-gobject/value.rb', line 58 def set_value(val) send set_method, val end |
#uninitialized? ⇒ Boolean
123 124 125 |
# File 'lib/ffi-gobject/value.rb', line 123 def uninitialized? current_gtype == TYPE_INVALID end |