class CZMQ::FFI::Ztrie
simple trie for tokenizable strings @note This class is 100% generated using zproject.
Public Class Methods
@param ptr [::FFI::Pointer] @return [Proc]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.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.ztrie_destroy ptr_ptr end end
Create a new callback of the following type: Callback function for ztrie_node to destroy node data.
typedef void (ztrie_destroy_data_fn) ( void **data);
@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.
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 85 def self.destroy_data_fn ::FFI::Function.new :void, [:pointer], blocking: true do |data| result = yield data result end end
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.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
Creates a new ztrie. @param delimiter [::FFI::Pointer, to_ptr
] @return [CZMQ::Ztrie]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 95 def self.new(delimiter) ptr = ::CZMQ::FFI.ztrie_new(delimiter) __new ptr end
Self test of this class.
@param verbose [Boolean] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 209 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.ztrie_test(verbose) result end
Public Instance Methods
Return internal pointer @return [::FFI::Pointer]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 48 def __ptr raise DestroyedError unless @ptr @ptr end
Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object
and thus makes it unusable.
@return [::FFI::MemoryPointer] the pointer pointing to a pointer
pointing to the native object
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.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
Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native
object will be freed by other means.
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 71 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end
Destroy the ztrie.
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 103 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.ztrie_destroy(self_p) result end
Returns the asterisk matched part of a route, if there has been no match or no asterisk match, returns NULL.
@return [String]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 188 def hit_asterisk_match() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_asterisk_match(self_p) result end
Returns the data of a matched route from last ztrie_matches. If the path did not match, returns NULL. Do not delete the data as it's owned by ztrie.
@return [::FFI::Pointer]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 154 def hit_data() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_data(self_p) result end
Returns the count of parameters that a matched route has.
@return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 164 def hit_parameter_count() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_parameter_count(self_p) result end
Returns the parameters of a matched route with named regexes from last ztrie_matches. If the path did not match or the route did not contain any named regexes, returns NULL.
@return [Zhashx]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 176 def hit_parameters() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_parameters(self_p) result = Zhashx.__new result, false result end
Inserts a new route into the tree and attaches the data. Returns -1 if the route already exists, otherwise 0. This method takes ownership of the provided data if a destroy_data_fn
is provided.
@param path [String, to_s, nil] @param data [::FFI::Pointer, to_ptr
] @param destroy_data_fn
[::FFI::Pointer, to_ptr
] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 118 def insert_route(path, data, destroy_data_fn) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_insert_route(self_p, path, data, destroy_data_fn) result end
Returns true if the path matches a route in the tree, otherwise false.
@param path [String, to_s, nil] @return [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 142 def matches(path) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_matches(self_p, path) result end
@return [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 43 def null? !@ptr or @ptr.null? end
Print the trie
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 198 def print() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_print(self_p) result end
Removes a route from the trie and destroys its data. Returns -1 if the route does not exists, otherwise 0. the start of the list call zlist_first (). Advances the cursor.
@param path [String, to_s, nil] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztrie.rb, line 131 def remove_route(path) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_remove_route(self_p, path) result end