Class: GDAL::Options
- Inherits:
-
Object
- Object
- GDAL::Options
- Defined in:
- lib/gdal/options.rb
Overview
A wrapper for the way GDAL does key/value pair options for methods.
Class Method Summary collapse
-
.pointer(hash) ⇒ FFI::MemoryPointer?
Shortcut for if you just want to build the options and get the pointer to them.
- .release(pointer) ⇒ Object
-
.to_hash(pointer) ⇒ Hash
Takes a GDAL options pointer and turns it into a Ruby Hash.
Class Method Details
.pointer(hash) ⇒ FFI::MemoryPointer?
Shortcut for if you just want to build the options and get the pointer to them.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gdal/options.rb', line 13 def self.pointer(hash) return if hash.empty? = FFI::MemoryPointer.new(:pointer) .autorelease = false hash.each do |key, value| # Note, we started off with a MemoryPointer above, but this returns a # new FFI::Pointer. = FFI::CPL::String.CSLAddNameValue(, key.to_s.upcase, value.to_s) .autorelease = false end FFI::AutoPointer.new(, Options.method(:release)) end |
.release(pointer) ⇒ Object
48 49 50 51 52 |
# File 'lib/gdal/options.rb', line 48 def self.release(pointer) return if pointer.nil? || pointer.null? FFI::CPL::String.CSLDestroy(pointer) end |
.to_hash(pointer) ⇒ Hash
Takes a GDAL options pointer and turns it into a Ruby Hash.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gdal/options.rb', line 33 def self.to_hash(pointer) # Docs say passing a null pointer here is ok; will result in 0. count = FFI::CPL::String.CSLCount(pointer) count.times.each_with_object({}) do |i, o| # Docs say that the pointer returned from CSLGetField shouldn't be freed. key_and_value, ptr = FFI::CPL::String.CSLGetField(pointer, i) ptr.autorelease = false key, value = key_and_value.split("=") o[key.downcase.to_sym] = value end end |