class GObject::Value

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

Constants

CLASS_TO_GTYPE_MAP
TYPE_TO_GET_METHOD_MAP
TYPE_TO_SET_METHOD_MAP

Public Class Methods

for_g_type(g_type) click to toggle source
# File lib/ffi-gobject/value.rb, line 130
def for_g_type g_type
  return nil if g_type == TYPE_NONE
  self.new.tap {|it| it.init g_type }
end
from(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 119
def from val
  case val
  when self
    val
  when nil
    nil
  else
    wrap_ruby_value val
  end
end
wrap_instance(instance) click to toggle source

TODO: Combine with ::wrap_ruby_value

# File lib/ffi-gobject/value.rb, line 137
def self.wrap_instance instance
  self.new.tap {|it|
    it.init GObject.type_from_instance instance
    it.set_instance instance
  }
end
wrap_ruby_value(val) click to toggle source

TODO: Give more generic name

# File lib/ffi-gobject/value.rb, line 115
def wrap_ruby_value val
  self.new.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 95
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 104
def get_value_plain
  send get_method
end
init_for_ruby_value(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 53
def init_for_ruby_value val
  CLASS_TO_GTYPE_MAP.each do |klass, type|
    if klass === val
      init type
      return self
    end
  end
  raise "Can't handle #{val.class}"
end
ruby_value() click to toggle source

@deprecated Compatibility function. Remove in 0.7.0.

# File lib/ffi-gobject/value.rb, line 109
def ruby_value
  get_value
end
set_ruby_value(val) click to toggle source

TODO: Give more generic name

# File lib/ffi-gobject/value.rb, line 7
def set_ruby_value val
  if current_gtype == 0
    init_for_ruby_value val
  end

  set_value val
end
set_value(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 41
def set_value val
  send set_method, val
  self
end
value=(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 37
def value= val
  set_value val
end

Private Instance Methods

check_type_compatibility(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 151
def check_type_compatibility val
  if !GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype)
    raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}"
  end
end
get_method() click to toggle source
# File lib/ffi-gobject/value.rb, line 168
def get_method
  TYPE_TO_GET_METHOD_MAP[current_gtype] or
    TYPE_TO_GET_METHOD_MAP[current_fundamental_type] or
    raise "Can't find method to get #{current_gtype_name}"
end
set_instance_enhanced(val) click to toggle source
# File lib/ffi-gobject/value.rb, line 146
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 174
def set_method
  TYPE_TO_SET_METHOD_MAP[current_gtype] or
    TYPE_TO_SET_METHOD_MAP[current_fundamental_type] or
    raise "Can't find method to set #{current_gtype_name}"
end
wrap_boxed(boxed) click to toggle source
# File lib/ffi-gobject/value.rb, line 157
def wrap_boxed boxed
  case current_gtype
  when TYPE_STRV
    GLib::Strv.wrap boxed
  when TYPE_HASH_TABLE
    GLib::HashTable.wrap [:gpointer, :gpointer], boxed
  else
    boxed.wrap_by_gtype current_gtype
  end
end