Sha256: d99d8de28b0773a8a317d6b0f802251338fab5564ed90a5c4d78c50cbbe7b33f

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

require_relative '../ogr'
require_relative 'style_table_extensions'

module OGR
  class StyleTable
    include StyleTableExtensions

    # @return [FFI::Pointer] C pointer to the C style table.
    attr_reader :c_pointer

    # @param [FFI::Pointer] c_pointer
    def initialize(c_pointer = nil)
      @c_pointer = c_pointer ? c_pointer : FFI::OGR::API.OGR_STBL_Create

      raise 'Unable to create StyleTable' if @c_pointer.null?
    end

    def destroy!
      return unless @c_pointer

      FFI::OGR::API.OGR_STBL_Destroy(@c_pointer)
      @c_pointer = nil
    end

    # @param name [String] Name of the style.
    # @param style [String]
    # @return [Boolean]
    def add_style(name, style)
      FFI::OGR::API.OGR_STBL_AddStyle(@c_pointer, name, style)
    end

    # @param style_name [String]
    # @return [String, nil]
    def find(style_name)
      FFI::OGR::API.OGR_STBL_Find(@c_pointer, style_name)
    end

    # @return [String, nil] The style name of the last string fetched with #next_style.
    def last_style_name
      FFI::OGR::API.OGR_STBL_GetLastStyleName(@c_pointer)
    end

    # @return [String, nil] The next style string from the table.
    def next_style
      FFI::OGR::API.OGR_STBL_GetNextStyle(@c_pointer)
    end

    # @param file_name [String]
    # @return [Boolean]
    def load!(file_name)
      FFI::OGR::API.OGR_STBL_LoadStyleTable(@c_pointer, file_name)
    end

    # Resets the #next_style to the 0th style.
    def reset_style_string_reading
      FFI::OGR::API.OGR_STBL_ResetStyleStringReading(@c_pointer)
    end

    # @param file_name [String] Path to the file to save to.
    # @return [Boolean]
    def save(file_name)
      FFI::OGR::API.OGR_STBL_SaveStyleTable(@c_pointer, file_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta7 lib/ogr/style_table.rb
ffi-gdal-1.0.0.beta6 lib/ogr/style_table.rb