Module: GirFFI::InfoExt::ITypeInfo
- Included in:
- ReceiverTypeInfo, UserDataTypeInfo
- Defined in:
- lib/gir_ffi/info_ext/i_type_info.rb
Overview
Extensions for GObjectIntrospection::ITypeInfo needed by GirFFI
Constant Summary collapse
- TAG_TO_WRAPPER_CLASS_MAP =
{ :array => 'GLib::Array', :byte_array => 'GLib::ByteArray', :c => 'GirFFI::SizedArray', :error => 'GLib::Error', :ghash => 'GLib::HashTable', :glist => 'GLib::List', :gslist => 'GLib::SList', :ptr_array => 'GLib::PtrArray', :strv => 'GLib::Strv', :utf8 => 'GirFFI::InPointer', :void => 'GirFFI::InPointer', :zero_terminated => 'GirFFI::ZeroTerminated' }
Class Method Summary collapse
Instance Method Summary collapse
-
#argument_class_name ⇒ Object
TODO: Use class rather than class name.
- #element_type ⇒ Object
- #extra_conversion_arguments ⇒ Object
- #flattened_tag ⇒ Object
- #g_type ⇒ Object
- #interface_type ⇒ Object
- #make_g_value ⇒ Object
- #needs_conversion_for_callbacks? ⇒ Boolean
- #needs_conversion_for_functions? ⇒ Boolean
- #needs_ruby_to_c_conversion_for_functions? ⇒ Boolean
- #tag_or_class ⇒ Object
- #to_callback_ffitype ⇒ Object
- #to_ffitype ⇒ Object
Class Method Details
.flattened_tag_to_gtype_map ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 8 def self.flattened_tag_to_gtype_map @flattened_tag_to_gtype_map ||= { :array => GObject::TYPE_ARRAY, :c => GObject::TYPE_POINTER, :gboolean => GObject::TYPE_BOOLEAN, :ghash => GObject::TYPE_HASH_TABLE, :gint32 => GObject::TYPE_INT, :gint64 => GObject::TYPE_INT64, :guint64 => GObject::TYPE_UINT64, :strv => GObject::TYPE_STRV, :utf8 => GObject::TYPE_STRING, :void => GObject::TYPE_NONE } end |
Instance Method Details
#argument_class_name ⇒ Object
TODO: Use class rather than class name
94 95 96 97 98 99 100 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 94 def argument_class_name if tag == :interface interface.full_type_name else TAG_TO_WRAPPER_CLASS_MAP[flattened_tag] end end |
#element_type ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 36 def element_type case tag when :glist, :gslist, :array, :c enumerable_element_type when :ghash dictionary_element_type else nil end end |
#extra_conversion_arguments ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 145 def extra_conversion_arguments case flattened_tag when :utf8, :void [flattened_tag] when :c [element_type, array_fixed_size] when :array, :ghash, :glist, :gslist, :ptr_array, :zero_terminated [element_type] else [] end end |
#flattened_tag ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 47 def flattened_tag case tag when :interface interface_type when :array flattened_array_type else tag end end |
#g_type ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 23 def g_type if tag == :interface interface.g_type else ITypeInfo.flattened_tag_to_gtype_map[flattened_tag] or raise "Can't find type for #{flattened_tag} pointer? = #{pointer?}" end end |
#interface_type ⇒ Object
58 59 60 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 58 def interface_type tag == :interface && interface.info_type end |
#make_g_value ⇒ Object
32 33 34 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 32 def make_g_value GObject::Value.for_g_type g_type end |
#needs_conversion_for_callbacks? ⇒ Boolean
141 142 143 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 141 def needs_conversion_for_callbacks? flattened_tag == :enum || needs_conversion_for_functions? end |
#needs_conversion_for_functions? ⇒ Boolean
135 136 137 138 139 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 135 def needs_conversion_for_functions? [ :array, :byte_array, :c, :error, :filename, :ghash, :glist, :gslist, :interface, :object, :ptr_array, :struct, :strv, :union, :utf8, :zero_terminated ].include?(flattened_tag) end |
#needs_ruby_to_c_conversion_for_functions? ⇒ Boolean
130 131 132 133 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 130 def needs_ruby_to_c_conversion_for_functions? [ :array, :c, :callback, :ghash, :glist, :gslist, :object, :ptr_array, :struct, :strv, :utf8, :void, :zero_terminated ].include?(flattened_tag) end |
#tag_or_class ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 62 def tag_or_class base = case tag when:interface Builder.build_class interface when :ghash [tag, *element_type] else flattened_tag end if pointer? && tag != :utf8 && tag != :filename [:pointer, base] else base end end |
#to_callback_ffitype ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 115 def to_callback_ffitype return :pointer if pointer? if tag == :interface case interface.info_type when :enum, :flags :int32 else :pointer end else TypeMap.map_basic_type tag end end |
#to_ffitype ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 102 def to_ffitype return :pointer if pointer? case tag when :interface interface.to_ffitype when :array [subtype_ffitype(0), array_fixed_size] else TypeMap.map_basic_type tag end end |