Class: Rclrb::Fields::AtomicField

Inherits:
Object
  • Object
show all
Defined in:
lib/rclrb/fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_value, field_name, ffi_type, array_reader, array_writter) ⇒ AtomicField

Returns a new instance of AtomicField.



26
27
28
29
30
31
32
33
# File 'lib/rclrb/fields.rb', line 26

def initialize(init_value, field_name, ffi_type, array_reader, array_writter)
  @init_value = init_value
  @field_name    = "Rclrb::Fields::#{field_name}"
  @ffi_type      = ffi_type
  @memory_size   = FFI::type_size @ffi_type
  @array_reader  = array_reader
  @array_writter = array_writter
end

Instance Attribute Details

#ffi_typeObject (readonly)

Returns the value of attribute ffi_type.



25
26
27
# File 'lib/rclrb/fields.rb', line 25

def ffi_type
  @ffi_type
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



25
26
27
# File 'lib/rclrb/fields.rb', line 25

def field_name
  @field_name
end

#init_valueObject (readonly)

Returns the value of attribute init_value.



25
26
27
# File 'lib/rclrb/fields.rb', line 25

def init_value
  @init_value
end

Instance Method Details

#array_fieldObject



37
38
39
40
# File 'lib/rclrb/fields.rb', line 37

def array_field()
  @array_field = ArrayField.new(self) unless defined?(@array_field)
  return @array_field
end

#create_from_dict(v) ⇒ Object



34
35
36
# File 'lib/rclrb/fields.rb', line 34

def create_from_dict v
  return v
end

#destroy_ros_message(data) ⇒ Object



61
62
# File 'lib/rclrb/fields.rb', line 61

def destroy_ros_message(data)
end

#ffi_sizeObject



63
64
65
# File 'lib/rclrb/fields.rb', line 63

def ffi_size()
  return @memory_size
end

#fill_ros_message(data, index, value) ⇒ Object



51
52
53
# File 'lib/rclrb/fields.rb', line 51

def fill_ros_message(data, index, value)
  data[index] = value
end

#fill_ros_message_array(array_pointer, value) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/rclrb/fields.rb', line 54

def fill_ros_message_array(array_pointer, value)
  if @array_writter
    return array_pointer.send @array_writter, 0, value
  else
    Fields.__generic_fill_ros_message_array(array_pointer, value, self.ffi_size) { |ptr, value| ptr.put @ffi_type, 0, value }
  end
end

#is_atomicObject



66
67
68
# File 'lib/rclrb/fields.rb', line 66

def is_atomic
  return true
end

#parse_ros_message(data) ⇒ Object



41
42
43
# File 'lib/rclrb/fields.rb', line 41

def parse_ros_message(data)
  return data
end

#parse_ros_message_array(data, length) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rclrb/fields.rb', line 44

def parse_ros_message_array(data, length)
  if @array_reader
    return data.send @array_reader, 0, length
  else
    return Fields.__generic_parse_array(data, length, self.ffi_size) { |ptr| ptr.get(@ffi_type, 0) }
  end
end