|
|
@ -36,8 +36,8 @@ class Compound < MemStruct
|
|
|
|
def pointer_ary(tglen)
|
|
|
|
def pointer_ary(tglen)
|
|
|
|
PointerAry.new(tglen, yield)
|
|
|
|
PointerAry.new(tglen, yield)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def static_array(len, tglen)
|
|
|
|
def static_array(len, tglen, indexenum=nil)
|
|
|
|
StaticArray.new(tglen, len, yield)
|
|
|
|
StaticArray.new(tglen, len, indexenum, yield)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def static_string(len)
|
|
|
|
def static_string(len)
|
|
|
|
StaticString.new(len)
|
|
|
|
StaticString.new(len)
|
|
|
@ -61,8 +61,8 @@ class Compound < MemStruct
|
|
|
|
StlDeque.new(tglen, yield)
|
|
|
|
StlDeque.new(tglen, yield)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def df_flagarray
|
|
|
|
def df_flagarray(indexenum=nil)
|
|
|
|
DfFlagarray.new
|
|
|
|
DfFlagarray.new(indexenum)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def df_array(tglen)
|
|
|
|
def df_array(tglen)
|
|
|
|
DfArray.new(tglen, yield)
|
|
|
|
DfArray.new(tglen, yield)
|
|
|
@ -250,11 +250,22 @@ class PointerAry < MemStruct
|
|
|
|
|
|
|
|
|
|
|
|
def inspect ; "#<PointerAry #{'0x%X' % _getp}>" ; end
|
|
|
|
def inspect ; "#<PointerAry #{'0x%X' % _getp}>" ; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module IndexEnum
|
|
|
|
|
|
|
|
def indexenum(idx)
|
|
|
|
|
|
|
|
if idx.kind_of?(::Symbol) or idx.kind_of?(::String) and _indexenum
|
|
|
|
|
|
|
|
DFHack.const_get(_indexenum).const_get(idx) || idx
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
idx
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
class StaticArray < MemStruct
|
|
|
|
class StaticArray < MemStruct
|
|
|
|
attr_accessor :_tglen, :_length, :_tg
|
|
|
|
include IndexEnum
|
|
|
|
def initialize(tglen, length, tg)
|
|
|
|
attr_accessor :_tglen, :_length, :_indexenum, :_tg
|
|
|
|
|
|
|
|
def initialize(tglen, length, indexenum, tg)
|
|
|
|
@_tglen = tglen
|
|
|
|
@_tglen = tglen
|
|
|
|
@_length = length
|
|
|
|
@_length = length
|
|
|
|
|
|
|
|
@_indexenum = indexenum
|
|
|
|
@_tg = tg
|
|
|
|
@_tg = tg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def _set(a)
|
|
|
|
def _set(a)
|
|
|
@ -266,17 +277,26 @@ class StaticArray < MemStruct
|
|
|
|
@_tg._at(@_memaddr + i*@_tglen) if i >= 0 and i < @_length
|
|
|
|
@_tg._at(@_memaddr + i*@_tglen) if i >= 0 and i < @_length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def [](i)
|
|
|
|
def [](i)
|
|
|
|
|
|
|
|
i = indexenum(i)
|
|
|
|
i += @_length if i < 0
|
|
|
|
i += @_length if i < 0
|
|
|
|
_tgat(i)._get
|
|
|
|
_tgat(i)._get
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def []=(i, v)
|
|
|
|
def []=(i, v)
|
|
|
|
|
|
|
|
i = indexenum(i)
|
|
|
|
i += @_length if i < 0
|
|
|
|
i += @_length if i < 0
|
|
|
|
_tgat(i)._set(v)
|
|
|
|
_tgat(i)._set(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
include Enumerable
|
|
|
|
include Enumerable
|
|
|
|
def each ; (0...length).each { |i| yield self[i] } ; end
|
|
|
|
def each ; (0...length).each { |i| yield self[i] } ; end
|
|
|
|
def inspect ; to_a.inspect ; end
|
|
|
|
def inspect
|
|
|
|
|
|
|
|
if _indexenum
|
|
|
|
|
|
|
|
e = DFHack.const_get(_indexenum)::ENUM
|
|
|
|
|
|
|
|
'[' + (0...length).map { |i| "#{e[i]}=#{self[i].inspect}" }.join(' ') + ']'
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
to_a.inspect
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class StaticString < MemStruct
|
|
|
|
class StaticString < MemStruct
|
|
|
|
attr_accessor :_length
|
|
|
|
attr_accessor :_length
|
|
|
@ -431,6 +451,11 @@ class StlDeque < MemStruct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class DfFlagarray < MemStruct
|
|
|
|
class DfFlagarray < MemStruct
|
|
|
|
|
|
|
|
include IndexEnum
|
|
|
|
|
|
|
|
attr_accessor :_indexenum
|
|
|
|
|
|
|
|
def initialize(indexenum)
|
|
|
|
|
|
|
|
@_indexenum = indexenum
|
|
|
|
|
|
|
|
end
|
|
|
|
def length
|
|
|
|
def length
|
|
|
|
DFHack.memory_bitarray_length(@_memaddr)
|
|
|
|
DFHack.memory_bitarray_length(@_memaddr)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -439,10 +464,12 @@ class DfFlagarray < MemStruct
|
|
|
|
DFHack.memory_bitarray_resize(@_memaddr, len)
|
|
|
|
DFHack.memory_bitarray_resize(@_memaddr, len)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def [](idx)
|
|
|
|
def [](idx)
|
|
|
|
|
|
|
|
idx = indexenum(idx)
|
|
|
|
idx += length if idx < 0
|
|
|
|
idx += length if idx < 0
|
|
|
|
DFHack.memory_bitarray_isset(@_memaddr, idx) if idx >= 0 and idx < length
|
|
|
|
DFHack.memory_bitarray_isset(@_memaddr, idx) if idx >= 0 and idx < length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def []=(idx, v)
|
|
|
|
def []=(idx, v)
|
|
|
|
|
|
|
|
idx = indexenum(idx)
|
|
|
|
idx += length if idx < 0
|
|
|
|
idx += length if idx < 0
|
|
|
|
if idx >= length or idx < 0
|
|
|
|
if idx >= length or idx < 0
|
|
|
|
raise 'invalid idx'
|
|
|
|
raise 'invalid idx'
|
|
|
@ -453,7 +480,14 @@ class DfFlagarray < MemStruct
|
|
|
|
|
|
|
|
|
|
|
|
include Enumerable
|
|
|
|
include Enumerable
|
|
|
|
def each ; (0...length).each { |i| yield self[i] } ; end
|
|
|
|
def each ; (0...length).each { |i| yield self[i] } ; end
|
|
|
|
def inspect ; to_a.inspect ; end
|
|
|
|
def inspect
|
|
|
|
|
|
|
|
if _indexenum
|
|
|
|
|
|
|
|
e = DFHack.const_get(_indexenum)::ENUM
|
|
|
|
|
|
|
|
'[' + (0...length).map { |i| if self[i] ; e[i] || i ; end }.compact.join(' ') + ']'
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
to_a.inspect
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class DfArray < Compound
|
|
|
|
class DfArray < Compound
|
|
|
|
attr_accessor :_tglen, :_tg
|
|
|
|
attr_accessor :_tglen, :_tg
|
|
|
|