8 Commits

Author SHA1 Message Date
Nicholas Devenish 1f2187b0e1 store_into: Accept float (by accepting generic floating point) 2025-01-26 21:11:42 +00:00
Alessandro Pasotti 8dead89026 FEATURE: multiple actions
Also fixes the incompatibility between store_into and scan and action:
when the three methods above were called, being all based on the
(unique) action, the last one would overwrite the previous ones.

This issue was making the parser strictly dependant on the order
of the scan/store_into/action calls making them mutually exclusive.
2024-05-09 09:53:34 +02:00
Alessandro Pasotti b85a0a414d Add Argument::store_into(std::set<int||string> &var) method 2024-04-30 17:30:48 +02:00
Andrew Bell 7cb70ed6f3 Don't store -1 into unsigned value. 2024-04-18 18:11:07 -04:00
Andrew Bell 29f1d12333 Add cstdint header. 2024-04-18 08:24:57 -04:00
Andrew Bell d141b8d2a1 Add support for general integer types in store_into. 2024-04-17 13:35:51 -04:00
Even Rouault 29367256d3 Add Argument::store_into(std::vector<int> &var) method 2024-04-02 23:22:53 +02:00
Even Rouault 8784cc8ddf Add Argument::store_into() functions
It is possible to bind arguments to a variable storing their value, as an
alternative to explicitly calling ``program.get<T>(arg_name)`` or ``program[arg_name]``

This is currently implementeted for variables of type ``bool`` (this also
implicitly calls ``flag()``), ``int``, ``double``, ``std::string`` and
``std::vector<std::string>``. If the argument is not specified in the command
line, the default value (if set) is set into the variable.

```cpp
bool flagvar = false;
program.add_argument("--flagvar").store_into(flagvar);

int intvar = 0;
program.add_argument("--intvar").store_into(intvar);

double doublevar = 0;
program.add_argument("--doublevar").store_into(doublevar);

std::string strvar;
program.add_argument("--strvar").store_into(strvar);

std::vector<std::string> strvar_repeated;
program.add_argument("--strvar-repeated").append().store_into(strvar_repeated);

std::vector<std::string> strvar_multi_valued;
program.add_argument("--strvar-multi-valued").nargs(2).store_into(strvar_multi_valued);
```
2024-03-12 12:50:22 +01:00