Class: GLib::SList

Inherits:
Object
  • Object
show all
Includes:
ListMethods
Defined in:
lib/ffi-glib/s_list.rb

Overview

Overrides for GSList, GLib’s singly-linked list implementation.

Instance Attribute Summary

Attributes included from ListMethods

#element_type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ListMethods

#each, #head, included, replace_method, #reset_typespec, #tail

Class Method Details

.from_enumerable(type, arr) ⇒ Object



22
23
24
25
# File 'lib/ffi-glib/s_list.rb', line 22

def self.from_enumerable type, arr
  arr.reverse.inject(self.new type) { |lst, val|
    lst.prepend val }
end

.new(type) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ffi-glib/s_list.rb', line 14

def self.new type
  _real_new.tap do |it|
    struct = self::Struct.new(FFI::Pointer.new(0))
    it.instance_variable_set :@struct, struct
    it.element_type = type
  end
end

Instance Method Details

#prepend(data) ⇒ Object



27
28
29
30
31
# File 'lib/ffi-glib/s_list.rb', line 27

def prepend data
  elm_t = element_type
  data_ptr = GirFFI::InPointer.from(elm_t, data)
  self.class.wrap(elm_t, Lib.g_slist_prepend(self, data_ptr))
end