5#ifndef MADNESS_COMMANDLINEPARSER_H
6#define MADNESS_COMMANDLINEPARSER_H
17 std::map<std::string, std::string>
keyval;
27 std::vector<std::string> allArgs_raw(argv, argv + argc);
28 allArgs_raw.erase(allArgs_raw.begin());
29 for (
auto &
a : allArgs_raw) {
33 std::replace_copy(
a.begin(),
a.end(),
a.begin(),
'=',
' ');
35 std::stringstream sa(
a);
37 val=
a.substr(key.size());
38 if (key==
"input")
set_keyval(
"user_defined_input_file",
"1");
50 for (
auto&[key, val] :
keyval) {
51 printf(
"%20s %20s \n", key.c_str(), val.c_str());
59 std::string
value(
const std::string key)
const {
72 if (line[0]==
'-')
return line;
73 auto words=
split(line,
"=");
74 if (words.size()==1) line=
"input="+line;
78 static std::string
tolower(std::string s) {
79 std::transform(s.begin(), s.end(), s.begin(), [](
unsigned char c){ return std::tolower(c); });
86 static std::vector<std::string>
split(std::string s,
const std::string delimiter) {
89 std::vector<std::string> result;
90 while ((pos = s.find(delimiter)) != std::string::npos) {
91 token = s.substr(0, pos);
92 result.push_back(token);
93 s.erase(0, pos + delimiter.length());
100 std::size_t first=
arg.find_first_not_of(
'-');
101 return arg.substr(first);
105 std::string result=
arg;
106 const std::string item=
"=";
107 const std::string blank=
" ";
108 auto it=std::find_first_of(result.begin(),result.end(),item.begin(),item.end());
109 std::replace(it,it+1,item.front(),blank.front());
115 std::string str2 =
arg;
116 str2.erase(std::remove_if(str2.begin(), str2.end(),
117 [](
unsigned char x){return std::isspace(x);}),str2.end());
123 if (
arg.size()==0)
return arg;
124 std::size_t first=
arg.find_first_not_of(
' ');
125 std::size_t last=
arg.find_last_not_of(
' ');
126 return arg.substr(first,last-first+1);
129 static std::string
base_name(std::string
const &
path, std::string
const & delims =
"/")
131 return path.substr(
path.find_last_of(delims) + 1);
136 std::size_t
p=
filename.find_last_of(
'.');
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
std::filesystem::path path
Definition excited_state_calc.cpp:25
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition tensor.h:2502
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
static const char * filename
Definition legendre.cc:96
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
very simple command line parser
Definition commandlineparser.h:15
static std::string trim_blanks(const std::string arg)
remove blanks at the beginning and the end only
Definition commandlineparser.h:122
std::string value(const std::string key) const
Definition commandlineparser.h:59
void set_keyval(const std::string key, const std::string value)
Definition commandlineparser.h:64
bool key_exists(std::string key) const
Definition commandlineparser.h:55
std::map< std::string, std::string > keyval
Definition commandlineparser.h:17
static std::string base_name(std::string const &path, std::string const &delims="/")
Definition commandlineparser.h:129
static std::string tolower(std::string s)
make lower case
Definition commandlineparser.h:78
void set_defaults()
set default values from the command line
Definition commandlineparser.h:44
commandlineparser(int argc, char **argv)
Definition commandlineparser.h:25
static std::string remove_first_equal(const std::string arg)
Definition commandlineparser.h:104
static std::string remove_extension(std::string const &filename)
Definition commandlineparser.h:134
static std::string remove_blanks(const std::string arg)
remove all blanks
Definition commandlineparser.h:114
commandlineparser()
Definition commandlineparser.h:19
std::string check_for_input_file(std::string line)
special option: the input file has no hyphens in front and is just a value
Definition commandlineparser.h:71
void print_map() const
Definition commandlineparser.h:49
static std::string remove_front_hyphens(const std::string arg)
Definition commandlineparser.h:99
static std::vector< std::string > split(std::string s, const std::string delimiter)
split a string s into a vector of strings, using delimiter
Definition commandlineparser.h:86