8#ifndef _AUROSTD_ARGV_CPP_
9#define _AUROSTD_ARGV_CPP_
31#define VERBOSE_ARGV false
37 string attach(
const string& s1,
const string& s2) {
40 string attach(
const string& s1,
const string& s2,
const string& s3) {
41 return s1 +
"|" + s2 +
"|" + s3;
43 string attach(
const string& s1,
const string& s2,
const string& s3,
const string& s4) {
44 return s1 +
"|" + s2 +
"|" + s3 +
"|" + s4;
46 string attach(
const string& s1,
const string& s2,
const string& s3,
const string& s4,
const string& s5) {
47 return s1 +
"|" + s2 +
"|" + s3 +
"|" + s4 +
"|" + s5;
58 vector<string> out_argv;
59 for (
int i = 0; i < _argc; i++) {
60 string argi(_argv[i]);
61 if (argi ==
"-np" || argi ==
"-npmax") {
62 argi = string(
"-") + argi;
64 if (argi ==
"-f" || argi ==
"-F") {
65 argi = string(
"-") + argi;
67 if (argi ==
"-d" || argi ==
"-D") {
68 argi = string(
"-") + argi;
70 if (argi.size() >= 2) {
71 if (argi[0] ==
'-' && argi[1] ==
'n') {
72 argi = string(
"-") + argi;
76 if (argi.size() >= 2) {
77 if (argi[0] ==
'-' && argi[1] ==
'f') {
78 argi = string(
"-") + argi;
81 if (argi.size() >= 2) {
82 if (argi[0] ==
'-' && argi[1] ==
'F') {
83 argi = string(
"-") + argi;
86 if (argi.size() >= 2) {
87 if (argi[0] ==
'-' && argi[1] ==
'd') {
88 argi = string(
"-") + argi;
91 if (argi.size() >= 2) {
92 if (argi[0] ==
'-' && argi[1] ==
'D') {
93 argi = string(
"-") + argi;
97 if (argi ==
"--machine") {
100 if (argi ==
"--machine_name") {
103 if (argi ==
"--aflowlib") {
106 if (argi ==
"--np") {
109 if (argi.at(argi.size() - 1) ==
'=' && i < _argc - 1) {
110 argi += string(_argv[i + 1]);
113 out_argv.push_back(argi);
116 for (
size_t i = 0; i < out_argv.size(); i++) {
117 cerr <<
"out_argv.at(" << i <<
")=" << out_argv[i] << endl;
128 bool args2flag(
const vector<string>& argv,
const string& s0) {
131 vector<string> tokens;
134 for (
size_t j = 0; j < tokens.size(); j++) {
135 cerr <<
"[" << tokens[j] <<
"]" << endl;
138 for (
size_t j = 0; j < tokens.size(); j++) {
139 for (
size_t i = 0; i < argv.size(); i++) {
140 if (argv[i] == tokens[j]) {
148 bool args2flag(
const vector<string>& argv, std::vector<string>& cmds,
const string& s0) {
151 vector<string> tokens;
154 for (
size_t j = 0; j < tokens.size(); j++) {
155 cerr <<
"[" << tokens[j] <<
"]" << endl;
158 for (
size_t j = 0; j < tokens.size(); j++) {
159 cmds.push_back(tokens[j]);
161 for (
size_t i = 0; i < argv.size(); i++) {
162 for (
size_t j = 0; j < tokens.size(); j++) {
163 if (argv[i] == tokens[j]) {
177 template <
class utype> utype
args2utype(
const vector<string>& argv,
const string& s0, utype def_out) {
180 vector<string> tokens;
183 for (
size_t j = 0; j < tokens.size(); j++) {
184 cerr <<
"[" << tokens[j] <<
"]" << endl;
188 for (
size_t i = 1; i < argv.size() - 1; i++) {
189 for (
size_t j = 0; j < tokens.size(); j++) {
190 if (argv[i] == tokens[j]) {
192 out = (utype) atof(argv.at(i + 1).c_str());
194 out = (utype) atoi(argv.at(i + 1).c_str());
201#define AST_TEMPLATE(atype) template atype args2utype(const vector<string>&, const string&, atype);
213 vector<string> tokens;
216 for (
size_t j = 0; j < tokens.size(); j++) {
217 cerr <<
"[" << tokens[j] <<
"]" << endl;
222 for (
size_t i = 0; i < argv.size(); i++) {
223 if (i + out.
rows < argv.size()) {
224 for (
size_t j = 0; j < tokens.size(); j++) {
225 if (argv[i] == tokens[j]) {
226 for (
int k = 0; k < out.
rows; k++) {
228 out(k + out.
lrows) = (utype) atof(argv.at(i + k + 1).c_str());
230 out(k + out.
lrows) = (utype) atoi(argv.at(i + k + 1).c_str());
239#define AST_TEMPLATE(atype) template xvector<atype> args2xvectorutype(const vector<string>&, const string&, const xvector<atype>&);
246 vector<string> tokens;
249 for (
size_t j = 0; j < tokens.size(); j++) {
250 cerr <<
"[" << tokens[j] <<
"]" << endl;
254 for (
size_t i = 0; i < argv.size(); i++) {
255 if (i + out.
rows < argv.size()) {
256 for (
size_t j = 0; j < tokens.size(); j++) {
257 if (argv[i] == tokens[j]) {
258 for (
int k = 0; k < out.
rows; k++) {
260 out(k + out.
lrows) = (utype) atof(argv.at(i + k + 1).c_str());
262 out(k + out.
lrows) = (utype) atoi(argv.at(i + k + 1).c_str());
271#define AST_TEMPLATE(atype) template xvector<atype> args2xvectorutype(const vector<string>&, const string&, int);
280 template <
class utype> vector<utype>
args2vectorutype(
const vector<string>& argv,
const string& s0) {
283 vector<string> tokens;
286 for (
size_t j = 0; j < tokens.size(); j++) {
287 cerr <<
"[" << tokens[j] <<
"]" << endl;
291 for (
size_t i = 0; i < argv.size(); i++) {
292 for (
size_t j = 0; j < tokens.size(); j++) {
293 if (argv[i] == tokens[j]) {
294 for (
size_t k = 0; k < argv.size(); k++) {
296 out.push_back((utype) atof(argv.at(i + k + 1).c_str()));
298 out.push_back((utype) atoi(argv.at(i + k + 1).c_str()));
307 template <
class utype> deque<utype>
args2dequeutype(
const deque<string>& argv,
const string& s0) {
310 deque<string> tokens;
313 for (
size_t j = 0; j < tokens.size(); j++) {
314 cerr <<
"[" << tokens[j] <<
"]" << endl;
318 for (
size_t i = 0; i < argv.size(); i++) {
319 for (
size_t j = 0; j < tokens.size(); j++) {
320 if (argv[i] == tokens[j]) {
321 for (
size_t k = 0; k < argv.size(); k++) {
323 out.push_back((utype) atof(argv.at(i + k + 1).c_str()));
325 out.push_back((utype) atoi(argv.at(i + k + 1).c_str()));
339 string args2string(
const vector<string>& argv,
const string& s0,
const string& s_def) {
342 vector<string> tokens;
345 for (
size_t j = 0; j < tokens.size(); j++) {
346 cerr <<
"[" << tokens[j] <<
"]" << endl;
349 for (
size_t i = 0; i < argv.size() - 1; i++) {
350 for (
size_t j = 0; j < tokens.size(); j++) {
351 if (argv[i] == tokens[j]) {
352 return argv.at(i + 1);
359 string args2string(
const vector<string>& argv, vector<string>& cmds,
const string& s0,
const string& s_def) {
362 vector<string> tokens;
365 for (
size_t j = 0; j < tokens.size(); j++) {
366 cerr <<
"[" << tokens[j] <<
"]" << endl;
369 for (
size_t j = 0; j < tokens.size(); j++) {
370 cmds.push_back(tokens[j]);
372 for (
size_t i = 0; i < argv.size() - 1; i++) {
373 for (
size_t j = 0; j < tokens.size(); j++) {
374 if (argv[i] == tokens[j]) {
375 return argv.at(i + 1);
388 vector<string> str_out;
389 str_out.push_back(str_in);
393 vector<string>
args2vectorstring(
const vector<string>& argv,
const string& s0,
const string& s_def) {
396 vector<string> tokens;
399 for (
size_t j = 0; j < tokens.size(); j++) {
400 cerr <<
"[" << tokens[j] <<
"]" << endl;
403 for (
size_t i = 0; i < argv.size() - 1; i++) {
404 for (
size_t j = 0; j < tokens.size(); j++) {
405 if (argv[i] == tokens[j]) {
406 return vector<string>(argv.begin() + (i + 1), argv.end());
420 const string message =
"not ported to \"|\"";
439 if (tokens.empty()) {
476 if (tokens.empty()) {
523 if (tokens.empty()) {
581 if (tokens.empty()) {
599 vector<string> tokens;
602 for (
size_t j = 0; j < tokens.size(); j++) {
603 cerr <<
"[" << tokens[j] <<
"]" << endl;
606 for (
size_t i = 0; i < argv.size(); i++) {
607 for (
size_t j = 0; j < tokens.size(); j++) {
616 bool args2attachedflag(
const vector<string>& argv, std::vector<string>& cmds,
const string& s0) {
619 vector<string> tokens;
622 for (
size_t j = 0; j < tokens.size(); j++) {
623 cerr <<
"[" << tokens[j] <<
"]" << endl;
626 for (
size_t j = 0; j < tokens.size(); j++) {
627 cmds.push_back(tokens[j]);
629 for (
size_t i = 0; i < argv.size(); i++) {
630 for (
size_t j = 0; j < tokens.size(); j++) {
648 vector<string> tokens;
651 cerr <<
"argv.size()=" << argv.size() << endl;
652 for (
size_t j = 0; j < argv.size(); j++) {
653 cerr <<
"[" << argv[j] <<
"]" << endl;
657 cerr <<
"tokens.size()=" << tokens.size() << endl;
658 for (
size_t j = 0; j < tokens.size(); j++) {
659 cerr <<
"[" << tokens[j] <<
"]" << endl;
662 for (
size_t i = 1; i < argv.size(); i++) {
663 for (
size_t j = 0; j < tokens.size(); j++) {
664 if (argv[i].find(tokens[j]) != string::npos) {
665 output = argv[i].substr(argv[i].find(tokens[j]) + tokens[j].length());
666 if (!output.empty()) {
675 template <
typename string>
string args2attachedutype(
const vector<string>& argv,
const string& s0,
const string& s_def) {
679 vector<string> tokens;
682 cerr <<
"argv.size()=" << argv.size() << endl;
683 for (
size_t j = 0; j < argv.size(); j++) {
684 cerr <<
"[" << argv[j] <<
"]" << endl;
688 cerr <<
"tokens.size()=" << tokens.size() << endl;
689 for (
size_t j = 0; j < tokens.size(); j++) {
690 cerr <<
"[" << tokens[j] <<
"]" << endl;
693 for (
size_t i = 1; i < argv.size(); i++) {
694 for (
size_t j = 0; j < tokens.size(); j++) {
695 if (argv[i].find(tokens[j]) != string::npos) {
696 return argv[i].substr(argv[i].find(tokens[j]) + tokens[j].length());
708 template <
typename utype> utype
args2attachedutype(
const vector<string>& argv,
const string& str1,
const utype& utype_default) {
710 vector<string> tokens1;
713 cerr <<
"argv.size()=" << argv.size() << endl;
714 for (
size_t j = 0; j < argv.size(); j++) {
715 cerr <<
"[" << argv[j] <<
"]" << endl;
719 cerr <<
"tokens1.size()=" << tokens1.size() << endl;
720 for (
size_t j = 0; j < tokens1.size(); j++) {
721 cerr <<
"[" << tokens1[j] <<
"]" << endl;
724 utype out = utype_default;
725 for (
size_t j = 0; j < tokens1.size(); j++) {
726 string s1 = tokens1[j];
737 vector<string> tokens2;
739 if (!tokens2.empty()) {
747#define AST_TEMPLATE(atype) template atype args2attachedutype(const vector<string>&, const string&, const atype&);
This file contains the preprocessor macros to ensure a proper instantiation of all aurostd functions.
#define AST_GEN_1(type_selection)
autogenerate 1D code based on AST_TEMPLATE
string RemoveSubString(const string &str_orig, const string &str_rm) __xprototype
void StringSubstInPlace(string &work_string, const string &old_string, const string &new_string)
substitute parts of a strings in place
xvector< utype > args2xvectorutype(const vector< string > &argv, const string &s0, const xvector< utype > &def_out)
deque< utype > args2dequeutype(const deque< string > &argv, const string &s0)
uint string2tokens(const string &str, vector< string > &tokens, const string &delimiters=" ", bool consecutive=false) __xprototype
string RemoveSpaces(const string &s) __xprototype
bool get_itemized_vector_string_from_input(const vector< string > &argv, const string &s0, vector< string > &tokens, const string &delimiter)
utype string2utype(const string &from, const uint base=10)
string attach(const string &s1)
bool args2flag(const vector< string > &argv, const string &s0)
vector< string > get_arguments_from_input(int _argc, char **_argv)
vector< string > string2vstring(const string &str_in)
string args2string(const vector< string > &argv, const string &s0, const string &s_def)
string args2attachedutype(const vector< string > &argv, const string &s0, const string &s_def)
utype args2utype(const vector< string > &argv, const string &s0, utype def_out)
vector< utype > args2vectorutype(const vector< string > &argv, const string &s0)
bool args2attachedflag(const vector< string > &argv, const string &s0)
string args2attachedstring(const vector< string > &argv, const string &s0, string s_def)
vector< string > args2vectorstring(const vector< string > &argv, const string &s0, const string &s_def)
string RemoveWhiteSpaces(const string &s) __xprototype
bool substring2bool(const string &strstream, const string &strsub1, bool RemoveWS=false, bool RemoveComments=true)