Class: Proj::Options
- Inherits:
-
Object
- Object
- Proj::Options
- Defined in:
- lib/proj/options.rb
Overview
Wraps a hash of key-value pairs as a null-terminated array of “KEY=VALUE” C string pointers suitable for PROJ option parameters.
Many PROJ C API functions accept an optional array of “KEY=VALUE” strings to control their behavior. This class builds the required pointer array and keeps the underlying FFI memory alive so that the garbage collector cannot free it before the C call returns.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Options
constructor
Creates a new Options instance.
-
#to_ptr ⇒ FFI::Pointer
Returns the pointer to the null-terminated string array, or a NULL pointer if no options were provided.
Constructor Details
#initialize(options = {}) ⇒ Options
Creates a new Options instance.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/proj/options.rb', line 18 def initialize( = {}) = .compact @string_ptrs = .map do |key, value| FFI::MemoryPointer.from_string("#{key}=#{value}") end if @string_ptrs.empty? @pointer = nil else @pointer = FFI::MemoryPointer.new(:pointer, .size + 1) # PROJ expects a NULL-terminated char* array. @pointer.write_array_of_pointer(@string_ptrs + [FFI::Pointer::NULL]) end end |
Instance Method Details
#to_ptr ⇒ FFI::Pointer
Returns the pointer to the null-terminated string array, or a NULL pointer if no options were provided.
37 38 39 |
# File 'lib/proj/options.rb', line 37 def to_ptr @pointer || FFI::Pointer::NULL end |