* @param description Description of current Argument
* @param function Function used to handle current Argument.
*/
- Argument(const std::string & description, void (*function)(ParameterType))
- : Parameter(description), Callable<ParameterType>(function) {
- }
-
Argument(const std::string & description, std::function<void(ParameterType)> function)
: Parameter(description), Callable<ParameterType>(function) {
}
* @param description Description of current Option
* @param function Function used to handle current Option.
*/
- Option(const std::string & name, const std::string & description, void (*function)(ParameterType))
+ Option(const std::string & name, const std::string & description, std::function<void(ParameterType)> function)
: Parameter(description), Callable<ParameterType>(function), name(name) {
}
* @param description Description of current Option
* @param function Function used to handle current Option.
*/
- Option(const std::string & name, const std::string & description, void (*function)(void))
+ Option(const std::string & name, const std::string & description, std::function<void(void)> function)
: Parameter(description), Callable<void>(function), name(name) {
}
#include <iostream>
#include <string>
+#include <functional>
#include "option.h"
#include "argument.h"
std::cout << "Void function " << std::endl;
}
+class ExampleClass {
+public:
+ void _argument(bool a) {
+ argument_function(a);
+ }
+ void _option(std::string a) {
+ option_function(a);
+ }
+ void _void(void) {
+ void_function();
+ }
+};
+
int main(int argc, char *argv[]) {
+ Class c;
+
try {
Command command(argc, argv, {
new Grouped({
- new Required(new MultiValue("-", new Argument<bool>("Input values", argument_function))),
- new MultiValue(",", new Option<std::string>("f", "Optional file", option_function))
+ new Required(
+ new MultiValue("-",
+ new Argument<bool>("Input values", std::bind(&ExampleClass::_argument, &c, std::placeholders::_1))
+ )
+ ),
+ new MultiValue(",",
+ new Option<std::string>("f", "Optional file", std::bind(&ExampleClass::_option, &c, std::placeholders::_1))
+ )
}),
- new Option<void>("h", "Help", void_function)
+ new Option<void>("h", "Help", std::bind(&ExampleClass::_void, &c)),
+
+ // just a pure method calling
+ new Option<void>("v", "version", void_function)
});
+
+ /* ExampleClass is initialized.
+ * You can run your main program now
+ */
}
catch(const std::exception & e) {
std::cout << e.what() << std::endl;
}
return 0;
-}
\ No newline at end of file
+}