Class: CZMQ::FFI::Zlistx

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/zlistx.rb

Overview

Note:

This class is 100% generated using zproject.

extended generic list container

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zlistx

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


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

.__newObject



18
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 18

alias :__new :new

.comparator_fnObject

Note:

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);


117
118
119
120
121
122
123
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 117

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

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


35
36
37
38
39
40
41
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 35

def self.create_finalizer_for(ptr)
  Proc.new do
    ptr_ptr = ::FFI::MemoryPointer.new :pointer
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.zlistx_destroy ptr_ptr
  end
end

.destructor_fnObject

Note:

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);


85
86
87
88
89
90
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 85

def self.destructor_fn
  ::FFI::Function.new :void, [:pointer], blocking: true do |item|
    result = yield item
    result
  end
end

.duplicator_fnObject

Note:

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);


101
102
103
104
105
106
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 101

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.

Parameters:

  • handle (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)


272
273
274
275
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 272

def self.handle_item(handle)
  result = ::CZMQ::FFI.zlistx_handle_item(handle)
  result
end

.newCZMQ::Zlistx

Create a new, empty list.

Returns:

  • (CZMQ::Zlistx)


127
128
129
130
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 127

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.

Parameters:

  • verbose (Boolean)


466
467
468
469
470
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 466

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zlistx_test(verbose)
  result
end

Instance Method Details

#__ptr::FFI::Pointer Also known as: to_ptr

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



48
49
50
51
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 48

def __ptr
  raise DestroyedError unless @ptr
  @ptr
end

#__ptr_give_ref::FFI::MemoryPointer

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



59
60
61
62
63
64
65
66
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 59

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_finalizervoid

Note:

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.



71
72
73
74
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 71

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, NULL if memory was exhausted.

Parameters:

  • item (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



162
163
164
165
166
167
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 162

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, NULL if memory was exhausted.

Parameters:

  • item (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



149
150
151
152
153
154
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 149

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.

Returns:

  • (::FFI::Pointer)

Raises:



260
261
262
263
264
265
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 260

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 is 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.

Parameters:

  • handle (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



326
327
328
329
330
331
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 326

def delete(handle)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_delete(self_p, handle)
  result
end

#destroyvoid

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.



136
137
138
139
140
141
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 136

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.

Parameters:

  • handle (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



298
299
300
301
302
303
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 298

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.

Returns:

  • (::FFI::Pointer)

Raises:



311
312
313
314
315
316
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 311

def detach_cur()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_detach_cur(self_p)
  result
end

#dupZlistx

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.

Returns:

Raises:



417
418
419
420
421
422
423
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 417

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.

Parameters:

  • item (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



283
284
285
286
287
288
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 283

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.

Returns:

  • (::FFI::Pointer)

Raises:



203
204
205
206
207
208
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 203

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

Returns:

  • (::FFI::Pointer)

Raises:



182
183
184
185
186
187
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 182

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, or NULL if memory was exhausted. Resets the cursor to the list head.

Parameters:

  • item (::FFI::Pointer, #to_ptr)
  • low_value (Boolean)

Returns:

  • (::FFI::Pointer)

Raises:



388
389
390
391
392
393
394
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 388

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.

Returns:

  • (::FFI::Pointer)

Raises:



249
250
251
252
253
254
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 249

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.

Returns:

  • (::FFI::Pointer)

Raises:



238
239
240
241
242
243
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 238

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.

Parameters:

  • handle (::FFI::Pointer, #to_ptr)

Raises:



348
349
350
351
352
353
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 348

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.

Parameters:

  • handle (::FFI::Pointer, #to_ptr)

Raises:



337
338
339
340
341
342
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 337

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().

Returns:

  • (::FFI::Pointer)

Raises:



215
216
217
218
219
220
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 215

def next()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_next(self_p)
  result
end

#null?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 43

def null?
  !@ptr or @ptr.null?
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().

Returns:

  • (::FFI::Pointer)

Raises:



227
228
229
230
231
232
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 227

def prev()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_prev(self_p)
  result
end

#purgevoid

This method returns an undefined value.

Remove all items from the list, and destroy them if the item destructor is set.

Raises:



359
360
361
362
363
364
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 359

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.

Parameters:

  • handle (::FFI::Pointer, #to_ptr)
  • low_value (Boolean)

Raises:



404
405
406
407
408
409
410
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 404

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.

Parameters:

  • comparator (::FFI::Pointer, #to_ptr)

Raises:



455
456
457
458
459
460
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 455

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.

Parameters:

  • destructor (::FFI::Pointer, #to_ptr)

Raises:



430
431
432
433
434
435
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 430

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.

Parameters:

  • duplicator (::FFI::Pointer, #to_ptr)

Raises:



442
443
444
445
446
447
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 442

def set_duplicator(duplicator)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_set_duplicator(self_p, duplicator)
  result
end

#sizeInteger

Return the number of items in the list

Returns:

  • (Integer)

Raises:



172
173
174
175
176
177
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 172

def size()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_size(self_p)
  result
end

#sortvoid

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.

Raises:



371
372
373
374
375
376
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 371

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

Returns:

  • (::FFI::Pointer)

Raises:



192
193
194
195
196
197
# File 'lib/czmq-ffi-gen/czmq/ffi/zlistx.rb', line 192

def tail()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zlistx_tail(self_p)
  result
end