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_BOXED => :set_boxed, TYPE_CHAR => :set_char, TYPE_DOUBLE => :set_double, TYPE_ENUM => :set_enum, TYPE_FLOAT => :set_float, TYPE_GTYPE => :set_gtype, TYPE_INT64 => :set_int64, TYPE_INT => :set_int, TYPE_LONG => :set_long, TYPE_OBJECT => :set_instance_enhanced, TYPE_PARAM => :set_param, TYPE_POINTER => :set_pointer, TYPE_STRING => :set_string, TYPE_UCHAR => :set_uchar, TYPE_UINT => :set_uint, TYPE_UINT64 => :set_uint64, TYPE_ULONG => :set_ulong, TYPE_VARIANT => :set_variant, }
- 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_BOXED => :get_boxed, TYPE_CHAR => :get_char, TYPE_DOUBLE => :get_double, TYPE_ENUM => :get_enum_enhanced, TYPE_FLAGS => :get_flags, TYPE_FLOAT => :get_float, TYPE_GTYPE => :get_gtype, TYPE_INT64 => :get_int64, TYPE_INT => :get_int, TYPE_LONG => :get_long, TYPE_OBJECT => :get_object, TYPE_POINTER => :get_pointer, TYPE_STRING => :get_string, TYPE_UCHAR => :get_uchar, TYPE_UINT => :get_uint, TYPE_UINT64 => :get_uint64, TYPE_ULONG => :get_ulong, TYPE_VARIANT => :get_variant, }
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
- #get_value_plain ⇒ Object
- #init_for_ruby_value(val) ⇒ Object
-
#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
127 128 129 130 |
# File 'lib/ffi-gobject/value.rb', line 127 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
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ffi-gobject/value.rb', line 116 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
134 135 136 137 138 139 |
# File 'lib/ffi-gobject/value.rb', line 134 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
112 113 114 |
# File 'lib/ffi-gobject/value.rb', line 112 def wrap_ruby_value val self.new.set_ruby_value val end |
Instance Method Details
#current_fundamental_type ⇒ Object
67 68 69 |
# File 'lib/ffi-gobject/value.rb', line 67 def current_fundamental_type GObject.type_fundamental current_gtype end |
#current_gtype ⇒ Object
63 64 65 |
# File 'lib/ffi-gobject/value.rb', line 63 def current_gtype @struct[:g_type] end |
#current_gtype_name ⇒ Object
71 72 73 |
# File 'lib/ffi-gobject/value.rb', line 71 def current_gtype_name GObject.type_name current_gtype end |
#get_value ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/ffi-gobject/value.rb', line 97 def get_value value = get_value_plain if current_fundamental_type == TYPE_BOXED wrap_boxed value else value end end |
#get_value_plain ⇒ Object
106 107 108 |
# File 'lib/ffi-gobject/value.rb', line 106 def get_value_plain send get_method end |
#init_for_ruby_value(val) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# 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 |
#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
41 42 43 44 |
# File 'lib/ffi-gobject/value.rb', line 41 def set_value val send set_method, val self end |
#value=(val) ⇒ Object
37 38 39 |
# File 'lib/ffi-gobject/value.rb', line 37 def value= val set_value val end |