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
- .for_gtype(gtype) ⇒ Object
- .from(val) ⇒ Object
- .make_finalizer(ptr) ⇒ 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_with_finalizer(type) ⇒ Object (also: #init)
- #set_value(val) ⇒ Object (also: #value=)
Class Method Details
.for_gtype(gtype) ⇒ Object
95 96 97 98 99 |
# File 'lib/ffi-gobject/value.rb', line 95 def self.for_gtype(gtype) new.tap do |it| it.init gtype end end |
.from(val) ⇒ Object
86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
18 19 20 21 22 |
# 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) ⇒ Object
TODO: Combine with wrap_ruby_value
102 103 104 105 106 107 |
# 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) ⇒ Object
TODO: Give more generic name
82 83 84 |
# File 'lib/ffi-gobject/value.rb', line 82 def self.wrap_ruby_value(val) new.tap { |gv| gv.__send__ :set_ruby_value, val } end |
Instance Method Details
#current_fundamental_type ⇒ Object
60 61 62 |
# File 'lib/ffi-gobject/value.rb', line 60 def current_fundamental_type GObject.type_fundamental current_gtype end |
#current_gtype ⇒ Object
56 57 58 |
# File 'lib/ffi-gobject/value.rb', line 56 def current_gtype @struct[:g_type] end |
#current_gtype_name ⇒ Object
64 65 66 |
# File 'lib/ffi-gobject/value.rb', line 64 def current_gtype_name GObject.type_name current_gtype end |
#get_value ⇒ Object
68 69 70 71 72 73 74 75 |
# 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 ⇒ Object
77 78 79 |
# File 'lib/ffi-gobject/value.rb', line 77 def get_value_plain send get_method end |
#init_with_finalizer(type) ⇒ Object Also known as: init
8 9 10 11 12 13 |
# 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) ObjectSpace.define_finalizer self, self.class.make_finalizer(to_ptr) self end |
#set_value(val) ⇒ Object Also known as: value=
50 51 52 |
# File 'lib/ffi-gobject/value.rb', line 50 def set_value(val) send set_method, val end |