1 #ifndef __COMMAND_MULTIVALUE_H
2 #define __COMMAND_MULTIVALUE_H
10 * Multiple Value Parameter decorator. Allows Parameters to understand
15 * - multiValue: "0,1,2,3,4,5,6,7,8,9"
18 * - ./myprog ARGUMENT,ARGUMENT,ARGUMENT,ARGUMENT
19 * - ./myprog OPTION_NAME=VALUE,VALUE,VALUE,VALUE
21 class MultiValue : public Parameter {
24 * Parameter which will be treated as containing multiple values
26 Parameter * parameter;
28 std::vector<std::string> values;
30 std::string separator;
34 * Default constructor.
36 * @param parameter Parameter which will be treated as containing multiple values
38 MultiValue(std::string separator, Parameter * parameter)
39 : Parameter(parameter->describe()), parameter(parameter),
40 separator(separator) {
44 * Default destructor. Releases allocated memory
46 virtual ~MultiValue() {
51 * Wrapper method around passed Parameter::handle().
55 virtual void handle() {
56 for (std::string value : values) {
57 parameter->understand(value);
63 * Wrapper method around passed Parameter::understand()
65 * @param argv command line value against which test will be made
69 virtual bool understand(const std::string & value) {
70 size_t start = parameter->valuePosition(value);
72 bool _understand = true;
73 std::string prefix = "";
76 prefix = value.substr(0, ++start);// always count: "="
80 pos = value.find(separator, start);
81 values.push_back(prefix + value.substr(start, pos-start));
82 _understand &= parameter->understand(values.back());
84 } while ((pos != std::string::npos) && (start < value.size()));
90 * Wrapper method around passed Parameter::isRequired().
91 * Indicates if current Parameter is required.
93 * @return true if Parameter is required, false otherwise
95 virtual bool isRequired() {
96 return parameter->isRequired();
100 * Wrapper method around passed Parameter::isUsed().
104 virtual bool isUsed() {
105 return parameter->isUsed();
109 * Wrapper method around passed Parameter::valuePosition().
113 virtual unsigned int valuePosition(const std::string & value) {
114 return parameter->valuePosition(value);
119 #endif /* __COMMAND_PARAMETER_H */