zz::cfg::ArgOption Class Reference

The ArgOption class for ArgParser. More...

#include <zupply.hpp>

Public Member Functions

 ArgOption (char shortKey, std::string longKey)
 ArgOption constructor with short key and long key. More...
 
 ArgOption (char shortKey)
 ArgOption constructor with short key only. More...
 
 ArgOption (std::string longKey)
 ArgOption constructor with long key only. More...
 
ArgOptioncall (std::function< void()> todo)
 Set callback function when this option is triggered. One can use lambda function as callback. More...
 
ArgOptioncall (std::function< void()> todo, std::function< void()> otherwise)
 Set callback functions. Both TODO function and Default function required. If ArgParser detect this option, the TODO function will be called. Otherwise, the default callback function will be executed. More...
 
ArgOptionset_help (std::string helpInfo)
 Set help info for this option. Use this to add description for this option. More...
 
ArgOptionrequire (bool require=true)
 Set this option to required or not. After parsing arguments, if this set to required but not found, ArgParser will generate an error information. More...
 
ArgOptionset_once (bool onlyOnce=true)
 Set this option to allow option be called only once. This is set to disable accidentally set a variable multiply times. More...
 
ArgOptionset_type (std::string type)
 Set option variable type. Optional. Let user know what type this option take, INT, FLOAT, STRING... More...
 
ArgOptionset_min (int minCount)
 Set minimum number of argument this option take. If minimum number not satisfied, ArgParser will generate an error. More...
 
ArgOptionset_max (int maxCount)
 Set maximum number of argument this option take. If maximum number not satisfied, ArgParser will generate an error. More...
 
Value get_value ()
 Return the stored value. More...
 
int get_count ()
 Return the count. More...
 

Friends

class ArgParser
 

Detailed Description

The ArgOption class for ArgParser.

Constructor & Destructor Documentation

zz::cfg::ArgOption::ArgOption ( char  shortKey,
std::string  longKey 
)

ArgOption constructor with short key and long key.

Parameters
shortKeyA char, use 'a'
longKeyA std::string "long"
zz::cfg::ArgOption::ArgOption ( char  shortKey)

ArgOption constructor with short key only.

Parameters
shortKeyA char, use 'a'
zz::cfg::ArgOption::ArgOption ( std::string  longKey)

ArgOption constructor with long key only.

Parameters
longKeyA std::string "long"

Member Function Documentation

ArgOption & zz::cfg::ArgOption::call ( std::function< void()>  todo)

Set callback function when this option is triggered. One can use lambda function as callback.

Parameters
todoFunction callback
Returns
Reference to this option
ArgOption & zz::cfg::ArgOption::call ( std::function< void()>  todo,
std::function< void()>  otherwise 
)

Set callback functions. Both TODO function and Default function required. If ArgParser detect this option, the TODO function will be called. Otherwise, the default callback function will be executed.

Parameters
todoCallback function when triggered
otherwiseDefault function if this option not found
Returns
Reference to this option
int zz::cfg::ArgOption::get_count ( )

Return the count.

Returns
Reference count
Value zz::cfg::ArgOption::get_value ( )

Return the stored value.

Returns
Stored value
ArgOption & zz::cfg::ArgOption::require ( bool  require = true)

Set this option to required or not. After parsing arguments, if this set to required but not found, ArgParser will generate an error information.

Parameters
requireRequire this option if set to true
Returns
Reference to this option
ArgOption & zz::cfg::ArgOption::set_help ( std::string  helpInfo)

Set help info for this option. Use this to add description for this option.

Parameters
helpInfo
Returns
Reference to this option
ArgOption & zz::cfg::ArgOption::set_max ( int  maxCount)

Set maximum number of argument this option take. If maximum number not satisfied, ArgParser will generate an error.

Parameters
maxCount
Returns
Reference to this option
ArgOption & zz::cfg::ArgOption::set_min ( int  minCount)

Set minimum number of argument this option take. If minimum number not satisfied, ArgParser will generate an error.

Parameters
minCount
Returns
Reference to this option
ArgOption & zz::cfg::ArgOption::set_once ( bool  onlyOnce = true)

Set this option to allow option be called only once. This is set to disable accidentally set a variable multiply times.

Parameters
onlyOnceAllow this option be used only once
Returns
Reference to this option
ArgOption & zz::cfg::ArgOption::set_type ( std::string  type)

Set option variable type. Optional. Let user know what type this option take, INT, FLOAT, STRING...

Parameters
typeType name in string, just a reminder.
Returns
Reference to this option

The documentation for this class was generated from the following files: