+ std::string arg1 = "", arg2 = "";
+ if (!argumentExpression) { std::cerr << "Invalid argument expression: cannot register NULL literal on command-line" << std::endl; return; }
+
+ anna::Tokenizer expression;
+ expression.apply (argumentExpression, ",");
+ if (expression.size() > 2) { std::cerr << "Invalid argument expression '" << argumentExpression << "': only '<letter>[,<word>]' or '<word>[,<letter>]' are supported for command-line registration" << std::endl; return; }
+
+ anna::Tokenizer::const_iterator tok_it = expression.begin();
+ arg1 = anna::Tokenizer::data(tok_it);
+ // No leading hyphens in the name:
+ if (arg1[0] == '-') { std::cerr << "Invalid argument expression '" << argumentExpression << "': no leading hyphens allowed in argument names for command-line registration" << std::endl; return; }
+
+ tok_it++;
+ if (tok_it != expression.end()) {
+ arg2 = anna::Tokenizer::data(tok_it);
+ // No hyphens in the name:
+ if (arg2[0] == '-') { std::cerr << "Invalid argument expression '" << argumentExpression << "': no leading hyphens allowed in argument names for command-line registration" << std::endl; return; }
+ }
+
+ // swap to have first non empty:
+ if (arg1 == "") { arg1 = arg2; arg2 = ""; }
+
+ // If both provided, one will be single letter and the other, a word:
+ if (arg2 != "") {
+ int s1 = arg1.size();
+ int s2 = arg2.size();
+ if ((s1 + s2) == 2) { std::cerr << "Invalid argument expression '" << argumentExpression << "': only '<letter>[,<word>]' or '<word>[,<letter>]' are supported for command-line registration (provided two letters !)" << std::endl; return; }
+ if ((s1 != 1) && (s2 != 1)) { std::cerr << "Invalid argument expression '" << argumentExpression << "': only '<letter>[,<word>]' or '<word>[,<letter>]' are supported for command-line registration (provided two words !)" << std::endl; return; }
+ }
+
+ // assign:
+ a_arguments.push_back(new Variable(arg1, arg2, type, comment, needValue));
+}
+
+void CommandLine::initialize(const char** argv, const int argc, int positionalArguments)
+throw(RuntimeException) {
+ if (argc < 1) throw RuntimeException("Provided argc < 1 as command-line argv size !", ANNA_FILE_LOCATION);
+ if (positionalArguments < 0) throw RuntimeException("Provided negative number of positional arguments as command-line initializer", ANNA_FILE_LOCATION);
+ if (positionalArguments > (argc-1)) throw RuntimeException("Provided positional arguments > (argc - 1) as command-line initializer", ANNA_FILE_LOCATION);
+ a_positionalArguments = positionalArguments;
+ a_argv = argv;
+ a_argc = argc;
+ a_wasParsed = false;