Class: GRCommons::Fiddley::MemoryPointer
- Inherits:
-
Object
- Object
- GRCommons::Fiddley::MemoryPointer
show all
- Includes:
- Utils
- Defined in:
- lib/gr_commons/fiddley.rb
Constant Summary
Constants included
from Utils
Utils::SIZET_FORMAT, Utils::SIZET_TYPE
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#address ⇒ Object
-
#get_bytes(offset, len) ⇒ Object
-
#get_string(offset, len = nil) ⇒ Object
-
#initialize(type, num = 1) ⇒ MemoryPointer
constructor
A new instance of MemoryPointer.
-
#put_bytes(offset, str, idx = 0, len = str.bytesize - idx) ⇒ Object
-
#put_string(offset, str) ⇒ Object
-
#read_bytes(len) ⇒ Object
-
#read_pointer ⇒ Object
added NOTE: Return Fiddle::Pointer.
-
#read_string(len = nil) ⇒ Object
-
#to_ptr ⇒ Object
-
#write_bytes(str, idx = 0, len = nil) ⇒ Object
-
#write_string(str, len = nil) ⇒ Object
-
#write_string_length(str, len) ⇒ Object
Methods included from Utils
array2str, str2array, type2size, type2type
Constructor Details
#initialize(type, num = 1) ⇒ MemoryPointer
Returns a new instance of MemoryPointer.
185
186
187
188
189
190
191
192
193
|
# File 'lib/gr_commons/fiddley.rb', line 185
def initialize(type, num = 1)
if num.is_a?(Fiddle::Pointer)
@ptr = num
@size = @ptr.size
else
@size = type2size(type) * num
@ptr = Fiddle::Pointer.malloc(@size, Fiddle::RUBY_FREE)
end
end
|
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
195
196
197
|
# File 'lib/gr_commons/fiddley.rb', line 195
def size
@size
end
|
Instance Method Details
#address ⇒ Object
201
202
203
|
# File 'lib/gr_commons/fiddley.rb', line 201
def address
@ptr.to_i
end
|
#get_bytes(offset, len) ⇒ Object
363
364
365
|
# File 'lib/gr_commons/fiddley.rb', line 363
def get_bytes(offset, len)
@ptr[offset, len]
end
|
#get_string(offset, len = nil) ⇒ Object
383
384
385
|
# File 'lib/gr_commons/fiddley.rb', line 383
def get_string(offset, len = nil)
@ptr[offset, len || @size - offset]
end
|
#put_bytes(offset, str, idx = 0, len = str.bytesize - idx) ⇒ Object
355
356
357
|
# File 'lib/gr_commons/fiddley.rb', line 355
def put_bytes(offset, str, idx = 0, len = str.bytesize - idx)
@ptr[offset, len] = str[idx, len]
end
|
#put_string(offset, str) ⇒ Object
371
372
373
|
# File 'lib/gr_commons/fiddley.rb', line 371
def put_string(offset, str)
@ptr[offset, str.bytesize] = str
end
|
#read_bytes(len) ⇒ Object
367
368
369
|
# File 'lib/gr_commons/fiddley.rb', line 367
def read_bytes(len)
get_bytes(0, len)
end
|
#read_pointer ⇒ Object
added NOTE: Return Fiddle::Pointer. Not MemoryPointer.
393
394
395
|
# File 'lib/gr_commons/fiddley.rb', line 393
def read_pointer
to_ptr.ptr
end
|
#read_string(len = nil) ⇒ Object
387
388
389
|
# File 'lib/gr_commons/fiddley.rb', line 387
def read_string(len = nil)
get_string(0, len)
end
|
#to_ptr ⇒ Object
197
198
199
|
# File 'lib/gr_commons/fiddley.rb', line 197
def to_ptr
@ptr
end
|
#write_bytes(str, idx = 0, len = nil) ⇒ Object
359
360
361
|
# File 'lib/gr_commons/fiddley.rb', line 359
def write_bytes(str, idx = 0, len = nil)
put_bytes(0, str, idx, len)
end
|
#write_string(str, len = nil) ⇒ Object
375
376
377
|
# File 'lib/gr_commons/fiddley.rb', line 375
def write_string(str, len = nil)
put_string(0, len ? str[0, len] : str)
end
|
#write_string_length(str, len) ⇒ Object
379
380
381
|
# File 'lib/gr_commons/fiddley.rb', line 379
def write_string_length(str, len)
put_string(0, str[0, len])
end
|