Class: Gogyou::Model::Array
- Inherits:
-
Gogyou::Model
- Object
- Gogyou::Model
- Gogyou::Model::Array
- Defined in:
- lib/gogyou/model.rb
Overview
C の配列を模造するクラス。
Constant Summary
Constants inherited from Gogyou::Model
BasicStruct, FIELDNAME_PATTERN, TYPEMAP
Instance Method Summary collapse
Methods inherited from Gogyou::Model
check_typeinfo, define_container, #initialize, #pretty_print, struct, #to_s, typedef, union
Constructor Details
This class inherits a constructor from Gogyou::Model
Instance Method Details
#aref(buffer, offset) ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/gogyou/model.rb', line 500 def aref(buffer, offset) raise NotImplementedError accessor = Accessor::Array[buffer, offset, self] accessor.instance_eval do field = fields[0] type = field.type elements = field.vector[-1] define_singleton_method(:check_index, ->(i) { i = i.to_i raise IndexError unless i >= 0 && (elements.nil? || i < elements) i }) define_singleton_method(:[], ->(i) { v = type.aref(buffer__GOGYOU__, offset__GOGYOU__ + type.bytesize * check_index(i)) v.infect_from(self, buffer) unless v.frozen? v.freeze if frozen? || buffer.frozen? || field.const? v }) define_singleton_method(:[]=, ->(i, v) { type.aset(buffer__GOGYOU__, offset__GOGYOU__ + type.bytesize * check_index(i), v) }) end accessor end |
#aset(buffer, offset, value) ⇒ Object
496 497 498 |
# File 'lib/gogyou/model.rb', line 496 def aset(buffer, offset, value) raise NotImplementedError end |
#extensible? ⇒ Boolean
492 493 494 |
# File 'lib/gogyou/model.rb', line 492 def extensible? fields[-1] == 0 ? true : false end |