Sha256: 52289d558317a3a7cc14eb65b7f9f451b8ca184903697c59ffc5c3e122b2f004

Contents?: true

Size: 727 Bytes

Versions: 13

Compression:

Stored size: 727 Bytes

Contents

# frozen_string_literal: true

require "ffi"

module GObjectIntrospection
  # 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
      offset = 0
      while (ptr = fetch_ptr offset)
        offset += POINTER_SIZE
        yield ptr.read_string
      end
    end

    def self.wrap(ptr)
      new ptr
    end

    private

    def fetch_ptr(offset)
      return if @ptr.null?

      ptr = @ptr.get_pointer offset
      ptr unless ptr.null?
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gir_ffi-0.17.0 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.16.1 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.16.0 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.9 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.8 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.7 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.6 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.5 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.4 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.3 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.2 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.1 lib/ffi-gobject_introspection/strv.rb
gir_ffi-0.15.0 lib/ffi-gobject_introspection/strv.rb