Class: CZMQ::FFI::Zlistx
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zlistx
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zlistx.rb
Overview
This class is 100% generated using zproject.
extended generic list container
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
-
.comparator_fn ⇒ Object
Create a new callback of the following type: Compare two items, for sorting typedef int (zlistx_comparator_fn) ( const void *item1, const void *item2);.
- .create_finalizer_for(ptr) ⇒ Proc
-
.destructor_fn ⇒ Object
Create a new callback of the following type: Destroy an item typedef void (zlistx_destructor_fn) ( void **item);.
-
.duplicator_fn ⇒ Object
Create a new callback of the following type: Duplicate an item typedef void * (zlistx_duplicator_fn) ( const void *item);.
-
.handle_item(handle) ⇒ ::FFI::Pointer
Returns the item associated with the given list handle, or NULL if passed in handle is NULL.
-
.new ⇒ CZMQ::Zlistx
Create a new, empty list.
-
.test(verbose) ⇒ void
Self test of this class.
-
.unpack(frame) ⇒ CZMQ::Zlistx
Unpack binary frame into a new list.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#add_end(item) ⇒ ::FFI::Pointer
Add an item to the tail of the list.
-
#add_start(item) ⇒ ::FFI::Pointer
Add an item to the head of the list.
-
#cursor ⇒ ::FFI::Pointer
Returns the handle of the item at the cursor, or NULL if the cursor is not pointing to an item.
-
#delete(handle) ⇒ Integer
Delete an item, using its handle.
-
#destroy ⇒ void
Destroy a list.
-
#detach(handle) ⇒ ::FFI::Pointer
Detach an item from the list, using its handle.
-
#detach_cur ⇒ ::FFI::Pointer
Detach item at the cursor, if any, from the list.
-
#dup ⇒ Zlistx
Make a copy of the list; items are duplicated if you set a duplicator for the list, otherwise not.
-
#find(item) ⇒ ::FFI::Pointer
Find an item in the list, searching from the start.
-
#first ⇒ ::FFI::Pointer
Return the item at the head of list.
-
#head ⇒ ::FFI::Pointer
Return first item in the list, or null, leaves the cursor.
-
#initialize(ptr, finalize = true) ⇒ Zlistx
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#insert(item, low_value) ⇒ ::FFI::Pointer
Create a new node and insert it into a sorted list.
-
#item ⇒ ::FFI::Pointer
Returns the value of the item at the cursor, or NULL if the cursor is not pointing to an item.
-
#last ⇒ ::FFI::Pointer
Return the item at the tail of list.
-
#move_end(handle) ⇒ void
Move an item to the end of the list, via its handle.
-
#move_start(handle) ⇒ void
Move an item to the start of the list, via its handle.
-
#next ⇒ ::FFI::Pointer
Return the next item.
- #null? ⇒ Boolean
-
#pack ⇒ Zframe
Serialize list to a binary frame that can be sent in a message.
-
#prev ⇒ ::FFI::Pointer
Return the previous item.
-
#purge ⇒ void
Remove all items from the list, and destroy them if the item destructor is set.
-
#reorder(handle, low_value) ⇒ void
Move an item, specified by handle, into position in a sorted list.
-
#set_comparator(comparator) ⇒ void
Set a user-defined comparator for zlistx_find and zlistx_sort; the method must return -1, 0, or 1 depending on whether item1 is less than, equal to, or greater than, item2.
-
#set_destructor(destructor) ⇒ void
Set a user-defined deallocator for list items; by default items are not freed when the list is destroyed.
-
#set_duplicator(duplicator) ⇒ void
Set a user-defined duplicator for list items; by default items are not copied when the list is duplicated.
-
#size ⇒ Integer
Return the number of items in the list.
-
#sort ⇒ void
Sort the list.
-
#tail ⇒ ::FFI::Pointer
Return last item in the list, or null, leaves the cursor.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zlistx
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
24 25 26 27 28 29 30 31 32 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 18 alias :__new :new |
.comparator_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Compare two items, for sorting
typedef int (zlistx_comparator_fn) (
const void *item1, const void *item2);
118 119 120 121 122 123 124 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 118 def self.comparator_fn ::FFI::Function.new :int, [:pointer, :pointer], blocking: true do |item1, item2| result = yield item1, item2 result = Integer(result) result end end |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 35 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zlistx_destroy ptr_ptr end end |
.destructor_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Destroy an item
typedef void (zlistx_destructor_fn) (
void **item);
86 87 88 89 90 91 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 86 def self.destructor_fn ::FFI::Function.new :void, [:pointer], blocking: true do |item| result = yield item result end end |
.duplicator_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Duplicate an item
typedef void * (zlistx_duplicator_fn) (
const void *item);
102 103 104 105 106 107 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 102 def self.duplicator_fn ::FFI::Function.new :pointer, [:pointer], blocking: true do |item| result = yield item result end end |
.handle_item(handle) ⇒ ::FFI::Pointer
Returns the item associated with the given list handle, or NULL if passed in handle is NULL. Asserts that the passed in handle points to a list element.
284 285 286 287 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 284 def self.handle_item(handle) result = ::CZMQ::FFI.zlistx_handle_item(handle) result end |
.new ⇒ CZMQ::Zlistx
Create a new, empty list.
128 129 130 131 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 128 def self.new() ptr = ::CZMQ::FFI.zlistx_new() __new ptr end |
.test(verbose) ⇒ void
This method returns an undefined value.
Self test of this class.
499 500 501 502 503 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 499 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zlistx_test(verbose) result end |
.unpack(frame) ⇒ CZMQ::Zlistx
Unpack binary frame into a new list. Packed data must follow format defined by zlistx_pack. List is set to autofree. An empty frame unpacks to an empty list.
138 139 140 141 142 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 138 def self.unpack(frame) frame = frame.__ptr if frame ptr = ::CZMQ::FFI.zlistx_unpack(frame) __new ptr end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
49 50 51 52 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 49 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
60 61 62 63 64 65 66 67 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 60 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
72 73 74 75 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#add_end(item) ⇒ ::FFI::Pointer
Add an item to the tail of the list. Calls the item duplicator, if any, on the item. Resets cursor to list head. Returns an item handle on success.
174 175 176 177 178 179 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 174 def add_end(item) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_add_end(self_p, item) result end |
#add_start(item) ⇒ ::FFI::Pointer
Add an item to the head of the list. Calls the item duplicator, if any, on the item. Resets cursor to list head. Returns an item handle on success.
161 162 163 164 165 166 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 161 def add_start(item) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_add_start(self_p, item) result end |
#cursor ⇒ ::FFI::Pointer
Returns the handle of the item at the cursor, or NULL if the cursor is not pointing to an item.
272 273 274 275 276 277 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 272 def cursor() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_cursor(self_p) result end |
#delete(handle) ⇒ Integer
Delete an item, using its handle. Calls the item destructor if any is set. If handle is null, deletes the first item on the list. Returns 0 if an item was deleted, -1 if not. If cursor was at item, moves cursor to previous item, so you can delete items while iterating forwards through a list.
338 339 340 341 342 343 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 338 def delete(handle) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_delete(self_p, handle) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a list. If an item destructor was specified, all items in the list are automatically destroyed as well.
148 149 150 151 152 153 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 148 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zlistx_destroy(self_p) result end |
#detach(handle) ⇒ ::FFI::Pointer
Detach an item from the list, using its handle. The item is not modified, and the caller is responsible for destroying it if necessary. If handle is null, detaches the first item on the list. Returns item that was detached, or null if none was. If cursor was at item, moves cursor to previous item, so you can detach items while iterating forwards through a list.
310 311 312 313 314 315 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 310 def detach(handle) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_detach(self_p, handle) result end |
#detach_cur ⇒ ::FFI::Pointer
Detach item at the cursor, if any, from the list. The item is not modified, and the caller is responsible for destroying it as necessary. Returns item that was detached, or null if none was. Moves cursor to previous item, so you can detach items while iterating forwards through a list.
323 324 325 326 327 328 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 323 def detach_cur() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_detach_cur(self_p) result end |
#dup ⇒ Zlistx
Make a copy of the list; items are duplicated if you set a duplicator for the list, otherwise not. Copying a null reference returns a null reference.
428 429 430 431 432 433 434 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 428 def dup() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_dup(self_p) result = Zlistx.__new result, false result end |
#find(item) ⇒ ::FFI::Pointer
Find an item in the list, searching from the start. Uses the item comparator, if any, else compares item values directly. Returns the item handle found, or NULL. Sets the cursor to the found item, if any.
295 296 297 298 299 300 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 295 def find(item) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_find(self_p, item) result end |
#first ⇒ ::FFI::Pointer
Return the item at the head of list. If the list is empty, returns NULL. Leaves cursor pointing at the head item, or NULL if the list is empty.
215 216 217 218 219 220 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 215 def first() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_first(self_p) result end |
#head ⇒ ::FFI::Pointer
Return first item in the list, or null, leaves the cursor
194 195 196 197 198 199 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 194 def head() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_head(self_p) result end |
#insert(item, low_value) ⇒ ::FFI::Pointer
Create a new node and insert it into a sorted list. Calls the item duplicator, if any, on the item. If low_value is true, starts searching from the start of the list, otherwise searches from the end. Use the item comparator, if any, to find where to place the new node. Returns a handle to the new node. Resets the cursor to the list head.
399 400 401 402 403 404 405 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 399 def insert(item, low_value) raise DestroyedError unless @ptr self_p = @ptr low_value = !(0==low_value||!low_value) # boolean result = ::CZMQ::FFI.zlistx_insert(self_p, item, low_value) result end |
#item ⇒ ::FFI::Pointer
Returns the value of the item at the cursor, or NULL if the cursor is not pointing to an item.
261 262 263 264 265 266 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 261 def item() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_item(self_p) result end |
#last ⇒ ::FFI::Pointer
Return the item at the tail of list. If the list is empty, returns NULL. Leaves cursor pointing at the tail item, or NULL if the list is empty.
250 251 252 253 254 255 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 250 def last() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_last(self_p) result end |
#move_end(handle) ⇒ void
This method returns an undefined value.
Move an item to the end of the list, via its handle.
360 361 362 363 364 365 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 360 def move_end(handle) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_move_end(self_p, handle) result end |
#move_start(handle) ⇒ void
This method returns an undefined value.
Move an item to the start of the list, via its handle.
349 350 351 352 353 354 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 349 def move_start(handle) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_move_start(self_p, handle) result end |
#next ⇒ ::FFI::Pointer
Return the next item. At the end of the list (or in an empty list), returns NULL. Use repeated zlistx_next () calls to work through the list from zlistx_first (). First time, acts as zlistx_first().
227 228 229 230 231 232 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 227 def next() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_next(self_p) result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 44 def null? !@ptr or @ptr.null? end |
#pack ⇒ Zframe
Serialize list to a binary frame that can be sent in a message. The packed format is compatible with the ‘strings’ type implemented by zproto:
; A list of strings
list = list-count *longstr
list-count = number-4
; Strings are always length + text contents
longstr = number-4 *VCHAR
; Numbers are unsigned integers in network byte order
number-4 = 4OCTET
487 488 489 490 491 492 493 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 487 def pack() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_pack(self_p) result = Zframe.__new result, true result end |
#prev ⇒ ::FFI::Pointer
Return the previous item. At the start of the list (or in an empty list), returns NULL. Use repeated zlistx_prev () calls to work through the list backwards from zlistx_last (). First time, acts as zlistx_last().
239 240 241 242 243 244 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 239 def prev() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_prev(self_p) result end |
#purge ⇒ void
This method returns an undefined value.
Remove all items from the list, and destroy them if the item destructor is set.
371 372 373 374 375 376 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 371 def purge() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_purge(self_p) result end |
#reorder(handle, low_value) ⇒ void
This method returns an undefined value.
Move an item, specified by handle, into position in a sorted list. Uses the item comparator, if any, to determine the new location. If low_value is true, starts searching from the start of the list, otherwise searches from the end.
415 416 417 418 419 420 421 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 415 def reorder(handle, low_value) raise DestroyedError unless @ptr self_p = @ptr low_value = !(0==low_value||!low_value) # boolean result = ::CZMQ::FFI.zlistx_reorder(self_p, handle, low_value) result end |
#set_comparator(comparator) ⇒ void
This method returns an undefined value.
Set a user-defined comparator for zlistx_find and zlistx_sort; the method must return -1, 0, or 1 depending on whether item1 is less than, equal to, or greater than, item2.
466 467 468 469 470 471 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 466 def set_comparator(comparator) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_set_comparator(self_p, comparator) result end |
#set_destructor(destructor) ⇒ void
This method returns an undefined value.
Set a user-defined deallocator for list items; by default items are not freed when the list is destroyed.
441 442 443 444 445 446 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 441 def set_destructor(destructor) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_set_destructor(self_p, destructor) result end |
#set_duplicator(duplicator) ⇒ void
This method returns an undefined value.
Set a user-defined duplicator for list items; by default items are not copied when the list is duplicated.
453 454 455 456 457 458 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 453 def set_duplicator(duplicator) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_set_duplicator(self_p, duplicator) result end |
#size ⇒ Integer
Return the number of items in the list
184 185 186 187 188 189 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 184 def size() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_size(self_p) result end |
#sort ⇒ void
This method returns an undefined value.
Sort the list. If an item comparator was set, calls that to compare items, otherwise compares on item value. The sort is not stable, so may reorder equal items.
383 384 385 386 387 388 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 383 def sort() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_sort(self_p) result end |
#tail ⇒ ::FFI::Pointer
Return last item in the list, or null, leaves the cursor
204 205 206 207 208 209 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 204 def tail() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zlistx_tail(self_p) result end |