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) {
71 size_t start = parameter->valuePosition(value);
73 bool _understand = true;
74 std::string prefix = "";
77 prefix = value.substr(0, ++start);// always count: "="
81 pos = value.find(separator, start);
82 values.push_back(prefix + value.substr(start, pos-start));
83 _understand &= parameter->understand(values.back());
85 } while ((pos != std::string::npos) && (start < value.size()));
91 * Wrapper method around passed Parameter::isRequired().
92 * Indicates if current Parameter is required.
94 * @return true if Parameter is required, false otherwise
96 virtual bool isRequired() {
97 return parameter->isRequired();
101 * Wrapper method around passed Parameter::isUsed().
105 virtual bool isUsed() {
106 return parameter->isUsed();
110 * Wrapper method around passed Parameter::valuePosition().
114 virtual unsigned int valuePosition(const std::string & value) {
115 return parameter->valuePosition(value);
120 #endif /* __COMMAND_PARAMETER_H */