10 const char *
id,
const char *procOrRole,
const char *
type,
const char *
value,
const char *delimeter) {
12 this->procOrRole = procOrRole;
14 this->scalarOrVector =
value;
15 this->delim = delimeter;
18 Parameter::Parameter(
const char *
id,
19 const char *procOrRole,
22 const vector<string> &
rows,
23 const char *delimeter) {
25 this->procOrRole = procOrRole;
28 map<int, string> colIndexToName;
29 unique_ptr<char, void (*)(void *)>
copy(strdup(columns), free);
30 unsigned long nItems = 0;
32 for (
const char *
item = strtok_r(copy.get(), delimeter, &saveptr);
item !=
nullptr;
33 item = strtok_r(
nullptr, delimeter, &saveptr), nItems++) {
35 size_t pos = 0, len = strlen(
item);
36 while (pos < len && isspace(
item[pos]))
38 while (len > 0 && isspace(
item[--len]))
42 colIndexToName.insert(make_pair(nItems, str));
43 columnNameToIndex.insert(make_pair(str, nItems));
44 if (
table.insert(make_pair(str, vector<string>(rows.size()))).
second ==
false)
45 throw runtime_error(
"Duplicate column name: '" + str +
"'");
48 for (
unsigned int r = 0;
r < rows.size();
r++) {
49 unique_ptr<char, void (*)(void *)>
copy(strdup(rows[
r].c_str()), free);
50 for (
unsigned int pos = 0;
pos < nItems;
pos++) {
51 char *
item = strtok_r((
pos == 0 ? copy.get() :
nullptr), delimeter, &saveptr);
53 throw runtime_error(
"Too few elements in '" + rows[
r] +
"'");
56 size_t p = 0, len = strlen(item);
57 while (p < len && isspace(item[p]))
59 while (len > 0 && isspace(item[--len]))
64 if (strtok_r(
nullptr, delimeter, &saveptr) !=
nullptr)
65 throw runtime_error(
"Too many elements in '" + rows[
r] +
"', expected " + to_string(nItems));
68 this->delim = delimeter;
74 char *endptr =
nullptr;
75 long long retval = strtoll(
arg, &endptr, 0);
79 throw runtime_error(
"Cannot convert '" +
string(
arg) +
"' to integral type");
85 if (strlen(
arg) > 3) {
87 if (strstr(
arg,
"true") !=
nullptr && strstr(
arg,
"false") ==
nullptr)
90 if (strstr(
arg,
"true") ==
nullptr && strstr(
arg,
"false") !=
nullptr)
94 char *endptr =
nullptr;
95 long retval = strtol(
arg, &endptr, 0);
99 throw runtime_error(
"Cannot convert '" +
string(
arg) +
"' to boolean");
121 char *endptr =
nullptr;
122 long double retval = strtold(
arg, &endptr);
126 throw runtime_error(
"Cannot convert '" +
string(
arg) +
"' to floating point type");
139 char *endptr =
nullptr;
140 unsigned long long retval = strtoull(
arg, &endptr, 0);
144 throw runtime_error(
"Cannot convert '" +
string(
arg) +
"' to unsigned integral type");
char castTo< char >(const char *arg)
long double castTo< long double >(const char *arg)
unsigned int castTo< unsigned int >(const char *arg)
unsigned long long castTo< unsigned long long >(const char *arg)
U second(std::pair< T, U > const &p)
unsigned long castTo< unsigned long >(const char *arg)
float castTo< float >(const char *arg)
bool castTo< bool >(const char *arg)
long long castTo< long long >(const char *arg)
unsigned short castTo< unsigned short >(const char *arg)
double castTo< double >(const char *arg)
short castTo< short >(const char *arg)
long castTo< long >(const char *arg)
unsigned char castTo< unsigned char >(const char *arg)
int castTo< int >(const char *arg)