Module: GirFFI::InfoExt::ITypeInfo
- 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', # TODO: Create a string-like class void: 'GirFFI::InPointer', # TODO: Create a void-pointer class zero_terminated: 'GirFFI::ZeroTerminated' }.freeze
- TAGS_NEEDING_RUBY_TO_C_CONVERSION =
[ :array, :c, :callback, :error, :ghash, :glist, :gslist, :object, :ptr_array, :struct, :strv, :utf8, :zero_terminated ].freeze
- TAGS_NEEDING_C_TO_RUBY_CONVERSION =
[ :array, :byte_array, :c, :error, :filename, :ghash, :glist, :gslist, :interface, :object, :ptr_array, :struct, :strv, :union, :utf8, :zero_terminated ].freeze
- GOBJECT_VALUE_NAME =
'GObject::Value'.freeze
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
- #gtype ⇒ Object
- #gvalue? ⇒ Boolean
- #hidden_struct_type? ⇒ Boolean
- #interface_class ⇒ Object
- #interface_class_name ⇒ Object
- #interface_type ⇒ Object
- #make_g_value ⇒ Object
- #needs_c_to_ruby_conversion_for_callbacks? ⇒ Boolean
- #needs_c_to_ruby_conversion_for_closures? ⇒ Boolean
- #needs_c_to_ruby_conversion_for_functions? ⇒ Boolean
- #needs_c_to_ruby_conversion_for_properties? ⇒ Boolean
- #needs_ruby_to_c_conversion_for_callbacks? ⇒ Boolean
- #needs_ruby_to_c_conversion_for_closures? ⇒ Boolean
- #needs_ruby_to_c_conversion_for_functions? ⇒ Boolean
- #needs_ruby_to_c_conversion_for_properties? ⇒ Boolean
- #tag_or_class ⇒ Object
- #to_callback_ffi_type ⇒ Object
- #to_ffi_type ⇒ Object
Instance Method Details
#argument_class_name ⇒ Object
TODO: Use class rather than class name
81 82 83 84 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 81 def argument_class_name interface_class_name || TAG_TO_WRAPPER_CLASS_MAP[flattened_tag] end |
#element_type ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 17 def element_type case tag when :glist, :gslist, :array, :c enumerable_element_type when :ghash dictionary_element_type end end |
#extra_conversion_arguments ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 162 def extra_conversion_arguments case 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
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 26 def flattened_tag case tag when :interface interface_type when :array flattened_array_type else tag end end |
#gtype ⇒ Object
9 10 11 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 9 def gtype TypeMap.type_info_to_gtype self end |
#gvalue? ⇒ Boolean
175 176 177 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 175 def gvalue? argument_class_name == GOBJECT_VALUE_NAME end |
#hidden_struct_type? ⇒ Boolean
41 42 43 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 41 def hidden_struct_type? flattened_tag == :struct && interface.empty? end |
#interface_class ⇒ Object
61 62 63 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 61 def interface_class Builder.build_class interface if tag == :interface end |
#interface_class_name ⇒ Object
86 87 88 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 86 def interface_class_name interface.full_type_name if tag == :interface end |
#interface_type ⇒ Object
37 38 39 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 37 def interface_type tag == :interface && interface.info_type end |
#make_g_value ⇒ Object
13 14 15 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 13 def make_g_value GObject::Value.for_gtype gtype end |
#needs_c_to_ruby_conversion_for_callbacks? ⇒ Boolean
141 142 143 144 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 141 def needs_c_to_ruby_conversion_for_callbacks? [:callback, :enum].include?(flattened_tag) || needs_c_to_ruby_conversion_for_functions? end |
#needs_c_to_ruby_conversion_for_closures? ⇒ Boolean
146 147 148 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 146 def needs_c_to_ruby_conversion_for_closures? [:array, :c, :ghash, :glist, :struct, :strv].include?(flattened_tag) end |
#needs_c_to_ruby_conversion_for_functions? ⇒ Boolean
132 133 134 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 132 def needs_c_to_ruby_conversion_for_functions? TAGS_NEEDING_C_TO_RUBY_CONVERSION.include?(flattened_tag) end |
#needs_c_to_ruby_conversion_for_properties? ⇒ Boolean
158 159 160 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 158 def needs_c_to_ruby_conversion_for_properties? [:glist, :ghash, :callback].include?(flattened_tag) end |
#needs_ruby_to_c_conversion_for_callbacks? ⇒ Boolean
136 137 138 139 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 136 def needs_ruby_to_c_conversion_for_callbacks? [:enum].include?(flattened_tag) || needs_ruby_to_c_conversion_for_functions? end |
#needs_ruby_to_c_conversion_for_closures? ⇒ Boolean
150 151 152 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 150 def needs_ruby_to_c_conversion_for_closures? [:array].include?(flattened_tag) end |
#needs_ruby_to_c_conversion_for_functions? ⇒ Boolean
128 129 130 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 128 def needs_ruby_to_c_conversion_for_functions? TAGS_NEEDING_RUBY_TO_C_CONVERSION.include?(flattened_tag) end |
#needs_ruby_to_c_conversion_for_properties? ⇒ Boolean
154 155 156 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 154 def needs_ruby_to_c_conversion_for_properties? [:glist, :ghash, :strv, :callback].include?(flattened_tag) end |
#tag_or_class ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 45 def tag_or_class base = case tag when :interface interface_class when :ghash [tag, *element_type] else flattened_tag end if pointer? && tag != :utf8 && tag != :filename [:pointer, base] else base end end |
#to_callback_ffi_type ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 103 def to_callback_ffi_type return :pointer if pointer? case tag when :interface interface.to_callback_ffi_type when :gboolean # TODO: Move this logic into TypeMap :bool else TypeMap.map_basic_type tag end end |
#to_ffi_type ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/gir_ffi/info_ext/i_type_info.rb', line 90 def to_ffi_type return :pointer if pointer? case tag when :interface interface.to_ffi_type when :array [subtype_ffi_type(0), array_fixed_size] else TypeMap.map_basic_type tag end end |