Class: ConcurrentSHM::Value::IntPtr Abstract
- Inherits:
-
Object
- Object
- ConcurrentSHM::Value::IntPtr
- Defined in:
- lib/concurrent-shm/int_ptr.rb,
ext/concurrent-shm/main.c
Overview
Direct Known Subclasses
Int16Ptr, Int32Ptr, Int64Ptr, Int8Ptr, UInt16Ptr, UInt32Ptr, UInt64Ptr, UInt8Ptr
Instance Method Summary collapse
-
#[](bit = nil) ⇒ Integer
Read from the pointer.
-
#[]=(bit = nil, v) ⇒ Object
Writes to the pointer.
-
#read ⇒ Integer
Read from the pointer.
-
#write(value) ⇒ nil
Write to the pointer.
Instance Method Details
#[](bit = nil) ⇒ Integer
Read from the pointer. If ‘bit` is non-nil, read the specified bit.
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.
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 |
#read ⇒ Integer
Read from the pointer.
9 10 11 |
# File 'lib/concurrent-shm/int_ptr.rb', line 9 def read raise NotImplementedError end |
#write(value) ⇒ nil
Write to the pointer.
16 17 18 |
# File 'lib/concurrent-shm/int_ptr.rb', line 16 def write(value) raise NotImplementedError end |