Registering and opts parsing.
More...
|
| bool | tgen::has_opt (std::size_t index) |
| | Checks if opt at some index exists.
|
| bool | tgen::has_opt (const std::string &key) |
| | Checks if opt with with some key exists.
|
| template<typename T> |
| T | tgen::opt (size_t index, std::optional< T > default_value=std::nullopt) |
| | Gets opt by key.
|
| template<typename T> |
| T | tgen::opt (const std::string &key, std::optional< T > default_value=std::nullopt) |
| | Gets opt by key.
|
| void | tgen::register_gen (int argc, char **argv) |
| | Sets up the generator.
|
| void | tgen::register_gen (std::optional< long long > seed=std::nullopt) |
| | Sets up the generator without arguments.
|
| void | tgen::set_cpp_version (int version) |
| | Sets C++ version.
|
| void | tgen::set_compiler (_detail::compiler_value compiler) |
| | Sets compiler.
|
Registering and opts parsing.
Registering
The first line of your generator should be:
#include "tgen.h"
int main(int argc, char** argv) {
}
void register_gen(int argc, char **argv)
Sets up the generator.
This does two things:
- Sets up the seed for random generator based on the arguments (excluding the executable name). That is, ./a.out -n 10 and ./b.out -n 10 will use the same seed.
- Parses the opts (given in the arguments).
Opts
Opts are a list of either named or positional options.
Named options is given in one of the following formats:
- -keyname=value or –keyname=value (ex. -n=10, –test-count=20)
- -keyname value or –keyname value (ex. -n 10, –test-count 20)
Positional options are numbered from 0 sequentially.
For example, if you compile your code to a.out, calling ./a.out -n 10 str –q=5 -1.1e2 results in the following opts:
Consuming opts
You can consume the opts by using opt<>:
T opt(size_t index, std::optional< T > default_value=std::nullopt)
Gets opt by key.
◆ has_opt() [1/2]
| bool tgen::has_opt |
( |
const std::string & | key | ) |
|
|
inline |
Checks if opt with with some key exists.
- Parameters
-
- Returns
- If there is named opt with key.
Examples
bool has_opt(std::size_t index)
Checks if opt at some index exists.
Definition at line 1069 of file tgen.h.
◆ has_opt() [2/2]
| bool tgen::has_opt |
( |
std::size_t | index | ) |
|
|
inline |
Checks if opt at some index exists.
- Parameters
-
| index | Index of positional opt. |
- Returns
- If there is positional opt at index.
Examples
Definition at line 1063 of file tgen.h.
◆ opt() [1/2]
template<typename T>
| T tgen::opt |
( |
const std::string & | key, |
|
|
std::optional< T > | default_value = std::nullopt ) |
Gets opt by key.
- Template Parameters
-
- Parameters
-
| key | Key to fetch. |
| default_value | Default value to be returned, if key is not found. |
- Returns
- The value of opt with key. If not found, returns default_value.
- Exceptions
-
| std::runtime_error | if opt is not found and default_value is not given. |
Examples
Definition at line 1091 of file tgen.h.
◆ opt() [2/2]
template<typename T>
| T tgen::opt |
( |
size_t | index, |
|
|
std::optional< T > | default_value = std::nullopt ) |
Gets opt by key.
- Template Parameters
-
- Parameters
-
| index | index to fetch. |
| default_value | Default value to be returned, if index is not found. |
- Returns
- The value of opt at index. If not found, returns default_value.
- Exceptions
-
| std::runtime_error | if opt is not found and default_value is not given. |
Examples
Definition at line 1077 of file tgen.h.
◆ register_gen() [1/2]
| void tgen::register_gen |
( |
int | argc, |
|
|
char ** | argv ) |
|
inline |
Sets up the generator.
- Parameters
-
| argc | Argument count, from the main function. |
| argv | Argument vector, from the main function. |
Sets up the opts, and the seed of the random number generator. The seed is dependent on the arguments (excluding the executable name).
Examples
#include "tgen.h"
int main(int argc, char** argv) {
}
Definition at line 1102 of file tgen.h.
◆ register_gen() [2/2]
| void tgen::register_gen |
( |
std::optional< long long > | seed = std::nullopt | ) |
|
|
inline |
Sets up the generator without arguments.
- Parameters
-
| seed | Seed for the random number generator. |
Examples
#include "tgen.h"
int main() {
}
Or even:
#include "tgen.h"
int main() {
}
Definition at line 1113 of file tgen.h.
◆ set_compiler()
| void tgen::set_compiler |
( |
_detail::compiler_value | compiler | ) |
|
|
inline |
Sets compiler.
- Parameters
-
| compiler | The compiler (tgen::gcc(...) or tgen::clang(...)). |
This can be used by some functions to find counter testcases for specific systems.
Examples
void set_compiler(_detail::compiler_value compiler)
Sets compiler.
This can also be set by command argument:
- ./executable tgen::GCC: equivalent to tgen::set_compiler(tgen::gcc()).
- ./executable tgen::GCC:15: equivalent to tgen::set_compiler(tgen::gcc(15)).
- ./executable tgen::GCC:15.2: equivalent to tgen::set_compiler(tgen::gcc(15, 2)).
Definition at line 877 of file tgen.h.
◆ set_cpp_version()
| void tgen::set_cpp_version |
( |
int | version | ) |
|
|
inline |
Sets C++ version.
- Parameters
-
| version | The C++ version (17, 20, or 23). |
This can be used by some functions to find counter testcases for specific systems.
Examples
void set_cpp_version(int version)
Sets C++ version.
This can also be set by command argument:
- ./executable tgen::CPP:20: equivalent to tgen::set_cpp_version(20).
Definition at line 858 of file tgen.h.