Sha256: 84d81c56739a3bde7a1ce77bcc7b3ebca09979e3cd9ce6f7d7c34c3948752b14

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

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 { layout(*spec) }
      end

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

      def base_layout_specification
        fields.map(&:layout_specification).flatten(1)
      end

      def setup_field_accessors
        fields.each do |finfo|
          FieldBuilder.new(finfo).build
        end
      end

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gir_ffi-0.8.6 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.8.5 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.8.4 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.8.3 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.8.2 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.8.1 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.8.0 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.7.10 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.7.9 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.7.8 lib/gir_ffi/builders/with_layout.rb
gir_ffi-0.7.7 lib/gir_ffi/builders/with_layout.rb