![]() |
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
Classes | |
class | EnumOption< T > |
class | ListOption< T > |
class | OptionException |
class | Manager |
class | Option |
class | StringList |
class | SwitchOption |
class | ValueOption< T > |
Macros | |
#define | ELM_RUN(C) int main(int argc, char **argv) { return C().manage(argc, argv); } |
ELM provides several classes to manage efficiently and easily command line options. There are currently two ways to use these classes, the old approach that will become quickly deprecated (please no more use it) and the new one.
To perform the parsing of command line arguments, ELM provides two basic classes. elm::option::Manager represents the command as a base of documentation and as a list of options items. The manager is initialized as in the following example:
According to your needs, as many configurations as needed can be passed to the Make() object while maintaining type checking. Refer to elm::option::Manager::Make class documentation for the list of available configurations.
The options works in the same way:
As many ".cmd()" method calls can be added and other configurations can be passed using the same syntax. Refer to the documentations of the different option classes to get details about the configuration items (elm::option::Option::Make, ...).
Using both configuration system for the manager and the option, a command is usually defined as in the following example:
At this point, the options may be used as normal values in the program as below:
Free arguments, not processed by an option item, are usually handled by overriding the method
The example above supports only one argument.In this example, if the argument is not defined, the argument arg
is copied to the field my_arg
. If it is already defined, an OptionException is raised. In this case, the passed message will be displayed to the user and the syntax of the command will also automatically be displayed then.
To use such a command, the main
parameters, argc
and argv
, must be passed to the parse()
method:
This may be replaced by the short-cut:
The classes allowed are:
#define ELM_RUN | ( | C | ) | int main(int argc, char **argv) { return C().manage(argc, argv); } |
#include <include/elm/option/Manager.h>
This macro is a short to a main function running an application class. The parameter must be the name of a class extending option::Manager. It replaces the mandatory main() function of a C++ application.
C | Name of the application class. |