Class: CZMQ::FFI::Zconfig
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zconfig
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zconfig.rb
Overview
This class is 100% generated using zproject.
work with config files written in rfc.zeromq.org/spec:4/ZPL.
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
-
.chunk_load(chunk) ⇒ Zconfig
Load a config tree from a memory chunk.
- .create_finalizer_for(ptr) ⇒ Proc
-
.fct ⇒ Object
Create a new callback of the following type:.
-
.load(filename) ⇒ CZMQ::Zconfig
Load a config tree from a specified ZPL text file; returns a zconfig_t reference for the root, if the file exists and is readable.
-
.loadf(format, *args) ⇒ CZMQ::Zconfig
Equivalent to zconfig_load, taking a format string instead of a fixed filename.
-
.new(name, parent) ⇒ CZMQ::Zconfig
Create new config item.
-
.reload(self_p) ⇒ Integer
Reload config tree from same file that it was previously loaded from.
-
.remove(self_p) ⇒ void
Destroy node and subtree (all children).
-
.str_load(string) ⇒ Zconfig
Load a config tree from a null-terminated string.
-
.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.
-
#at_depth(level) ⇒ Zconfig
Locate the last config item at a specified depth.
-
#child ⇒ Zconfig
Find our first child, if any.
-
#chunk_save ⇒ Zchunk
Save a config tree to a new memory chunk.
-
#comments ⇒ Zlist
Return comments of config item, as zlist.
-
#destroy ⇒ void
Destroy a config item and all its children.
-
#dup ⇒ Zconfig
Create copy of zconfig, caller MUST free the value Create copy of config, as new zconfig object.
-
#execute(handler, arg) ⇒ Integer
Execute a callback for each config item in the tree; returns zero if successful, else -1.
-
#filename ⇒ String
Report filename used during zconfig_load, or NULL if none.
-
#fprint(file) ⇒ void
Print the config file to open stream.
-
#get(path, default_value) ⇒ ::FFI::Pointer
Get value for config item into a string value; leading slash is optional and ignored.
-
#has_changed ⇒ Boolean
Return true if a configuration tree was loaded from a file and that file has changed in since the tree was loaded.
-
#initialize(ptr, finalize = true) ⇒ Zconfig
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#locate(path) ⇒ Zconfig
Find a config item along a path; leading slash is optional and ignored.
-
#name ⇒ ::FFI::Pointer
Return name of config item.
-
#next ⇒ Zconfig
Find our first sibling, if any.
- #null? ⇒ Boolean
-
#print ⇒ void
Print properties of object.
-
#put(path, value) ⇒ void
Insert or update configuration key with value.
-
#putf(path, format, *args) ⇒ void
Equivalent to zconfig_put, accepting a format specifier and variable argument list, instead of a single string value.
-
#remove_subtree ⇒ void
Destroy subtree (all children).
-
#save(filename) ⇒ Integer
Save a config tree to a specified ZPL text file, where a filename “-” means dump to standard output.
-
#savef(format, *args) ⇒ Integer
Equivalent to zconfig_save, taking a format string instead of a fixed filename.
-
#set_comment(format, *args) ⇒ void
Add comment to config item before saving to disk.
-
#set_name(name) ⇒ void
Set config item name, name may be NULL.
-
#set_value(format, *args) ⇒ void
Set new value for config item.
-
#str_save ⇒ ::FFI::AutoPointer
Save a config tree to a new null terminated string.
-
#value ⇒ ::FFI::Pointer
Return value of config item.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zconfig
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/zconfig.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/zconfig.rb', line 18 alias :__new :new |
.chunk_load(chunk) ⇒ Zconfig
Load a config tree from a memory chunk
369 370 371 372 373 374 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 369 def self.chunk_load(chunk) chunk = chunk.__ptr if chunk result = ::CZMQ::FFI.zconfig_chunk_load(chunk) result = Zconfig.__new result, false result end |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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.zconfig_destroy ptr_ptr end end |
.fct ⇒ 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:
typedef int (zconfig_fct) (
zconfig_t *self, void *arg, int level);
86 87 88 89 90 91 92 93 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 86 def self.fct ::FFI::Function.new :int, [:pointer, :pointer, :int], blocking: true do |self_, arg, level| self_ = Zconfig.__new self_, false result = yield self_, arg, level result = Integer(result) result end end |
.load(filename) ⇒ CZMQ::Zconfig
Load a config tree from a specified ZPL text file; returns a zconfig_t reference for the root, if the file exists and is readable. Returns NULL if the file does not exist.
110 111 112 113 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 110 def self.load(filename) ptr = ::CZMQ::FFI.zconfig_load(filename) __new ptr end |
.loadf(format, *args) ⇒ CZMQ::Zconfig
Equivalent to zconfig_load, taking a format string instead of a fixed filename.
120 121 122 123 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 120 def self.loadf(format, *args) ptr = ::CZMQ::FFI.zconfig_loadf(format, *args) __new ptr end |
.new(name, parent) ⇒ CZMQ::Zconfig
Create new config item
99 100 101 102 103 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 99 def self.new(name, parent) parent = parent.__ptr if parent ptr = ::CZMQ::FFI.zconfig_new(name, parent) __new ptr end |
.reload(self_p) ⇒ Integer
Reload config tree from same file that it was previously loaded from. Returns 0 if OK, -1 if there was an error (and then does not change existing data).
359 360 361 362 363 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 359 def self.reload(self_p) self_p = self_p.__ptr_give_ref result = ::CZMQ::FFI.zconfig_reload(self_p) result end |
.remove(self_p) ⇒ void
This method returns an undefined value.
Destroy node and subtree (all children)
433 434 435 436 437 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 433 def self.remove(self_p) self_p = self_p.__ptr_give_ref result = ::CZMQ::FFI.zconfig_remove(self_p) result 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/zconfig.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/zconfig.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/zconfig.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#at_depth(level) ⇒ Zconfig
Locate the last config item at a specified depth
271 272 273 274 275 276 277 278 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 271 def at_depth(level) raise DestroyedError unless @ptr self_p = @ptr level = Integer(level) result = ::CZMQ::FFI.zconfig_at_depth(self_p, level) result = Zconfig.__new result, false result end |
#child ⇒ Zconfig
Find our first child, if any
236 237 238 239 240 241 242 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 236 def child() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_child(self_p) result = Zconfig.__new result, false result end |
#chunk_save ⇒ Zchunk
Save a config tree to a new memory chunk
379 380 381 382 383 384 385 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 379 def chunk_save() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_chunk_save(self_p) result = Zchunk.__new result, false result end |
#comments ⇒ Zlist
Return comments of config item, as zlist.
310 311 312 313 314 315 316 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 310 def comments() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_comments(self_p) result = Zlist.__new result, false result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a config item and all its children
128 129 130 131 132 133 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 128 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zconfig_destroy(self_p) result end |
#dup ⇒ Zconfig
Create copy of zconfig, caller MUST free the value Create copy of config, as new zconfig object. Returns a fresh zconfig_t object. If config is null, or memory was exhausted, returns null.
140 141 142 143 144 145 146 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 140 def dup() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_dup(self_p) result = Zconfig.__new result, true result end |
#execute(handler, arg) ⇒ Integer
Execute a callback for each config item in the tree; returns zero if successful, else -1.
286 287 288 289 290 291 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 286 def execute(handler, arg) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_execute(self_p, handler, arg) result end |
#filename ⇒ String
Report filename used during zconfig_load, or NULL if none
346 347 348 349 350 351 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 346 def filename() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_filename(self_p) result end |
#fprint(file) ⇒ void
This method returns an undefined value.
Print the config file to open stream
443 444 445 446 447 448 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 443 def fprint(file) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_fprint(self_p, file) result end |
#get(path, default_value) ⇒ ::FFI::Pointer
Get value for config item into a string value; leading slash is optional and ignored.
200 201 202 203 204 205 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 200 def get(path, default_value) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_get(self_p, path, default_value) result end |
#has_changed ⇒ Boolean
Return true if a configuration tree was loaded from a file and that file has changed in since the tree was loaded.
412 413 414 415 416 417 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 412 def has_changed() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_has_changed(self_p) result end |
#locate(path) ⇒ Zconfig
Find a config item along a path; leading slash is optional and ignored.
259 260 261 262 263 264 265 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 259 def locate(path) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_locate(self_p, path) result = Zconfig.__new result, false result end |
#name ⇒ ::FFI::Pointer
Return name of config item
151 152 153 154 155 156 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 151 def name() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_name(self_p) result end |
#next ⇒ Zconfig
Find our first sibling, if any
247 248 249 250 251 252 253 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 247 def next() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_next(self_p) result = Zconfig.__new result, false result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 44 def null? !@ptr or @ptr.null? end |
#print ⇒ void
This method returns an undefined value.
Print properties of object
453 454 455 456 457 458 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 453 def print() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_print(self_p) result end |
#put(path, value) ⇒ void
This method returns an undefined value.
Insert or update configuration key with value
173 174 175 176 177 178 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 173 def put(path, value) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_put(self_p, path, value) result end |
#putf(path, format, *args) ⇒ void
This method returns an undefined value.
Equivalent to zconfig_put, accepting a format specifier and variable argument list, instead of a single string value.
187 188 189 190 191 192 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 187 def putf(path, format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_putf(self_p, path, format, *args) result end |
#remove_subtree ⇒ void
This method returns an undefined value.
Destroy subtree (all children)
422 423 424 425 426 427 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 422 def remove_subtree() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_remove_subtree(self_p) result end |
#save(filename) ⇒ Integer
Save a config tree to a specified ZPL text file, where a filename “-” means dump to standard output.
323 324 325 326 327 328 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 323 def save(filename) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_save(self_p, filename) result end |
#savef(format, *args) ⇒ Integer
Equivalent to zconfig_save, taking a format string instead of a fixed filename.
336 337 338 339 340 341 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 336 def savef(format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_savef(self_p, format, *args) result end |
#set_comment(format, *args) ⇒ void
This method returns an undefined value.
Add comment to config item before saving to disk. You can add as many comment lines as you like. If you use a null format, all comments are deleted.
300 301 302 303 304 305 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 300 def set_comment(format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_set_comment(self_p, format, *args) result end |
#set_name(name) ⇒ void
This method returns an undefined value.
Set config item name, name may be NULL
211 212 213 214 215 216 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 211 def set_name(name) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_set_name(self_p, name) result end |
#set_value(format, *args) ⇒ void
This method returns an undefined value.
Set new value for config item. The new value may be a string, a printf format, or NULL. Note that if string may possibly contain ‘%’, or if it comes from an insecure source, you must use ‘%s’ as the format, followed by the string.
226 227 228 229 230 231 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 226 def set_value(format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_set_value(self_p, format, *args) result end |
#str_save ⇒ ::FFI::AutoPointer
Save a config tree to a new null terminated string
400 401 402 403 404 405 406 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 400 def str_save() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_str_save(self_p) result = ::FFI::AutoPointer.new(result, LibC.method(:free)) result end |
#value ⇒ ::FFI::Pointer
Return value of config item
161 162 163 164 165 166 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 161 def value() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_value(self_p) result end |