Example program showing how to define and use GOptions : .
More...
#include "goptions.h"
#include <iostream>
Go to the source code of this file.
|
| GOptions | defineOptions () |
| | Builds and returns a set of example options (definitions only).
|
| int | main (int argc, char *argv[]) |
| | Example entry point: parse inputs and read back resolved values.
|
This example demonstrates an end-to-end pattern commonly used in GEMC-style modules:
- Build a definition-only GOptions : instance (no parsing yet).
- Construct a parsing GOptions : instance in main() using: GOptions(argc, argv, user_defined_options) .
- Retrieve resolved values with typed getters such as getScalarInt() .
It also shows:
- Defining a boolean switch with defineSwitch() .
- Defining scalar options with defineOption() .
- Defining a structured option schema (sequence of maps) and providing a usable command-line example.
Definition in file define_options.cc.
◆ defineOptions()
This function intentionally does not parse any inputs. Instead, it returns a GOptions : populated with registrations:
- switches (presence-based booleans),
- scalar options,
- structured option schemas.
The returned object is then passed into the parsing constructor:
auto gopts = std::make_shared<GOptions>(argc, argv,
defineOptions());
GOptions defineOptions()
Builds and returns a set of example options (definitions only).
This pattern allows multiple components (modules/plugins) to contribute their own option definitions and then combine them before parsing.
What this example defines:
- Switch log: dummy switch that can be toggled by -log.
- Scalar runno: an integer option set via -runno=<value>.
- Scalar nthreads: an integer option controlling thread usage, with 0 meaning "use all cores".
- Structured gparticle: a schema representing generator particles as a sequence of maps, including mandatory keys flagged using
goptions::NODFLT.
- Returns
- A GOptions : object populated with example switches and options.
Definition at line 55 of file define_options.cc.
◆ main()
| int main |
( |
int | argc, |
|
|
char * | argv[] ) |
This main() illustrates the common consumption flow:
- Construct a parsing GOptions : instance using argc/argv and the definitions provided by defineOptions().
- Query values from the resolved configuration.
Example invocations:
- Scalar option from command line:
define_options -nthreads=8
- Dot-notation (if supported by the target option; shown here for illustration):
define_options -verbosity.gemc=1
- Structured option payload (quoted so the shell does not split YAML-like characters):
define_options -gparticle="[{name: e-, p: 2300, theta: 23.0}]"
- Parameters
-
| argc | Number of command-line arguments. |
| argv | Array of command-line argument strings. |
- Returns
- Process exit code (
EXIT_SUCCESS on success).
Definition at line 116 of file define_options.cc.