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.
-
#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
355 356 357 358 359 360 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 355 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 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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.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);
85 86 87 88 89 90 91 92 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 85 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.
109 110 111 112 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 109 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.
119 120 121 122 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 119 def self.loadf(format, *args) ptr = ::CZMQ::FFI.zconfig_loadf(format, *args) __new ptr end |
.new(name, parent) ⇒ CZMQ::Zconfig
Create new config item
98 99 100 101 102 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 98 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).
345 346 347 348 349 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 345 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)
419 420 421 422 423 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 419 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
48 49 50 51 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 48 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.
59 60 61 62 63 64 65 66 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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_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.
71 72 73 74 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 71 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#at_depth(level) ⇒ Zconfig
Locate the last config item at a specified depth
257 258 259 260 261 262 263 264 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 257 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
222 223 224 225 226 227 228 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 222 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
365 366 367 368 369 370 371 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 365 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.
296 297 298 299 300 301 302 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 296 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
127 128 129 130 131 132 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 127 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zconfig_destroy(self_p) result end |
#execute(handler, arg) ⇒ Integer
Execute a callback for each config item in the tree; returns zero if successful, else -1.
272 273 274 275 276 277 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 272 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
332 333 334 335 336 337 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 332 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
429 430 431 432 433 434 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 429 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.
186 187 188 189 190 191 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 186 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.
398 399 400 401 402 403 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 398 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.
245 246 247 248 249 250 251 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 245 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
137 138 139 140 141 142 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 137 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
233 234 235 236 237 238 239 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 233 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
43 44 45 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 43 def null? !@ptr or @ptr.null? end |
#print ⇒ void
This method returns an undefined value.
Print properties of object
439 440 441 442 443 444 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 439 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
159 160 161 162 163 164 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 159 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.
173 174 175 176 177 178 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 173 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)
408 409 410 411 412 413 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 408 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.
309 310 311 312 313 314 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 309 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.
322 323 324 325 326 327 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 322 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.
286 287 288 289 290 291 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 286 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
197 198 199 200 201 202 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 197 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.
212 213 214 215 216 217 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 212 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
386 387 388 389 390 391 392 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 386 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
147 148 149 150 151 152 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 147 def value() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zconfig_value(self_p) result end |