Class: NWRFC::Table

Inherits:
DataContainer show all
Includes:
Enumerable
Defined in:
lib/nwrfc.rb

Instance Attribute Summary

Attributes inherited from DataContainer

#desc, #handle

Instance Method Summary collapse

Methods inherited from DataContainer

#[]=, #fields, #initialize, #member_metadata, #value_to_date, #value_to_time

Constructor Details

This class inherits a constructor from NWRFC::DataContainer

Instance Method Details

#[](index) ⇒ Object

Retrieve the row at the given index



348
349
350
351
352
353
354
# File 'lib/nwrfc.rb', line 348

def [](index)
  rc = NWRFCLib.move_to(@handle, index, @error)
  NWRFC.check_error(@error) if rc > 0
  struct_handle = NWRFCLib.get_current_row(@handle, @error)
  NWRFC.check_error(@error)
  Structure.new(struct_handle)
end

#append(row) ⇒ Object

Append a row (structure) to the table



357
358
359
360
361
# File 'lib/nwrfc.rb', line 357

def append(row)
  raise "Must append a structure" unless row.class == NWRFC::Structure
  rc = NWRFCLib.append_row(@handle, row.handle, @error)
  NWRFC.check_error(@error) if rc > 0
end

#clearObject

Delete all rows from (empty) the table



342
343
344
345
# File 'lib/nwrfc.rb', line 342

def clear
  rc = delete_all_rows(@handle, @error)
  NWRFC.check_error(@error) if rc > 0
end

#each(&block) ⇒ Object

Iterate over the rows in a table. Each row is yielded as a structure



322
323
324
325
326
327
328
329
330
331
332
# File 'lib/nwrfc.rb', line 322

def each(&block) #:yields row
  rc = NWRFCLib.move_to_first_row(@handle, @error)
  NWRFC.check_error(@error) if rc > 0
  size.times do |row|
    struct_handle = NWRFCLib.get_current_row(@handle, @error)
    NWRFC.check_error(@error)
    # CAVEAT: Other calls using the handle require "handle" field
    # of the RFC_DATA_CONTAINER struct
    yield Structure.new(struct_handle)
  end
end

#new_rowObject

Add new (empty) row and return the structure handle or yield it to a passed block

Returns:

  • Structure



366
367
368
369
370
371
372
373
374
375
# File 'lib/nwrfc.rb', line 366

def new_row
  s_handle = NWRFCLib.append_new_row(@handle, @error)
  NWRFC.check_error(@error)
  s = Structure.new(s_handle)
  if block_given?
    yield s
  else
    s
  end
end

#sizeObject

Return the number of rows in the table



335
336
337
338
339
# File 'lib/nwrfc.rb', line 335

def size
  rows = FFI::MemoryPointer.new(:uint)
  rc = NWRFCLib.get_row_count(@handle, rows, @error)
  rows.read_uint
end