Class: GirFFI::Builders::FieldBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/builders/field_builder.rb

Overview

Creates field getter and setter code for a given IFieldInfo.

Defined Under Namespace

Classes: GetterArgumentBuilder, GetterArgumentInfo, GetterBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_info, container_class) ⇒ FieldBuilder

Returns a new instance of FieldBuilder.



234
235
236
237
# File 'lib/gir_ffi/builders/field_builder.rb', line 234

def initialize(field_info, container_class)
  @info = field_info
  @container_class = container_class
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



232
233
234
# File 'lib/gir_ffi/builders/field_builder.rb', line 232

def info
  @info
end

Instance Method Details

#buildObject



239
240
241
242
# File 'lib/gir_ffi/builders/field_builder.rb', line 239

def build
  setup_getter
  setup_setter
end

#container_defines_getter_method?Boolean

Returns:



251
252
253
# File 'lib/gir_ffi/builders/field_builder.rb', line 251

def container_defines_getter_method?
  container_info.find_instance_method info.name
end

#getter_defObject



262
263
264
265
# File 'lib/gir_ffi/builders/field_builder.rb', line 262

def getter_def
  getter_builder = GetterBuilder.new(info)
  getter_builder.method_definition
end

#setter_defObject

TODO: Use MethodTemplate



268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/gir_ffi/builders/field_builder.rb', line 268

def setter_def
  builder = setter_builder

  field_ptr = builder.new_variable

  <<~CODE
    def #{info.name}= #{builder.method_argument_name}
      #{field_ptr} = @struct.to_ptr
      #{builder.pre_conversion.join("\n  ")}
      #{value_storage(field_ptr, builder)}
    end
  CODE
end

#setup_getterObject



244
245
246
247
248
249
# File 'lib/gir_ffi/builders/field_builder.rb', line 244

def setup_getter
  return if container_defines_getter_method?
  return if hidden_struct_type?

  container_class.class_eval getter_def, __FILE__, __LINE__
end

#setup_setterObject



255
256
257
258
259
260
# File 'lib/gir_ffi/builders/field_builder.rb', line 255

def setup_setter
  return unless info.writable?
  return if hidden_struct_type?

  container_class.class_eval setter_def, __FILE__, __LINE__
end