Sha256: ab1d1cdf3e186b33b87b4901b89104b8967617acc78630dcb1ef097cff6cce14

Contents?: true

Size: 1.12 KB

Versions: 13

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "gir_ffi/builders/field_builder"

module GirFFI
  module Builders
    # Implements the creation of classes representing types with layout,
    # i.e., :union, :struct, :object.
    # NOTE: This module depends on methods in RegisteredTypeBuilder.
    module WithLayout
      def layout_specification
        spec = base_layout_specification
        if spec.empty?
          dummy_layout_specification
        else
          spec
        end
      end

      private

      def setup_layout
        spec = layout_specification
        struct_class.class_eval do
          layout(*spec)
        end
      end

      def dummy_layout_specification
        if parent_info
          [:parent, superclass::Struct, 0]
        else
          [:dummy, :char, 0]
        end
      end

      def base_layout_specification
        fields.flat_map(&:layout_specification)
      end

      def klass
        @klass ||= get_or_define_class namespace_module, @classname, superclass
      end

      def struct_class
        @struct_class ||= get_or_define_class klass, :Struct, layout_superclass
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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