Sha256: 8966a57883490fae8c4a7d3e73eb4aeabac690ed5dcb75b546ef75765f038b62

Contents?: true

Size: 892 Bytes

Versions: 5

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

module GLib
  # Common methods for container classes: Array, PtrArray, List, SList and
  # HashTable.
  module ContainerClassMethods
    def wrap(typespec, ptr)
      # HACK: wrap and from are almost the same!
      ptr = case ptr
            when nil
              nil
            when FFI::Pointer
              ptr
            when self
              ptr.to_ptr
            when GirFFI::BoxedBase
              ptr.to_ptr
            end

      super(ptr).tap do |container|
        container&.reset_typespec typespec
      end
    end

    def from(typespec = :void, obj)
      case obj
      when nil
        nil
      when FFI::Pointer
        wrap typespec, obj
      when self
        obj.reset_typespec typespec
      when GirFFI::BoxedBase
        wrap typespec, obj.to_ptr
      else
        from_enumerable typespec, obj
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.15.4 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.3 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.2 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.1 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.0 lib/ffi-glib/container_class_methods.rb