Class: CZMQ::FFI::Ztrie
- Inherits:
-
Object
- Object
- CZMQ::FFI::Ztrie
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/ztrie.rb
Overview
This class is 100% generated using zproject.
simple trie for tokenizable strings
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.destroy_data_fn ⇒ Object
Create a new callback of the following type: Callback function for ztrie_node to destroy node data.
-
.new(delimiter) ⇒ CZMQ::Ztrie
Creates a new ztrie.
-
.test(verbose) ⇒ void
Self test of this class.
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.
-
#destroy ⇒ void
Destroy the ztrie.
-
#hit_asterisk_match ⇒ String
Returns the asterisk matched part of a route, if there has been no match or no asterisk match, returns NULL.
-
#hit_data ⇒ ::FFI::Pointer
Returns the data of a matched route from last ztrie_matches.
-
#hit_parameter_count ⇒ Integer
Returns the count of parameters that a matched route has.
-
#hit_parameters ⇒ Zhashx
Returns the parameters of a matched route with named regexes from last ztrie_matches.
-
#initialize(ptr, finalize = true) ⇒ Ztrie
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#insert_route(path, data, destroy_data_fn) ⇒ Integer
Inserts a new route into the tree and attaches the data.
-
#matches(path) ⇒ Boolean
Returns true if the path matches a route in the tree, otherwise false.
- #null? ⇒ Boolean
-
#print ⇒ void
Print the trie.
-
#remove_route(path) ⇒ Integer
Removes a route from the trie and destroys its data.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Ztrie
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/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 |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.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.ztrie_destroy ptr_ptr end end |
.destroy_data_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: Callback function for ztrie_node to destroy node data.
typedef void (ztrie_destroy_data_fn) (
void **data);
86 87 88 89 90 91 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 86 def self.destroy_data_fn ::FFI::Function.new :void, [:pointer], blocking: true do |data| result = yield data result end 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/ztrie.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/ztrie.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/ztrie.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#destroy ⇒ void
This method returns an undefined value.
Destroy the ztrie.
104 105 106 107 108 109 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 104 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.ztrie_destroy(self_p) result end |
#hit_asterisk_match ⇒ String
Returns the asterisk matched part of a route, if there has been no match or no asterisk match, returns NULL.
189 190 191 192 193 194 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 189 def hit_asterisk_match() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_asterisk_match(self_p) result end |
#hit_data ⇒ ::FFI::Pointer
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.
155 156 157 158 159 160 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 155 def hit_data() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_data(self_p) result end |
#hit_parameter_count ⇒ Integer
Returns the count of parameters that a matched route has.
165 166 167 168 169 170 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 165 def hit_parameter_count() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_hit_parameter_count(self_p) result end |
#hit_parameters ⇒ Zhashx
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.
177 178 179 180 181 182 183 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 177 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 |
#insert_route(path, data, destroy_data_fn) ⇒ Integer
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.
119 120 121 122 123 124 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 119 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 |
#matches(path) ⇒ Boolean
Returns true if the path matches a route in the tree, otherwise false.
143 144 145 146 147 148 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 143 def matches(path) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_matches(self_p, path) result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 44 def null? !@ptr or @ptr.null? end |
#print ⇒ void
This method returns an undefined value.
Print the trie
199 200 201 202 203 204 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 199 def print() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_print(self_p) result end |
#remove_route(path) ⇒ Integer
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.
132 133 134 135 136 137 |
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 132 def remove_route(path) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztrie_remove_route(self_p, path) result end |