Class: CZMQ::FFI::Ztrie

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

Overview

Note:

This class is 100% generated using zproject.

simple trie for tokenizable strings

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Ztrie

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/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

.__newObject



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

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (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_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: 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

.new(delimiter) ⇒ CZMQ::Ztrie

Creates a new ztrie.

Parameters:

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

Returns:

  • (CZMQ::Ztrie)


96
97
98
99
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 96

def self.new(delimiter)
  ptr = ::CZMQ::FFI.ztrie_new(delimiter)
  __new ptr
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


210
211
212
213
214
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 210

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

Instance Method Details

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

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



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

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:



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



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

#destroyvoid

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_matchString

Returns the asterisk matched part of a route, if there has been no match or no asterisk match, returns NULL.

Returns:

  • (String)

Raises:



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.

Returns:

  • (::FFI::Pointer)

Raises:



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_countInteger

Returns the count of parameters that a matched route has.

Returns:

  • (Integer)

Raises:



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_parametersZhashx

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.

Returns:

Raises:



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.

Parameters:

  • path (String, #to_s, nil)
  • data (::FFI::Pointer, #to_ptr)
  • destroy_data_fn (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



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.

Parameters:

  • path (String, #to_s, nil)

Returns:

  • (Boolean)

Raises:



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

Returns:

  • (Boolean)


44
45
46
# File 'lib/czmq-ffi-gen/czmq/ffi/ztrie.rb', line 44

def null?
  !@ptr or @ptr.null?
end

This method returns an undefined value.

Print the trie

Raises:



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.

Parameters:

  • path (String, #to_s, nil)

Returns:

  • (Integer)

Raises:



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