From 5d3d8cfdf0048da0f821c055be2565f9c49e3107 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Mon, 8 Feb 2016 22:13:29 +0100 Subject: [PATCH] Added examples for binding functions and methods --- ChangeLog | 4 +++ Makefile.am | 2 +- configure.ac | 3 ++- debian/changelog | 9 ++++++- examples/Makefile.am | 18 +++++++++++++ examples/functions.cpp | 55 +++++++++++++++++++++++++++++++++++++++ examples/methods.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 examples/Makefile.am create mode 100644 examples/functions.cpp create mode 100644 examples/methods.cpp diff --git a/ChangeLog b/ChangeLog index e69de29..9a2a077 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,4 @@ +## [0.3] - 2016-02-08 +### Added +- Possibility to bind class method to parameter +- Examples (check examples dir) diff --git a/Makefile.am b/Makefile.am index a349614..e10d5a8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,7 @@ CLEANFILES = \ %~ \ doxyfile.stamp -SUBDIRS = include . tests docs +SUBDIRS = include . tests examples docs noinst_PROGRAMS = bin/command diff --git a/configure.ac b/configure.ac index 988c072..b990066 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([Command], [0.2.1], [bugz@dlugolecki.net.pl], [command], [http://dlugolecki.net.pl/software/command/]) +AC_INIT([Command], [0.3], [bugz@dlugolecki.net.pl], [command], [http://dlugolecki.net.pl/software/command/]) AC_PREREQ([2.59]) AM_INIT_AUTOMAKE([1.10 -Wall]) AC_CONFIG_HEADERS([config.h]) @@ -7,6 +7,7 @@ AC_CONFIG_FILES([ include/Makefile Makefile tests/Makefile + examples/Makefile docs/Makefile ]) diff --git a/debian/changelog b/debian/changelog index 3e9f181..33a946c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,13 @@ +command (0.3) unstable; urgency=medium + + * Possibility to bind class method to parameter + * New examples + + -- Rafał Długołęcki Mon, 08 Feb 2016 22:06:13 +0100 + command (0.2.1) unstable; urgency=medium * Initial public release. * Added debian package building configuration - -- Rafał Długołęcki Wed, 20 May 2015 21:52:46 +0200 + -- Rafał Długołęcki Wed, 20 May 2015 21:52:46 +0200 diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 0000000..ece5a5b --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,18 @@ +noinst_PROGRAMS = \ + functions \ + methods + +AM_CXXFLAGS = -std=c++11 + +functions_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -Wall -pedantic -Wextra +functions_SOURCES = \ + functions.cpp + +methods_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -Wall -pedantic -Wextra +methods_SOURCES = \ + methods.cpp + diff --git a/examples/functions.cpp b/examples/functions.cpp new file mode 100644 index 0000000..df3ec47 --- /dev/null +++ b/examples/functions.cpp @@ -0,0 +1,55 @@ +#include +#include +#include + +#include "option.h" +#include "argument.h" +#include "required.h" +#include "multiValue.h" +#include "grouped.h" +#include "command.h" + +using namespace command; + +/** + * @file + * @brief Simple example explaining how to bind functions to command-line parameters + */ + +void argument_function(bool a) { + std::cout << "Argument: " << a << std::endl; +} + +void option_function(std::string a) { + std::cout << "Help function " << a << std::endl; +} + +void void_function(void) { + std::cout << "Void function " << std::endl; +} + +int main(int argc, char **argv) +{ + try { + Command command(argc, argv, { + // function with bool parameter + new Argument("Input values", argument_function), + + // function with std::string parameter + new Option("f", "Optional file", option_function), + + // function without parameter + new Option("h", "Help", void_function) + }); + + /* Code is initialized. + * + * You can run your main program e.g. here + */ + } + catch(const std::exception & e) { + std::cout << e.what() << std::endl; + } + + return 0; +} diff --git a/examples/methods.cpp b/examples/methods.cpp new file mode 100644 index 0000000..9a8735f --- /dev/null +++ b/examples/methods.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include "option.h" +#include "argument.h" +#include "required.h" +#include "multiValue.h" +#include "grouped.h" +#include "command.h" + +using namespace command; + +/** + * @file + * @brief Simple example explaining how to bind class methods to command-line parameters + */ + +class ExampleClass { +public: + void _argument(bool a) { + std::cout << "Argument: " << a << std::endl; + } + void _option(std::string a) { + std::cout << "Help function " << a << std::endl; + } + void _void(void) { + std::cout << "Void function " << std::endl; + } +}; + +int main(int argc, char **argv) +{ + ExampleClass c; + + try { + Command command(argc, argv, { + // class method with bool parameter + new Argument("Input values", std::bind(&ExampleClass::_argument, &c, std::placeholders::_1)), + + // class method std::string parameter + new Option("f", "Optional file", std::bind(&ExampleClass::_option, &c, std::placeholders::_1)), + + // class method without parameter + new Option("h", "Help", std::bind(&ExampleClass::_void, &c)) + }); + + /* Code is initialized. + * + * You can run your main program for example here + */ + } + catch(const std::exception & e) { + std::cout << e.what() << std::endl; + } + + return 0; +} -- 2.30.2