Added examples for binding functions and methods v0.3 v0.3-deb
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Mon, 8 Feb 2016 21:13:29 +0000 (22:13 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Mon, 8 Feb 2016 21:13:29 +0000 (22:13 +0100)
ChangeLog
Makefile.am
configure.ac
debian/changelog
examples/Makefile.am [new file with mode: 0644]
examples/functions.cpp [new file with mode: 0644]
examples/methods.cpp [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9a2a0779cf839e98c906b192f5f42f697395930b 100644 (file)
--- 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)
index a3496141e4ff4c9835f406c58ddefd17e792ba3d..e10d5a8f1c8f8d129a495b29885710dcee4aeac8 100644 (file)
@@ -21,7 +21,7 @@ CLEANFILES = \
     %~ \
     doxyfile.stamp
 
-SUBDIRS = include . tests docs
+SUBDIRS = include . tests examples docs
 
 noinst_PROGRAMS = bin/command
 
index 988c0725d11efb548dc2e3b021c2893452f45df3..b990066154cb468a5fbbe8554b93dce04752e9b7 100644 (file)
@@ -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
 ])
 
index 3e9f18149cc9c25278b8950526c3f19b01ff6048..33a946cf99bec6c72d3d9056fbe7fc229d7bf486 100644 (file)
@@ -1,6 +1,13 @@
+command (0.3) unstable; urgency=medium
+
+  * Possibility to bind class method to parameter
+  * New examples
+
+ -- Rafał Długołęcki <rafal@dlugolecki.net.pl>  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 <rafal@yggdrasil>  Wed, 20 May 2015 21:52:46 +0200
+ -- Rafał Długołęcki <rafal@dlugolecki.net.pl>  Wed, 20 May 2015 21:52:46 +0200
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644 (file)
index 0000000..ece5a5b
--- /dev/null
@@ -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 (file)
index 0000000..df3ec47
--- /dev/null
@@ -0,0 +1,55 @@
+#include <iostream>
+#include <string>
+#include <functional>
+
+#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<bool>("Input values", argument_function),
+
+            // function with std::string parameter
+            new Option<std::string>("f", "Optional file", option_function),
+
+            // function without parameter
+            new Option<void>("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 (file)
index 0000000..9a8735f
--- /dev/null
@@ -0,0 +1,58 @@
+#include <iostream>
+#include <string>
+#include <functional>
+
+#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<bool>("Input values", std::bind(&ExampleClass::_argument, &c, std::placeholders::_1)),
+
+            // class method std::string parameter
+            new Option<std::string>("f", "Optional file", std::bind(&ExampleClass::_option, &c, std::placeholders::_1)),
+
+            // class method without parameter
+            new Option<void>("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;
+}