Skip to content

Commit 4f381dc

Browse files
Updating OptionParser to allow for returning the vector rather than output parameters
1 parent 5b76fd5 commit 4f381dc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

OptionParser.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ read_config_file(const string &config_filename,
407407
}
408408
}
409409

410-
void
411-
OptionParser::parse(const int argc, const char **argv,
412-
vector<string> &arguments) {
410+
vector<string>
411+
OptionParser::parse(const int argc, const char **argv) {
413412
// The "2" below corresponds to the "about" and "help" options
414413
assert(options.size() >= 2);
415414

415+
vector<string> arguments;
416+
416417
// The '1' and '+ 1' below is to skip over the program name
417-
arguments.clear();
418418
assert(argc >= 1);
419419
copy(argv + 1, argv + argc, back_inserter(arguments));
420420

@@ -449,6 +449,13 @@ OptionParser::parse(const int argc, const char **argv,
449449
first_missing_option_name = options[i].format_option_name();
450450

451451
leftover_args = arguments;
452+
return arguments;
453+
}
454+
455+
void
456+
OptionParser::parse(const int argc, const char **argv,
457+
vector<string> &arguments) {
458+
arguments = parse(argc, argv);
452459
}
453460

454461
void

OptionParser.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class OptionParser {
110110
void parse(const int argc, const char **argv,
111111
std::vector<std::string> &arguments);
112112

113+
std::vector<std::string>
114+
parse(const int argc, const char **argv);
115+
113116
void parse(const int argc, const char **argv,
114117
std::vector<std::string> &arguments,
115118
std::string config_filename);

0 commit comments

Comments
 (0)