Class: OodCore::Job::Adapters::Torque::FFI::Attrl
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- OodCore::Job::Adapters::Torque::FFI::Attrl
- Defined in:
- lib/ood_core/job/adapters/torque/ffi.rb
Overview
Struct for Attribute C-linked list
Class Method Summary collapse
-
.from_list(list) ⇒ Attrl
Given an array of attribute names convert it to Attrl C-linked list.
Instance Method Summary collapse
-
#to_h ⇒ Hash
Convert to hash describing this linked list.
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
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_h ⇒ Hash
Convert to hash describing this 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 |