class GMSEC::Config

Public Class Methods

from_config_file(config_file, config_name) click to toggle source
# File lib/gmsec/config.rb, line 10
def self.from_config_file(config_file, config_name)
  config = config_file.get_config(config_name)
  new(native_object: to_native(config))
end
new(options={}) click to toggle source
# File lib/gmsec/config.rb, line 15
def initialize(options={})
  options.each do |key, value|
    add_value(key, value)
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/gmsec/config.rb, line 21
def [](key)
  get_value(key)
end
[]=(key, value) click to toggle source
# File lib/gmsec/config.rb, line 25
def []=(key, value)
  add_value(key, value)
end
to_xml() click to toggle source
# File lib/gmsec/config.rb, line 58
def to_xml
  with_string_pointer do |pointer|
    gmsec_ConfigToXML(self, pointer, status)
  end
end
values() click to toggle source
# File lib/gmsec/config.rb, line 29
def values
  Enumerator.new do |y|
    field = GMSEC::Field.new

    key_buffer = FFI::Buffer.new(1024)
    value_buffer = FFI::Buffer.new(8*1024)

    key_pointer = FFI::MemoryPointer.new(key_buffer)
    value_pointer = FFI::MemoryPointer.new(value_buffer)

    gmsec_ConfigGetFirst(self, key_pointer, value_pointer, status)

    key = key_pointer.read_pointer.read_string_to_null unless status.is_error?
    value = value_pointer.read_pointer.read_string_to_null unless status.is_error?

    while status.code != GMSEC_CONFIG_END_REACHED && status.code == GMSEC_STATUS_NO_ERROR
      y << [key, value]
      gmsec_ConfigGetNext(self, key_pointer, value_pointer, status)

      key = key_pointer.read_pointer.read_string_to_null unless status.is_error?
      value = value_pointer.read_pointer.read_string_to_null unless status.is_error?
    end

    if status.code != GMSEC_CONFIG_END_REACHED
      raise RuntimeError.new("Error reading config fields : #{status}")
    end
  end
end

Protected Instance Methods

add_value(key, value) click to toggle source
# File lib/gmsec/config.rb, line 66
def add_value(key, value)
  gmsec_ConfigAddValue(self, key.to_s, value.to_s, status)
  get_value(key)
end
get_value(key) click to toggle source
# File lib/gmsec/config.rb, line 71
def get_value(key)
  with_string_pointer do |pointer|
    gmsec_ConfigGetValue(self, key.to_s, pointer, status)
  end
end