Sha256: 9facaf0c9108341bd759515843af7249087829fcbdcfdbc6d8563e64c80e4ede

Contents?: true

Size: 950 Bytes

Versions: 6

Compression:

Stored size: 950 Bytes

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)
        case ffi_type_spec
        when Module
          "#{ffi_type_spec}.get_value_from_pointer(#{ptr_exp}, 0)"
        when Symbol
          "#{ptr_exp}.get_#{ffi_type_spec}(0)"
        end
      end

      def value_to_pointer(ptr_exp, value_exp)
        case ffi_type_spec
        when Module
          "#{ffi_type_spec}.copy_value_to_pointer(#{value_exp}, #{ptr_exp})"
        when Symbol
          "#{ptr_exp}.put_#{ffi_type_spec} 0, #{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

6 entries across 6 versions & 1 rubygems

Version Path
gir_ffi-0.13.0 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.12.1 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.12.0 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.11.4 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.11.3 lib/gir_ffi/builders/pointer_value_convertor.rb
gir_ffi-0.11.2 lib/gir_ffi/builders/pointer_value_convertor.rb