-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples for binding functions and methods
- Loading branch information
Rafał Długołęcki
committed
Feb 8, 2016
1 parent
6029eb4
commit 5d3d8cf
Showing
7 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## [0.3] - 2016-02-08 | ||
### Added | ||
- Possibility to bind class method to parameter | ||
- Examples (check examples dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |