Command  0.3
argument.h
1#ifndef __COMMAND_ARGUMENT_H
2#define __COMMAND_ARGUMENT_H
3
4#include <string>
5#include <sstream>
6#include <iostream>
7#include <functional>
8
9#include "parameter.h"
10#include "callable.h"
11
12namespace command {
22 template<typename ParameterType>
23 class Argument : public Parameter, public Callable<ParameterType> {
24 protected:
25 ParameterType value;
26 public:
27 typedef class Argument Type;
28
35 Argument(const std::string & description, std::function<void(ParameterType)> function)
36 : Parameter(description), Callable<ParameterType>(function) {
37 }
38
42 virtual ~Argument() { }
43
47 virtual void handle() {
48 this->call(value);
49 this->used = true;
50 }
51
68 virtual bool understand(const std::string & argv) {
69 std::stringstream ss;
70
71 ss << std::fixed << argv;
72 ss >> value;
73
74 if (!ss.fail()) {
75 return true;
76 }
77
78 return false;
79 }
80
84 virtual unsigned int valuePosition(const std::string & ) {
85 return 0;
86 }
87 };
88}
89
90#endif /* __COMMAND_ARGUMENT_H */
Definition: argument.h:23
virtual bool understand(const std::string &argv)
Definition: argument.h:68
virtual void handle()
Definition: argument.h:47
Argument(const std::string &description, std::function< void(ParameterType)> function)
Definition: argument.h:35
virtual unsigned int valuePosition(const std::string &)
Definition: argument.h:84
Definition: callable.h:12
void call(ParameterType value)
Definition: callable.h:37
Definition: parameter.h:17
bool used
Definition: parameter.h:20