Set a an argument's value from a string. Throws an arg_error exception if \a s can't be converted to the argument's type. Values must be provided for with the option name. \note Not intended to be called from user code. \param s Value to set. */
| 402 | \param s Value to set. |
| 403 | */ |
| 404 | virtual void setValue(const std::string& s) |
| 405 | { |
| 406 | if (m_set) |
| 407 | { |
| 408 | throw arg_val_error("Attempted to set value twice for argument '" + |
| 409 | m_longname + "'."); |
| 410 | } |
| 411 | if (s.empty()) |
| 412 | { |
| 413 | throw arg_val_error("Argument '" + m_longname + |
| 414 | "' needs a value and none was provided."); |
| 415 | } |
| 416 | |
| 417 | m_rawVal = s; |
| 418 | auto status = Utils::fromString(s, m_var); |
| 419 | if (!status) |
| 420 | { |
| 421 | std::string error(m_error); |
| 422 | |
| 423 | if (error.empty()) |
| 424 | { |
| 425 | if (status.what().size()) |
| 426 | error = "Invalid value for argument '" + m_longname + |
| 427 | "': " + status.what(); |
| 428 | else |
| 429 | error = "Invalid value '" + s + "' for argument '" + |
| 430 | m_longname + "'."; |
| 431 | } |
| 432 | throw arg_val_error(error); |
| 433 | } |
| 434 | m_set = true; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | Reset the argument's state. |
no test coverage detected