1 #ifndef __COMMAND_MULTIVALUE_H
2 #define __COMMAND_MULTIVALUE_H
11 * Multiple Value Parameter decorator. Allows Parameters to understand
16 * - multiValue: "0,1,2,3,4,5,6,7,8,9"
19 * - ./myprog ARGUMENT,ARGUMENT,ARGUMENT,ARGUMENT
20 * - ./myprog OPTION_NAME=VALUE,VALUE,VALUE,VALUE
22 class MultiValue : public Parameter {
25 * Parameter which will be treated as containing multiple values
27 Parameter * parameter;
29 std::vector<std::string> values;
31 std::string separator;
35 * Default constructor.
37 * @param parameter Parameter which will be treated as containing multiple values
39 MultiValue(std::string separator, Parameter * parameter)
40 : Parameter(parameter->describe()), parameter(parameter),
41 separator(separator) {
45 * Default destructor. Releases allocated memory
47 virtual ~MultiValue() {
52 * Wrapper method around passed Parameter::handle().
56 virtual void handle() {
57 for (std::string value : values) {
58 parameter->understand(value);
64 * Wrapper method around passed Parameter::understand()
66 * @param argv command line value against which test will be made
70 virtual bool understand(const std::string & value) {
73 bool _understand = true;
74 std::string prefix = "";
76 start = parameter->valuePosition(value);
78 if (start > value.size()) {
83 prefix = value.substr(0, ++start);// always count: "="
87 pos = value.find(separator, start);
88 values.push_back(prefix + value.substr(start, pos-start));
89 _understand &= parameter->understand(values.back());
96 } while ((pos != std::string::npos) && (start < value.size()));
101 * Wrapper method around passed Parameter::isRequired().
102 * Indicates if current Parameter is required.
104 * @return true if Parameter is required, false otherwise
106 virtual bool isRequired() {
107 return parameter->isRequired();
111 * Wrapper method around passed Parameter::isUsed().
115 virtual bool isUsed() {
116 return parameter->isUsed();
120 * Wrapper method around passed Parameter::valuePosition().
124 virtual unsigned int valuePosition(const std::string & value) {
125 return parameter->valuePosition(value);
130 #endif /* __COMMAND_MULTIVALUE_H */