Possibility to pass class method reference
[command.git] / include / argument.h
index 5690e5dbf6ba2973147535ce32d66459ad23dd95..2cd3c300f970a8d2e205de7685a6f10fd9ad241d 100644 (file)
@@ -4,6 +4,7 @@
 #include <string>
 #include <sstream>
 #include <iostream>
+#include <functional>
 
 #include "parameter.h"
 #include "callable.h"
@@ -35,6 +36,10 @@ namespace command {
             : Parameter(description), Callable<ParameterType>(function) {
         }
 
+        Argument(const std::string & description, std::function<void(ParameterType)> function)
+            : Parameter(description), Callable<ParameterType>(function) {
+        }
+
         /**
          *
          */
@@ -45,6 +50,7 @@ namespace command {
          */
         virtual void handle() {
             this->call(value);
+            this->used = true;
         }
 
         /**
@@ -64,20 +70,24 @@ namespace command {
          *  against next value.
          */
         virtual bool understand(const std::string & argv) {
-            if (!isUsed()) {
-                std::stringstream ss;
+            std::stringstream ss;
 
-                ss << argv;
-                ss >> value;
+            ss << std::fixed << argv;
+            ss >> value;
 
-                if (!ss.fail()) {
-                    this->used = true;
-                    return true;
-                }
+            if (!ss.fail()) {
+                return true;
             }
 
             return false;
         }
+
+        /**
+         * \inheritdoc
+         */
+        virtual unsigned int valuePosition(const std::string & ) {
+            return 0;
+        }
     };
 }