Sha256: 10e713b9b537c04e5b628d256ae44bd876b2e2374bd23fe44ce787116ccc18b2

Contents?: true

Size: 710 Bytes

Versions: 5

Compression:

Stored size: 710 Bytes

Contents

require 'ffi'

module GLib
  # Represents a null-terminated array of strings. GLib uses this
  # construction, but does not provide any actual functions for this class.
  class Strv
    include Enumerable

    POINTER_SIZE = FFI.type_size(:pointer)

    def initialize ptr
      @ptr = ptr
    end

    def to_ptr
      @ptr
    end

    def each
      return if @ptr.null?
      reset_iterator
      while (ptr = next_ptr)
        yield ptr.read_string
      end
    end

    def self.wrap ptr
      new ptr
    end

    private

    def reset_iterator
      @offset = 0
    end

    def next_ptr
      ptr = @ptr.get_pointer @offset
      @offset += POINTER_SIZE
      ptr unless ptr.null?
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.7.10 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.9 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.8 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.7 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.6 lib/gir_ffi-base/glib/strv.rb