Sha256: c2e59c2c0ea9939936d32f071e9173a92c96afc34b456385ba103e8c81786837

Contents?: true

Size: 725 Bytes

Versions: 19

Compression:

Stored size: 725 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
      reset_iterator or return
      while (ptr = next_ptr)
        yield ptr.read_string
      end
    end

    def self.wrap ptr
      self.new ptr
    end

    private

    def reset_iterator
      return if @ptr.null?
      @offset = 0
    end

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
gir_ffi-0.7.4 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.3 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.2 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.1 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.7.0 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.7 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.6 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.5 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.4 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.3 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.2 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.1 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.6.0 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.5.2 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.5.1 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.5.0 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.4.3 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.4.2 lib/gir_ffi-base/glib/strv.rb
gir_ffi-0.4.1 lib/gir_ffi-base/glib/strv.rb