Class: Zfp::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/zfp/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, shape, buffer) ⇒ Field

Returns a new instance of Field.

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zfp/field.rb', line 7

def initialize(type, shape, buffer)
  validate_shape!(shape)
  @type         = type
  @shape        = shape
  @buffer       = buffer  # hold reference — prevents GC while field is alive
  @zfp_type_int = Zfp::TypeCoercion::RUBY_TO_ZFP_TYPE[type]
  @ptr = Zfp::FFI.zfp_field_alloc
  raise Zfp::Error, "Failed to allocate zfp_field" if @ptr.null?

  Zfp::FFI.zfp_field_set_pointer(@ptr, buffer)
  Zfp::FFI.zfp_field_set_type(@ptr, @zfp_type_int)
  set_shape(shape)
end

Instance Attribute Details

#shapeObject (readonly)

Returns the value of attribute shape.



5
6
7
# File 'lib/zfp/field.rb', line 5

def shape
  @shape
end

#zfp_type_intObject (readonly)

Returns the value of attribute zfp_type_int.



5
6
7
# File 'lib/zfp/field.rb', line 5

def zfp_type_int
  @zfp_type_int
end

Instance Method Details

#dimsObject



25
26
27
# File 'lib/zfp/field.rb', line 25

def dims
  @shape.length
end

#freeObject



29
30
31
32
33
# File 'lib/zfp/field.rb', line 29

def free
  return if @ptr.nil? || @ptr.null?
  Zfp::FFI.zfp_field_free(@ptr)
  @ptr = ::FFI::Pointer::NULL
end

#pointerObject



21
22
23
# File 'lib/zfp/field.rb', line 21

def pointer
  @ptr
end