SUBDIRS = include . tests
-noinst_PROGRAMS = bin_command
+noinst_PROGRAMS = bin/command
dist_noinst_SCRIPTS = autogen.sh
AC_CONFIG_HEADERS([config.h])
AC_PROG_CXX
AC_CONFIG_FILES([
+ include/Makefile
Makefile
+ tests/Makefile
])
-# include/Makefile
-# tests/Makefile
# docs/Makefile
AC_OUTPUT
--- /dev/null
+nobase_pkginclude_HEADERS = \
+ descriptive.h \
+ argument.h \
+ option.h \
+ command.h
#define __COMMAND_ARGUMENT_H
#include <string>
+#include <iostream>
-#include <command/descriptive.h>
+#include "parameter.h"
+#include "callable.h"
namespace command {
/**
* ./myprog ARGUMENT
*/
template<typename ArgumentType>
- class Argument : public Descriptive {
- public:
- typedef void (*)(ArgumentType) FunctionType;
-
- protected:
- /**
- * Function handling user Arguments
- */
- FunctionType function;
-
+ class Argument : public Parameter, public Callable<ArgumentType> {
public:
+ typedef class Argument Type;
/**
* Default constructor.
*
* @param description Description of current Argument
* @param function Function used to handle current Argument.
*/
- Argument(std::string description, FunctionType function)
- : Descriptive(description), function(function) {
+ Argument(std::string description, void (*function)(ArgumentType))
+ : Parameter(description), Callable<ArgumentType>(function) {
}
+ virtual ~Argument() { }
- /**
- * Executes command binded with argument
- *
- * @param value Value passed to program argument
- */
- void run(ArgumentType value) {
- this->function(value);
+ virtual void handle() {
+ std::cout << "Argument::handle()" << std::endl;
+ this->call(std::string("A"));
}
};
}
--- /dev/null
+#ifndef __COMMAND_CALLABLE_H
+#define __COMMAND_CALLABLE_H
+
+#include <string>
+
+namespace command {
+ /**
+ * Callable behaviour class.
+ */
+ template<typename ArgumentType>
+ class Callable {
+ protected:
+ /**
+ * Function handling user Arguments
+ */
+ void (*func)(ArgumentType);
+
+ public:
+ /**
+ * Default constructor.
+ *
+ * @param function Function that will be invoked
+ */
+ Callable(void (*function)(ArgumentType))
+ : func(function) {
+ }
+ virtual ~Callable() { }
+
+ protected:
+ /**
+ * Executes command binded with argument
+ *
+ * @param value Value passed to program argument
+ */
+ void call(ArgumentType value) {
+ this->func(value);
+ }
+ };
+}
+
+#endif /* __COMMAND_DESCRIPTIVE_H */
--- /dev/null
+#ifndef __COMMAND_COMMAND_H
+#define __COMMAND_COMMAND_H
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include "parameter.h"
+
+namespace command {
+ /**
+ * Main class for handling user passed parameters from command line.
+ */
+ class Command {
+ protected:
+ unsigned int argc;
+ std::vector<std::string> _argv;
+ std::vector<Parameter *> args;
+ public:
+ /**
+ * Default constructor.
+ *
+ * @param
+ * @param
+ * @param
+ */
+ Command(unsigned int argc, char *argv[], std::initializer_list<Parameter *> params)
+ : args(params) {
+ for(Parameter *param : params) {
+ std::cout << "Command foreach" << std::endl;
+ param->handle();
+ }
+ }
+
+ ~Command() {
+ for (Parameter * parameter : args) {
+ delete parameter;
+ }
+ }
+ };
+}
+
+#endif /* __COMMAND_COMMAND_H */
#ifndef __COMMAND_OPTION_H
#define __COMMAND_OPTION_H
+#include <string>
+
+#include "argument.h"
+
namespace command {
/**
* Class responsible for handling commandline options.
template<typename OptionType>
class Option
: Argument<OptionType> {
+ public:
+// typedef typename Argument<OptionType, Lambda>::FunctionType FunctionType;
protected:
/**
* Option name
* @param description Description of current Option
* @param function Function used to handle current Option.
*/
- Argument(std::string name, std::string description, FunctionType function)
+ Option(std::string name, std::string description, void (*function)(OptionType))
: name(name), Argument<OptionType>(description, function) {
}
+ virtual ~Option() { }
+
+ virtual void handle() {
+ }
};
}
--- /dev/null
+#ifndef __COMMAND_PARAMETER_H
+#define __COMMAND_PARAMETER_H
+
+#include <string>
+
+#include "descriptive.h"
+#include "callable.h"
+
+namespace command {
+ /**
+ * Class responsible for handling commandline arguments.
+ * Arguments are required,x non-named parameters of program.
+ *
+ * Example:
+ * ./myprog ARGUMENT
+ */
+ class Parameter : public Descriptive {
+ public:
+ typedef class Parameter Type;
+ /**
+ * Default constructor.
+ *
+ * @param description Description of current Argument
+ */
+ Parameter(std::string description)
+ : Descriptive(description) {
+ }
+ virtual ~Parameter() {}
+
+ virtual void handle() {
+ std::cout << "Parameter::handle()" << std::endl;
+ };
+ };
+}
+
+#endif /* __COMMAND_PARAMETER_H */
+#include <iostream>
+#include <string>
-int main() {
+#include "option.h"
+#include "argument.h"
+#include "command.h"
+
+
+int main(int argc, char *argv[]) {
command::Command command(argc, argv, {
- command::Option<std::string>("f", "File path", [](std::string value)->void { cout << "Sth: " << value << endl; }),
- command::Argument<std::string>("File path", []()->void { cout << "Sth: " << value << endl; }),
- command::Option<void>("help", "Help description", [](void)->void { cout << "Sth: " << value << endl; }),
- command::Option<void>("verbose", "Verbose option description", &myClass->verbose)
+ new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
+ new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
+ new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
+ new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
+ new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; })
});
return 0;