class CZMQ::FFI::Zargs

Platform independent command line argument parsing helpers

There are two kind of elements provided by this class Named parameters, accessed by param_get and param_has methods

* --named-parameter
* --parameter with_value
* -a val

Positional arguments, accessed by zargs_first, zargs_next

It DOES:

It does NOT

In future it SHALL

@note This class is 100% generated using zproject.

Public Class Methods

__new(argc, argv)
Alias for: new
create_finalizer_for(ptr) click to toggle source

@param ptr [::FFI::Pointer] @return [Proc]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 56
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(ptr, finalize = true) click to toggle source

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 45
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
new(argc, argv) click to toggle source

Create a new zargs from command line arguments. @param argc [Integer, to_int, to_i] @param argv [::FFI::Pointer, to_ptr] @return [CZMQ::Zargs]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 101
def self.new(argc, argv)
  argc = Integer(argc)
  ptr = ::CZMQ::FFI.zargs_new(argc, argv)
  __new ptr
end
Also aliased as: __new
test(verbose) click to toggle source

Self test of this class.

@param verbose [Boolean] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 249
def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zargs_test(verbose)
  result
end

Public Instance Methods

__ptr() click to toggle source

Return internal pointer @return [::FFI::Pointer]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 69
def __ptr
  raise DestroyedError unless @ptr
  @ptr
end
Also aliased as: to_ptr
__ptr_give_ref() click to toggle source

Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object

and thus makes it unusable.

@return [::FFI::MemoryPointer] the pointer pointing to a pointer

pointing to the native object
# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 80
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() click to toggle source

Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native

object will be freed by other means.

@return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 92
def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end
arguments() click to toggle source

Return number of positional arguments

@return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 130
def arguments()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_arguments(self_p)
  result
end
destroy() click to toggle source

Destroy zargs instance.

@return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 110
def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zargs_destroy(self_p)
  result
end
first() click to toggle source

Return first positional argument or NULL

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 140
def first()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_first(self_p)
  result
end
get(name) click to toggle source

Return value of named parameter or NULL is it has no value (or was not specified)

@param name [String, to_s, nil] @return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 193
def get(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_get(self_p, name)
  result
end
getx(name, *args) click to toggle source

Return value of one of parameter(s) or NULL is it has no value (or was not specified)

@param name [String, to_s, nil] @param args [Array<Object>] see github.com/ffi/ffi/wiki/examples#using-varargs @return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 205
def getx(name, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_getx(self_p, name, *args)
  result
end
has(name) click to toggle source

Returns true if named parameter was specified on command line

@param name [String, to_s, nil] @return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 216
def has(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_has(self_p, name)
  result
end
hasx(name, *args) click to toggle source

Returns true if named parameter(s) was specified on command line

@param name [String, to_s, nil] @param args [Array<Object>] see github.com/ffi/ffi/wiki/examples#using-varargs @return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 228
def hasx(name, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_hasx(self_p, name, *args)
  result
end
next() click to toggle source

Return next positional argument or NULL

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 150
def next()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_next(self_p)
  result
end
null?() click to toggle source

@return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 64
def null?
  !@ptr or @ptr.null?
end
param_first() click to toggle source

Return first named parameter value, or NULL if there are no named parameters, or value for which zargs_param_empty (arg) returns true.

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 161
def param_first()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_param_first(self_p)
  result
end
param_name() click to toggle source

Return current parameter name, or NULL if there are no named parameters.

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 182
def param_name()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_param_name(self_p)
  result
end
param_next() click to toggle source

Return next named parameter value, or NULL if there are no named parameters, or value for which zargs_param_empty (arg) returns true.

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 172
def param_next()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_param_next(self_p)
  result
end
print() click to toggle source

Print an instance of zargs.

@return [void]

progname() click to toggle source

Return program name (argv)

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zargs.rb, line 120
def progname()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_progname(self_p)
  result
end
to_ptr()

So external Libraries can just pass the Object to a FFI function which expects a :pointer

Alias for: __ptr