module GLib::ListMethods

Common methods for List and SList.

Attributes

element_type[R]

Public Class Methods

included(base) click to toggle source
# File lib/ffi-glib/list_methods.rb, line 9
def self.included(base)
  # Override default field accessors.
  replace_method base, :next, :tail
  replace_method base, :data, :head

  base.extend ContainerClassMethods
end
new(type) click to toggle source
# File lib/ffi-glib/list_methods.rb, line 24
def initialize(type)
  store_pointer(FFI::Pointer.new(0))
  @element_type = type
end
replace_method(base, old, new) click to toggle source
# File lib/ffi-glib/list_methods.rb, line 17
def self.replace_method(base, old, new)
  base.class_eval do
    remove_method old
    alias_method old, new
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/ffi-glib/list_methods.rb, line 49
def ==(other)
  to_a == other.to_a
end
each() { |elem| ... } click to toggle source
# File lib/ffi-glib/list_methods.rb, line 29
def each
  reset_iterator
  while (elem = next_element)
    yield elem
  end
end
head() click to toggle source
# File lib/ffi-glib/list_methods.rb, line 40
def head
  GirFFI::ArgHelper.cast_from_pointer(element_type, @struct[:data])
end
reset_typespec(typespec) click to toggle source
# File lib/ffi-glib/list_methods.rb, line 44
def reset_typespec(typespec)
  @element_type = typespec
  self
end
tail() click to toggle source
# File lib/ffi-glib/list_methods.rb, line 36
def tail
  self.class.wrap(element_type, @struct[:next])
end

Private Instance Methods

element_ptr_for(data) click to toggle source
# File lib/ffi-glib/list_methods.rb, line 66
def element_ptr_for(data)
  GirFFI::InPointer.from(element_type, data)
end
next_element() click to toggle source
# File lib/ffi-glib/list_methods.rb, line 59
def next_element
  return unless @current
  element = @current.head
  @current = @current.tail
  element
end
reset_iterator() click to toggle source
# File lib/ffi-glib/list_methods.rb, line 55
def reset_iterator
  @current = self
end