class GObject::Value
Overrides for GValue, GObject's generic value container structure.
Constants
- CLASS_TO_GTYPE_MAP
- METHOD_MAP
Public Class Methods
copy_value_to_pointer(value, pointer, offset = 0)
click to toggle source
# File lib/ffi-gobject/value.rb, line 116 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)
click to toggle source
# File lib/ffi-gobject/value.rb, line 102 def self.for_gtype(gtype) new.tap do |it| it.init gtype end end
from(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 93 def self.from(val) case val when self val else wrap_ruby_value val end end
make_finalizer(struct)
click to toggle source
# File lib/ffi-gobject/value.rb, line 21 def self.make_finalizer(struct) proc do if struct.owned? ptr = struct.to_ptr Lib.g_value_unset ptr unless struct[:g_type] == TYPE_INVALID GObject.boxed_free gtype, ptr end end end
new()
click to toggle source
Calls superclass method
# File lib/ffi-gobject/value.rb, line 10 def initialize super struct.owned = true to_ptr.autorelease = nil end
wrap_instance(instance)
click to toggle source
TODO: Combine with wrap_ruby_value
# File lib/ffi-gobject/value.rb, line 109 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)
click to toggle source
TODO: Give more generic name
# File lib/ffi-gobject/value.rb, line 89 def self.wrap_ruby_value(val) new.tap { |gv| gv.__send__ :set_ruby_value, val } end
Public Instance Methods
current_fundamental_type()
click to toggle source
# File lib/ffi-gobject/value.rb, line 67 def current_fundamental_type GObject.type_fundamental current_gtype end
current_gtype()
click to toggle source
# File lib/ffi-gobject/value.rb, line 63 def current_gtype struct[:g_type] end
current_gtype_name()
click to toggle source
# File lib/ffi-gobject/value.rb, line 71 def current_gtype_name GObject.type_name current_gtype end
get_value()
click to toggle source
# File lib/ffi-gobject/value.rb, line 75 def get_value value = get_value_plain if current_fundamental_type == TYPE_BOXED wrap_boxed value else value end end
get_value_plain()
click to toggle source
# File lib/ffi-gobject/value.rb, line 84 def get_value_plain send get_method end
init(type)
click to toggle source
# File lib/ffi-gobject/value.rb, line 16 def init(type) Lib.g_value_init self, type unless [TYPE_NONE, TYPE_INVALID].include? type self end
set_value(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 57 def set_value(val) send set_method, val end
Also aliased as: value=
uninitialized?()
click to toggle source
# File lib/ffi-gobject/value.rb, line 122 def uninitialized? current_gtype == TYPE_INVALID end
Private Instance Methods
check_type_compatibility(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 181 def check_type_compatibility(val) return if GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype) raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}" end
current_gtype_class()
click to toggle source
# File lib/ffi-gobject/value.rb, line 177 def current_gtype_class GirFFI::Builder.build_by_gtype(current_gtype) end
get_enum_enhanced()
click to toggle source
# File lib/ffi-gobject/value.rb, line 164 def get_enum_enhanced current_gtype_class.wrap(get_enum) end
get_flags_enhanced()
click to toggle source
# File lib/ffi-gobject/value.rb, line 173 def get_flags_enhanced current_gtype_class.wrap(get_flags) end
get_method()
click to toggle source
# File lib/ffi-gobject/value.rb, line 200 def get_method method_map_entry.first end
get_none()
click to toggle source
# File lib/ffi-gobject/value.rb, line 152 def get_none; end
init_for_ruby_value(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 141 def init_for_ruby_value(val) return init val.class.gtype if val.class.respond_to? :gtype CLASS_TO_GTYPE_MAP.each do |klass, type| return init type if val.is_a? klass end raise "Can't handle #{val.class}" end
method_map_entry()
click to toggle source
# File lib/ffi-gobject/value.rb, line 208 def method_map_entry METHOD_MAP[current_gtype] || METHOD_MAP[current_fundamental_type] || raise("No method map entry for '#{current_gtype_name}'") end
set_enum_enhanced(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 159 def set_enum_enhanced(val) val = current_gtype_class.to_native(val, nil) set_enum val end
set_flags_enhanced(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 168 def set_flags_enhanced(val) val = current_gtype_class.to_native(val, nil) set_flags val end
set_instance_enhanced(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 154 def set_instance_enhanced(val) check_type_compatibility val if val set_instance val end
set_method()
click to toggle source
# File lib/ffi-gobject/value.rb, line 204 def set_method method_map_entry.last end
set_none(_val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 150 def set_none(_val); end
set_ruby_value(val)
click to toggle source
# File lib/ffi-gobject/value.rb, line 128 def set_ruby_value(val) init_for_ruby_value val if uninitialized? set_value val end
wrap_boxed(boxed)
click to toggle source
# File lib/ffi-gobject/value.rb, line 187 def wrap_boxed(boxed) case current_gtype when TYPE_STRV GLib::Strv.wrap boxed when TYPE_HASH_TABLE GLib::HashTable.wrap [:gpointer, :gpointer], boxed when TYPE_ARRAY GLib::Array.wrap nil, boxed else current_gtype_class.wrap(boxed) unless boxed.null? end end