Added Argument template class
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Tue, 21 Apr 2015 23:18:35 +0000 (01:18 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Tue, 21 Apr 2015 23:18:35 +0000 (01:18 +0200)
include/argument.h [new file with mode: 0644]

diff --git a/include/argument.h b/include/argument.h
new file mode 100644 (file)
index 0000000..6a292b4
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef __COMMAND_ARGUMENT_H
+#define __COMMAND_ARGUMENT_H
+
+#include <string>
+
+#include <command/descriptive.h>
+
+namespace command {
+    /**
+     * Class responsible for handling commandline arguments.
+     * Arguments are required non-named parameters for program.
+     *
+     * Example:
+     *  ./myprog ARGUMENT
+     */
+    template<typename ArgumentType>
+    class Argument : public Descriptive {
+    public:
+        typedef void (*)(ArgumentType) FunctionType;
+
+    protected:
+        /**
+         * Function handling user Arguments
+         */
+        FunctionType function;
+
+    public:
+        /**
+         * 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) {
+        }
+
+        /**
+         * Executes command binded with argument
+         *
+         * @param value Value passed to program argument
+         */
+        void run(ArgumentType value) {
+            this->function(value);
+        }
+    };
+}
+
+#endif /* __COMMAND_ARGUMENT_H */