class GObject::Value

Overrides for GValue, GObject's generic value container structure.

Constants

CLASS_TO_GTYPE_MAP
METHOD_MAP

Public Class Methods

for_gtype(gtype) click to toggle source
# File lib/ffi-gobject/value.rb, line 95
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 86
def self.from(val)
  case val
  when self
    val
  else
    wrap_ruby_value val
  end
end
make_finalizer(ptr) click to toggle source
# File lib/ffi-gobject/value.rb, line 18
def self.make_finalizer(ptr)
  proc do
    GObject::Lib.g_value_unset ptr
  end
end
wrap_instance(instance) click to toggle source

TODO: Combine with ::wrap_ruby_value

# File lib/ffi-gobject/value.rb, line 102
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 82
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 60
def current_fundamental_type
  GObject.type_fundamental current_gtype
end
current_gtype() click to toggle source
# File lib/ffi-gobject/value.rb, line 56
def current_gtype
  @struct[:g_type]
end
current_gtype_name() click to toggle source
# File lib/ffi-gobject/value.rb, line 64
def current_gtype_name
  GObject.type_name current_gtype
end
get_value() click to toggle source
# File lib/ffi-gobject/value.rb, line 68
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 77
def get_value_plain
  send get_method
end
init(type)
Also aliased as: init_without_finalizer
Alias for: init_with_finalizer
init_with_finalizer(type) click to toggle source
# File lib/ffi-gobject/value.rb, line 8
def init_with_finalizer(type)
  return self if [TYPE_NONE, TYPE_INVALID].include? type
  init_without_finalizer(type).tap do
    ObjectSpace.define_finalizer self, self.class.make_finalizer(to_ptr)
  end
end
Also aliased as: init
init_without_finalizer(type)
Alias for: init
set_value(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 50
def set_value(val)
  send set_method, val
end
Also aliased as: value=
value=(val)
Alias for: set_value

Private Instance Methods

check_type_compatibility(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 162
def check_type_compatibility(val)
  unless GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype)
    raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}"
  end
end
current_gtype_class() click to toggle source
# File lib/ffi-gobject/value.rb, line 158
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 154
def get_enum_enhanced
  current_gtype_class.wrap(get_enum)
end
get_method() click to toggle source
# File lib/ffi-gobject/value.rb, line 181
def get_method
  method_map_entry.first
end
get_none() click to toggle source
# File lib/ffi-gobject/value.rb, line 137
def get_none
end
init_for_ruby_value(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 124
def init_for_ruby_value(val)
  if val.class.respond_to? :gtype
    return init val.class.gtype
  end
  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 189
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 149
def set_enum_enhanced(val)
  val = current_gtype_class[val] if val.is_a? Symbol
  set_enum val
end
set_instance_enhanced(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 144
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 185
def set_method
  method_map_entry.last
end
set_none(_) click to toggle source
# File lib/ffi-gobject/value.rb, line 134
def set_none(_)
end
set_ruby_value(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 111
def set_ruby_value(val)
  init_for_ruby_value val if uninitialized?
  set_value val
end
uninitialized?() click to toggle source
# File lib/ffi-gobject/value.rb, line 140
def uninitialized?
  current_gtype == TYPE_INVALID
end
wrap_boxed(boxed) click to toggle source
# File lib/ffi-gobject/value.rb, line 168
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