Class: ConcurrentSHM::Value::IntPtr Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent-shm/int_ptr.rb,
ext/concurrent-shm/main.c

Overview

This class is abstract.

Subclasses must override #read and #write.

Base class for integer pointers.

Instance Method Summary collapse

Instance Method Details

#[](bit = nil) ⇒ Integer

Read from the pointer. If ‘bit` is non-nil, read the specified bit.

Parameters:

  • bit (Integer) (defaults to: nil)

    the bit position to read

Returns:

  • (Integer)

    the value of the pointer

Raises:

  • (ArgumentError)

    if the bit is not nil or an integer



24
25
26
27
28
29
# File 'lib/concurrent-shm/int_ptr.rb', line 24

def [](bit=nil)
  return read if bit.nil?
  return (read >> bit) & 0x1 if bit.is_a?(Integer)

  raise ArgumentError, "Invalid index: #{bit.inspect}"
end

#[]=(bit = nil, v) ⇒ Object

Writes to the pointer. If ‘bit` is non-nil, write the specified bit.

Parameters:

  • bit (Integer) (defaults to: nil)

    the bit position to read

  • v (Integer)

    the value to write

Raises:

  • (IntDomainError)

    if the write under or overflows

  • (ArgumentError)

    if the value is not an integer or boolean, or if the bit is not nil or an integer



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/concurrent-shm/int_ptr.rb', line 36

def []=(bit=nil, v)
  case bit
  when nil
    write(v)
  when Integer
    if v
      write(read | (1 << bit))
    else
      write(read & ~(1 << bit))
    end

  else
    raise ArgumentError, "Invalid index: #{bit.inspect}"
  end
end

#readInteger

Read from the pointer.

Returns:

  • (Integer)

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/concurrent-shm/int_ptr.rb', line 9

def read
  raise NotImplementedError
end

#write(value) ⇒ nil

Write to the pointer.

Parameters:

  • value (Integer)

Returns:

  • (nil)

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/concurrent-shm/int_ptr.rb', line 16

def write(value)
  raise NotImplementedError
end