Sha256: 2f47d7afe00cc4ab3dee04b8d60355092979617f7c07b59518772776b8e679a1

Contents?: true

Size: 742 Bytes

Versions: 11

Compression:

Stored size: 742 Bytes

Contents

require 'ffi-glib/list_methods'

module GLib
  load_class :SList

  # Overrides for GSList, GLib's singly-linked list implementation.
  class SList
    include ListMethods

    class << self
      remove_method :new
    end

    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

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

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gir_ffi-0.6.7 lib/ffi-glib/s_list.rb
gir_ffi-0.6.6 lib/ffi-glib/s_list.rb
gir_ffi-0.6.5 lib/ffi-glib/s_list.rb
gir_ffi-0.6.4 lib/ffi-glib/s_list.rb
gir_ffi-0.6.3 lib/ffi-glib/s_list.rb
gir_ffi-0.6.2 lib/ffi-glib/s_list.rb
gir_ffi-0.6.1 lib/ffi-glib/s_list.rb
gir_ffi-0.6.0 lib/ffi-glib/s_list.rb
gir_ffi-0.5.2 lib/ffi-glib/s_list.rb
gir_ffi-0.5.1 lib/ffi-glib/s_list.rb
gir_ffi-0.5.0 lib/ffi-glib/s_list.rb