Class: CZMQ::FFI::Zargs
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zargs
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zargs.rb
Overview
This class is 100% generated using zproject.
Platform independent command line argument parsing helpers
There are two kind of elements provided by this class foo –named-parameter –parameter with_value positional arguments -a gain-parameter zargs keeps poision only for arguments, parameters are to be accessed like hash.
It DOES:
-
provide easy to use CLASS compatible API for accessing argv
-
is platform independent
-
provide getopt_long style – argument, which delimits parameters from arguments
-
makes parameters positon independent
It does NOT
-
change argv
-
provide a “declarative” way to define command line interface
In future it SHALL
-
hide several formats of command line to one (-Idir, –include=dir, –include dir are the same from API pov)
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.new(argc, argv) ⇒ CZMQ::Zargs
Create a new zargs from command line arguments.
-
.param_empty(arg) ⇒ Boolean
Returns true if parameter did not have a value.
-
.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.
-
#arguments ⇒ Integer
Return number of positional arguments.
-
#destroy ⇒ void
Destroy zargs instance.
-
#first ⇒ String
Return first positional argument or NULL.
-
#has_help ⇒ Boolean
Returns true if there are –help -h arguments.
-
#initialize(ptr, finalize = true) ⇒ Zargs
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#next ⇒ String
Return next positional argument or NULL.
- #null? ⇒ Boolean
-
#param_first ⇒ String
Return first named parameter value, or NULL if there are no named parameters, or value for which zargs_param_empty (arg) returns true.
-
#param_lookup(keys) ⇒ String
Return value of named parameter, NULL if no given parameter has been specified, or special value for wich zargs_param_empty () returns true.
-
#param_lookupx(keys, *args) ⇒ String
Return value of named parameter(s), NULL if no given parameter has been specified, or special value for wich zargs_param_empty () returns true.
-
#param_name ⇒ String
Return current parameter name, or NULL if there are no named parameters.
-
#param_next ⇒ String
Return next named parameter value, or NULL if there are no named parameters, or value for which zargs_param_empty (arg) returns true.
-
#print ⇒ void
Print an instance of zargs.
-
#progname ⇒ String
Return program name (argv).
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zargs
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
42 43 44 45 46 47 48 49 50 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 42 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
36 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 36 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
53 54 55 56 57 58 59 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 53 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.zargs_destroy ptr_ptr end end |
.new(argc, argv) ⇒ CZMQ::Zargs
Create a new zargs from command line arguments.
98 99 100 101 102 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 98 def self.new(argc, argv) argc = Integer(argc) ptr = ::CZMQ::FFI.zargs_new(argc, argv) __new ptr end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
66 67 68 69 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 66 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.
77 78 79 80 81 82 83 84 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 77 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.
89 90 91 92 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 89 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#arguments ⇒ Integer
Return number of positional arguments
127 128 129 130 131 132 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 127 def arguments() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_arguments(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy zargs instance.
107 108 109 110 111 112 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 107 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zargs_destroy(self_p) result end |
#first ⇒ String
Return first positional argument or NULL
137 138 139 140 141 142 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 137 def first() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_first(self_p) result end |
#has_help ⇒ Boolean
Returns true if there are –help -h arguments
217 218 219 220 221 222 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 217 def has_help() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_has_help(self_p) result end |
#next ⇒ String
Return next positional argument or NULL
147 148 149 150 151 152 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 147 def next() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_next(self_p) result end |
#null? ⇒ Boolean
61 62 63 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 61 def null? !@ptr or @ptr.null? end |
#param_first ⇒ String
Return first named parameter value, or NULL if there are no named parameters, or value for which zargs_param_empty (arg) returns true.
158 159 160 161 162 163 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 158 def param_first() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_param_first(self_p) result end |
#param_lookup(keys) ⇒ String
Return value of named parameter, NULL if no given parameter has been specified, or special value for wich zargs_param_empty () returns true.
193 194 195 196 197 198 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 193 def param_lookup(keys) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_param_lookup(self_p, keys) result end |
#param_lookupx(keys, *args) ⇒ String
Return value of named parameter(s), NULL if no given parameter has been specified, or special value for wich zargs_param_empty () returns true.
207 208 209 210 211 212 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 207 def param_lookupx(keys, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_param_lookupx(self_p, keys, *args) result end |
#param_name ⇒ String
Return current parameter name, or NULL if there are no named parameters.
180 181 182 183 184 185 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 180 def param_name() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_param_name(self_p) result end |
#param_next ⇒ String
Return next named parameter value, or NULL if there are no named parameters, or value for which zargs_param_empty (arg) returns true.
169 170 171 172 173 174 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 169 def param_next() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_param_next(self_p) result end |
#print ⇒ void
This method returns an undefined value.
Print an instance of zargs.
236 237 238 239 240 241 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 236 def print() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_print(self_p) result end |
#progname ⇒ String
Return program name (argv)
117 118 119 120 121 122 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 117 def progname() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zargs_progname(self_p) result end |