Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions common/arguments.cxx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>
#include <iostream>
#include <cstdlib>

using namespace std;

bool argument_exists(vector<string> arguments, string argument) {
for (unsigned int i = 0; i < arguments.size(); i++) {
if (argument.compare(arguments.at(i)) == 0) {
// cerr << "parsed argument '" << argument << "' successfully." << endl;
// cerr << "parsed argument '" << argument << "' successfully." << endl;
return true;
}
}
return false;
}

// template <>
// bool get_argument<string>(vector<string> arguments, string argument, bool required, string &result) {
bool get_argument(vector<string> arguments, string argument, bool required, string& result) {
//template <>
//bool get_argument<string>(vector<string> arguments, string argument, bool required, string &result) {
bool get_argument(vector<string> arguments, string argument, bool required, string &result) {
bool found = false;
for (unsigned int i = 0; i < arguments.size(); i++) {
if (argument.compare(arguments.at(i)) == 0) {
Expand All @@ -33,19 +33,20 @@ bool get_argument(vector<string> arguments, string argument, bool required, stri
}

if (found) {
// cerr << "parsed argument '" << argument << "' successfully: " << result << endl;
// cerr << "parsed argument '" << argument << "' successfully: " << result << endl;
}
return found;
}

// template <>
// bool get_argument_vector<string>(vector<string> arguments, string argument, bool required, vector<string> &results) {
bool get_argument_vector(vector<string> arguments, string argument, bool required, vector<string>& results) {

//template <>
//bool get_argument_vector<string>(vector<string> arguments, string argument, bool required, vector<string> &results) {
bool get_argument_vector(vector<string> arguments, string argument, bool required, vector<string> &results) {
bool found = false;
for (unsigned int i = 0; i < arguments.size(); i++) {
if (argument.compare(arguments.at(i)) == 0) {
i++;
while (i < arguments.size() && arguments.at(i).substr(0, 2).compare("--") != 0) {
while (i < arguments.size() && arguments.at(i).substr(0,2).compare("--") != 0) {
results.push_back(arguments.at(i++));
}
found = true;
Expand All @@ -69,3 +70,5 @@ bool get_argument_vector(vector<string> arguments, string argument, bool require
}
return found;
}


29 changes: 15 additions & 14 deletions common/arguments.hxx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#ifndef GIBBS_ARGUMENTS_H
#define GIBBS_ARGUMENTS_H

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>
#include <sstream>
#include <cstdlib>

using namespace std;

bool argument_exists(vector<string> arguments, string argument);

template <typename T>
bool get_argument_vector(vector<string> arguments, string argument, bool required, vector<T>& results) {
bool get_argument_vector(vector<string> arguments, string argument, bool required, vector<T> &results) {
bool found = false;
for (unsigned int i = 0; i < arguments.size(); i++) {
if (argument.compare(arguments.at(i)) == 0) {
i++;
while (i < arguments.size() && arguments.at(i).substr(0, 2).compare("--") != 0) {
while (i < arguments.size() && arguments.at(i).substr(0,2).compare("--") != 0) {
T result;
if (!(stringstream(arguments.at(i++)) >> result)) {
if ( !(stringstream(arguments.at(i++)) >> result) ) {
cerr << "ERROR: invalid argument '" << argument << "': " << arguments.at(i) << endl;
exit(1);
}
Expand Down Expand Up @@ -46,16 +46,16 @@ bool get_argument_vector(vector<string> arguments, string argument, bool require
return found;
}

bool get_argument_vector(vector<string> arguments, string argument, bool required, vector<string>& results);
bool get_argument_vector(vector<string> arguments, string argument, bool required, vector<string> &results);

bool get_argument(vector<string> arguments, string argument, bool required, string& result);
bool get_argument(vector<string> arguments, string argument, bool required, string &result);

template <typename T>
bool get_argument(vector<string> arguments, string argument, bool required, T& result) {
bool get_argument(vector<string> arguments, string argument, bool required, T &result) {
bool found = false;
for (unsigned int i = 0; i < arguments.size(); i++) {
if (argument.compare(arguments.at(i)) == 0) {
if (!(stringstream(arguments.at(++i)) >> result)) {
if ( !(stringstream(arguments.at(++i)) >> result) ) {
cerr << "ERROR: invalid argument '" << argument << "': " << arguments.at(i) << endl;
exit(1);
}
Expand All @@ -70,21 +70,22 @@ bool get_argument(vector<string> arguments, string argument, bool required, T& r
}

if (found) {
// cerr << "parsed argument '" << argument << "' successfully: " << result << endl;
// cerr << "parsed argument '" << argument << "' successfully: " << result << endl;
}
return found;
}


template <typename T1, typename T2>
bool get_arguments(vector<string> arguments, string argument, bool required, T1& result1, T2& result2) {
bool get_arguments(vector<string> arguments, string argument, bool required, T1 &result1, T2 &result2) {
bool found = false;
for (unsigned int i = 0; i < arguments.size(); i++) {
if (argument.compare(arguments.at(i)) == 0) {
if (!(stringstream(arguments.at(++i)) >> result1)) {
if ( !(stringstream(arguments.at(++i)) >> result1) ) {
cerr << "ERROR: invalid argument '" << argument << "': " << arguments.at(i) << endl;
exit(1);
}
if (!(stringstream(arguments.at(++i)) >> result2)) {
if ( !(stringstream(arguments.at(++i)) >> result2) ) {
cerr << "ERROR: invalid argument '" << argument << "': " << arguments.at(i) << endl;
exit(1);
}
Expand All @@ -99,7 +100,7 @@ bool get_arguments(vector<string> arguments, string argument, bool required, T1&
}

if (found) {
// cerr << "parsed argument '" << argument << "' successfully: " << result1 << " " << result2 << endl;
// cerr << "parsed argument '" << argument << "' successfully: " << result1 << " " << result2 << endl;
}
return found;
}
Expand Down
Loading