* Register a command-line argument to the handler. The registration may fail if * there is already an argument with the specified short or long option. * * @param opt Short option of an argument. * @param longOpt Long option of an argument. * @param hasInput True if the argument has an input, defaultly false. * * @return True if the registration was successful, otherwise false. */
| 66 | * @return True if the registration was successful, otherwise false. |
| 67 | */ |
| 68 | bool ArgHandler::registerArg(char opt, const std::string& longOpt, bool hasInput /*= false*/) |
| 69 | { |
| 70 | // '-' is reserved character for long options |
| 71 | if (opt == '-') |
| 72 | return false; |
| 73 | |
| 74 | std::string shortOpt(&opt, 1); |
| 75 | // Test if there is command with that option |
| 76 | if (_argMap.find(shortOpt) != _argMap.end()) |
| 77 | return false; |
| 78 | |
| 79 | // Test also long option if it is not missing |
| 80 | if (!longOpt.empty()) |
| 81 | { |
| 82 | if (_argMap.find(longOpt) != _argMap.end()) |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | _argMap[shortOpt] = new ArgInfo(opt, longOpt, hasInput); |
| 87 | if (!longOpt.empty()) |
| 88 | { |
| 89 | // Long option and short option are both using the same ArgInfo |
| 90 | _argMap[longOpt] = _argMap[shortOpt]; |
| 91 | } |
| 92 | |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Array like access to the command-line arguments. Accessor is short option. |