Class: OodCore::Job::Adapters::Torque::FFI::Attrl

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/ood_core/job/adapters/torque/ffi.rb

Overview

Struct for Attribute C-linked list

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_list(list) ⇒ Attrl

Given an array of attribute names convert it to OodCore::Job::Adapters::Torque::FFI::Attrl C-linked list

Parameters:

  • list (Array<Symbol>)

    list of attribute names

Returns:

  • (Attrl)

    generated attribute c-linked list object



214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ood_core/job/adapters/torque/ffi.rb', line 214

def self.from_list(list)
  attrl = nil
  prev = Attrl.new(::FFI::Pointer::NULL)
  list.each do |key|
    attrl = Attrl.new
    attrl[:name] = ::FFI::MemoryPointer.from_string(key.to_s)
    attrl[:next] = prev
    prev = attrl
  end
  attrl
end

Instance Method Details

#to_hHash

Convert to hash describing this linked list

Returns:

  • (Hash)

    hash describing linked list



228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/ood_core/job/adapters/torque/ffi.rb', line 228

def to_h
  attrl = self
  hash = {}
  until attrl.to_ptr.null?
    n = attrl[:name].read_string
    v = attrl[:value].read_string
    r = attrl[:resource].null? ? nil : attrl[:resource].read_string
    r ? (hash[n.to_sym] ||= {} and hash[n.to_sym][r.to_sym] = v) : hash[n.to_sym] = v
    attrl = attrl[:next]
  end
  hash
end