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
- TYPE_TO_SET_METHOD_MAP =
{ TYPE_BOOLEAN => :set_boolean, TYPE_INT => :set_int, TYPE_INT64 => :set_int64, TYPE_STRING => :set_string, TYPE_FLOAT => :set_float, TYPE_DOUBLE => :set_double, TYPE_PARAM => :set_param, TYPE_OBJECT => :set_instance_enhanced, TYPE_BOXED => :set_boxed, TYPE_POINTER => :set_pointer, TYPE_ENUM => :set_enum }
- CLASS_TO_GTYPE_MAP =
{ true => TYPE_BOOLEAN, false => TYPE_BOOLEAN, Integer => TYPE_INT, String => TYPE_STRING }
- TYPE_TO_GET_METHOD_MAP =
{ TYPE_BOOLEAN => :get_boolean, TYPE_INT => :get_int, TYPE_INT64 => :get_int64, TYPE_STRING => :get_string, TYPE_FLOAT => :get_float, TYPE_DOUBLE => :get_double, TYPE_OBJECT => :get_object, TYPE_BOXED => :get_boxed_enhanced, TYPE_POINTER => :get_pointer }
Class Method Summary collapse
- .for_g_type(g_type) ⇒ Object
- .from(val) ⇒ 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
- #init_for_ruby_value(val) ⇒ Object
-
#ruby_value ⇒ Object
deprecated
Deprecated.
Compatibility function. Remove in 0.7.0.
-
#set_ruby_value(val) ⇒ Object
TODO: Give more generic name.
- #set_value(val) ⇒ Object
- #value=(val) ⇒ Object
Class Method Details
.for_g_type(g_type) ⇒ Object
105 106 107 108 |
# File 'lib/ffi-gobject/value.rb', line 105 def for_g_type g_type return nil if g_type == TYPE_NONE self.new.tap {|it| it.init g_type } end |
.from(val) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ffi-gobject/value.rb', line 94 def from val case val when self val when nil nil else wrap_ruby_value val end end |
.wrap_instance(instance) ⇒ Object
TODO: Combine with wrap_ruby_value
112 113 114 115 116 117 |
# File 'lib/ffi-gobject/value.rb', line 112 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) ⇒ Object
TODO: Give more generic name
90 91 92 |
# File 'lib/ffi-gobject/value.rb', line 90 def wrap_ruby_value val self.new.set_ruby_value val end |
Instance Method Details
#current_fundamental_type ⇒ Object
59 60 61 |
# File 'lib/ffi-gobject/value.rb', line 59 def current_fundamental_type GObject.type_fundamental current_gtype end |
#current_gtype ⇒ Object
55 56 57 |
# File 'lib/ffi-gobject/value.rb', line 55 def current_gtype @struct[:g_type] end |
#current_gtype_name ⇒ Object
63 64 65 |
# File 'lib/ffi-gobject/value.rb', line 63 def current_gtype_name GObject.type_name current_gtype end |
#get_value ⇒ Object
79 80 81 |
# File 'lib/ffi-gobject/value.rb', line 79 def get_value send get_method end |
#init_for_ruby_value(val) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/ffi-gobject/value.rb', line 45 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 ⇒ Object
Deprecated.
Compatibility function. Remove in 0.7.0.
84 85 86 |
# File 'lib/ffi-gobject/value.rb', line 84 def ruby_value get_value end |
#set_ruby_value(val) ⇒ Object
TODO: Give more generic name
7 8 9 10 11 12 13 |
# 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) ⇒ Object
33 34 35 36 |
# File 'lib/ffi-gobject/value.rb', line 33 def set_value val send set_method, val self end |
#value=(val) ⇒ Object
29 30 31 |
# File 'lib/ffi-gobject/value.rb', line 29 def value= val set_value val end |