Class: Arg
- Inherits:
-
BaseOptArg
- Object
- BaseOptArg
- Arg
- Defined in:
- lib/yaggo/dsl.rb
Instance Attribute Summary collapse
-
#access_types ⇒ Object
Returns the value of attribute access_types.
-
#at_least ⇒ Object
readonly
Returns the value of attribute at_least.
-
#description ⇒ Object
Returns the value of attribute description.
-
#multiple ⇒ Object
Returns the value of attribute multiple.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#type ⇒ Object
Returns the value of attribute type.
-
#typestr ⇒ Object
Returns the value of attribute typestr.
-
#var ⇒ Object
readonly
Returns the value of attribute var.
Instance Method Summary collapse
- #check ⇒ Object
- #default=(*args) ⇒ Object
- #dump ⇒ Object
- #hidden=(*args) ⇒ Object
- #init ⇒ Object
-
#initialize(str) ⇒ Arg
constructor
A new instance of Arg.
- #off ⇒ Object
- #on ⇒ Object
- #parse_arg ⇒ Object
- #required=(*args) ⇒ Object
- #secret=(*args) ⇒ Object
- #var_decl ⇒ Object
Methods inherited from BaseOptArg
#access=, #at_least=, #suffix=
Constructor Details
#initialize(str) ⇒ Arg
Returns a new instance of Arg.
448 449 450 451 452 453 454 455 |
# File 'lib/yaggo/dsl.rb', line 448 def initialize(str) @name = str @var = @name.gsub(/[^a-zA-Z0-9_]/, "_") @type = nil @at_least = 0 @suffix = false @access_types = [] end |
Instance Attribute Details
#access_types ⇒ Object
Returns the value of attribute access_types.
446 447 448 |
# File 'lib/yaggo/dsl.rb', line 446 def access_types @access_types end |
#at_least ⇒ Object (readonly)
Returns the value of attribute at_least.
447 448 449 |
# File 'lib/yaggo/dsl.rb', line 447 def at_least @at_least end |
#description ⇒ Object
Returns the value of attribute description.
446 447 448 |
# File 'lib/yaggo/dsl.rb', line 446 def description @description end |
#multiple ⇒ Object
Returns the value of attribute multiple.
446 447 448 |
# File 'lib/yaggo/dsl.rb', line 446 def multiple @multiple end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
447 448 449 |
# File 'lib/yaggo/dsl.rb', line 447 def name @name end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
447 448 449 |
# File 'lib/yaggo/dsl.rb', line 447 def suffix @suffix end |
#type ⇒ Object
Returns the value of attribute type.
446 447 448 |
# File 'lib/yaggo/dsl.rb', line 446 def type @type end |
#typestr ⇒ Object
Returns the value of attribute typestr.
446 447 448 |
# File 'lib/yaggo/dsl.rb', line 446 def typestr @typestr end |
#var ⇒ Object (readonly)
Returns the value of attribute var.
447 448 449 |
# File 'lib/yaggo/dsl.rb', line 447 def var @var end |
Instance Method Details
#check ⇒ Object
481 482 483 484 485 486 |
# File 'lib/yaggo/dsl.rb', line 481 def check super pref = "Arg #{name}:" raise "#{pref} No type specified" if type.nil? end |
#default=(*args) ⇒ Object
465 466 467 |
# File 'lib/yaggo/dsl.rb', line 465 def default=(*args) raise "An arg cannot have a default value (#{args[0]})" end |
#dump ⇒ Object
506 507 508 509 |
# File 'lib/yaggo/dsl.rb', line 506 def dump ["\"#{@var}_arg:\"", @multiple ? "vec_str(#{@var}_arg)" : "#{@var}_arg"] end |
#hidden=(*args) ⇒ Object
469 470 471 |
# File 'lib/yaggo/dsl.rb', line 469 def hidden=(*args) raise "An arg cannot be marked hidden" end |
#init ⇒ Object
499 500 501 502 503 504 |
# File 'lib/yaggo/dsl.rb', line 499 def init s = "#{@var}_arg(" s += default_val(@default, @type) unless @multiple s += ")" s end |
#off ⇒ Object
463 |
# File 'lib/yaggo/dsl.rb', line 463 def off; raise "An arg cannot be a flag with default value off"; end |
#on ⇒ Object
462 |
# File 'lib/yaggo/dsl.rb', line 462 def on; raise "An arg cannot be a flag with default value on"; end |
#parse_arg ⇒ Object
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/yaggo/dsl.rb', line 511 def parse_arg a = [] off = "" if @multiple a << "for( ; optind < argc; ++optind) {" a << " #{@var}_arg.push_back(#{str_conv("argv[optind]", @type, @suffix)});" off = " " else a << "#{@var}_arg = #{str_conv("argv[optind]", @type, @suffix)};" end unless @type == :string || @type == :c_string a << (off + "CHECK_ERR(#{@type}_t, argv[optind], \"#{@var}\")") end a << (@multiple ? "}" : "++optind;") a end |
#required=(*args) ⇒ Object
477 478 479 |
# File 'lib/yaggo/dsl.rb', line 477 def required=(*args) raise "An arg cannot be marked required" end |
#secret=(*args) ⇒ Object
473 474 475 |
# File 'lib/yaggo/dsl.rb', line 473 def secret=(*args) raise "An arg cannot be marked secret" end |
#var_decl ⇒ Object
488 489 490 491 492 493 494 495 496 497 |
# File 'lib/yaggo/dsl.rb', line 488 def var_decl if @multiple c_type = "::std::vector<#{$type_to_C_type[@type]}>" [c_type.ljust($typejust) + " #{@var}_arg;", "typedef #{c_type}::iterator #{@var}_arg_it;", "typedef #{c_type}::const_iterator #{@var}_arg_const_it;"] else ["#{$type_to_C_type[@type]}".ljust($typejust) + " #{@var}_arg;"] end end |