Class: CZMQ::FFI::Zargs

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

Overview

Note:

This class is 100% generated using zproject.

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:

  • 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 position 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

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zargs

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


45
46
47
48
49
50
51
52
53
# 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

Class Method Details

.__newObject



39
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 39

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


56
57
58
59
60
61
62
63
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 56

def self.create_finalizer_for(ptr)
  ptr_ptr = ::FFI::MemoryPointer.new :pointer

  Proc.new do
    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.

Parameters:

  • argc (Integer, #to_int, #to_i)
  • argv (::FFI::Pointer, #to_ptr)

Returns:

  • (CZMQ::Zargs)


102
103
104
105
106
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 102

def self.new(argc, argv)
  argc = Integer(argc)
  ptr = ::CZMQ::FFI.zargs_new(argc, argv)
  __new ptr
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


250
251
252
253
254
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 250

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

Instance Method Details

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

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



70
71
72
73
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 70

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:



81
82
83
84
85
86
87
88
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 81

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.



93
94
95
96
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 93

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#argumentsInteger

Return number of positional arguments

Returns:

  • (Integer)

Raises:



131
132
133
134
135
136
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 131

def arguments()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_arguments(self_p)
  result
end

#destroyvoid

This method returns an undefined value.

Destroy zargs instance.



111
112
113
114
115
116
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 111

def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zargs_destroy(self_p)
  result
end

#firstString

Return first positional argument or NULL

Returns:

  • (String)

Raises:



141
142
143
144
145
146
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 141

def first()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_first(self_p)
  result
end

#get(name) ⇒ String

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

Parameters:

  • name (String, #to_s, nil)

Returns:

  • (String)

Raises:



194
195
196
197
198
199
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 194

def get(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_get(self_p, name)
  result
end

#getx(name, *args) ⇒ String

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

Parameters:

Returns:

  • (String)

Raises:



206
207
208
209
210
211
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 206

def getx(name, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_getx(self_p, name, *args)
  result
end

#has(name) ⇒ Boolean

Returns true if named parameter was specified on command line

Parameters:

  • name (String, #to_s, nil)

Returns:

  • (Boolean)

Raises:



217
218
219
220
221
222
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 217

def has(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_has(self_p, name)
  result
end

#hasx(name, *args) ⇒ Boolean

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

Parameters:

Returns:

  • (Boolean)

Raises:



229
230
231
232
233
234
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 229

def hasx(name, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_hasx(self_p, name, *args)
  result
end

#nextString

Return next positional argument or NULL

Returns:

  • (String)

Raises:



151
152
153
154
155
156
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 151

def next()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_next(self_p)
  result
end

#null?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 65

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

#param_firstString

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

Returns:

  • (String)

Raises:



162
163
164
165
166
167
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 162

def param_first()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_param_first(self_p)
  result
end

#param_nameString

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

Returns:

  • (String)

Raises:



183
184
185
186
187
188
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 183

def param_name()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_param_name(self_p)
  result
end

#param_nextString

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

Returns:

  • (String)

Raises:



173
174
175
176
177
178
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 173

def param_next()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_param_next(self_p)
  result
end

This method returns an undefined value.

Print an instance of zargs.

Raises:



239
240
241
242
243
244
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 239

def print()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_print(self_p)
  result
end

#prognameString

Return program name (argv)

Returns:

  • (String)

Raises:



121
122
123
124
125
126
# File 'lib/czmq-ffi-gen/czmq/ffi/zargs.rb', line 121

def progname()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zargs_progname(self_p)
  result
end