Sha256: accb54ff582dace3c0ce3850fb125e09839ce28cac23ba2a20554eb4dd502da3

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module GirFFI
  module Builders
    # Encapsulates knowledge about how to store values in pointers, and how to
    # fetch values from pointers.
    class PointerValueConvertor
      def initialize(type_spec)
        @type_spec = type_spec
      end

      def pointer_to_value(ptr_exp, offset = 0)
        case ffi_type_spec
        when Module
          "#{ffi_type_spec}.get_value_from_pointer(#{ptr_exp}, #{offset})"
        when Symbol
          "#{ptr_exp}.get_#{ffi_type_spec}(#{offset})"
        end
      end

      def value_to_pointer(ptr_exp, value_exp, offset = 0)
        case ffi_type_spec
        when Module
          args = [value_exp, ptr_exp]
          args << offset unless offset == 0
          "#{ffi_type_spec}.copy_value_to_pointer(#{args.join(', ')})"
        when Symbol
          "#{ptr_exp}.put_#{ffi_type_spec} #{offset}, #{value_exp}"
        end
      end

      private

      attr_reader :type_spec

      def ffi_type_spec
        TypeMap.type_specification_to_ffi_type type_spec
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gir_ffi-0.16.0 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.9 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.8 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.7 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.6 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.5 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.4 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.3 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.2 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.1 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.15.0 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.14.1 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.14.0 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.13.1 lib/gir_ffi/builders/pointer_value_convertor.rb