Sha256: 33db990603701dc208f0b2d42a8861608a9c2d400eec5dd068dd21ccc4cdb549

Contents?: true

Size: 919 Bytes

Versions: 3

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require 'gir_ffi/builders/registered_type_builder'
require 'gir_ffi/builders/struct_like'
require 'gir_ffi/struct_base'

module GirFFI
  module Builders
    # Implements the creation of a class representing a Struct.
    class StructBuilder < RegisteredTypeBuilder
      include StructLike

      def layout_superclass
        GirFFI::Struct
      end

      def superclass
        if info.gtype_struct?
          # HACK: Inheritance chain is not expressed in GObject's code correctly.
          type_name = info.full_type_name
          return GObject::ObjectClass if type_name == 'GObject::InitiallyUnownedClass'
          type = fields.first.field_type
          return type.tag_or_class if type.tag == :interface
        end

        if GObject.type_fundamental(info.gtype) == GObject::TYPE_BOXED
          return BoxedBase
        end

        StructBase
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gir_ffi-0.11.4 lib/gir_ffi/builders/struct_builder.rb
gir_ffi-0.11.3 lib/gir_ffi/builders/struct_builder.rb
gir_ffi-0.11.2 lib/gir_ffi/builders/struct_builder.rb