9 Parameter::Parameter(
const char *
id,
10 const char *procOrRole,
16 this->procOrRole = procOrRole;
18 this->scalarOrVector =
value;
19 this->
delim = delimeter;
22 Parameter::Parameter(
const char *
id,
23 const char *procOrRole,
26 const vector<string>&
rows,
30 this->procOrRole = procOrRole;
33 map<int,string> colIndexToName;
34 unique_ptr<char,void(*)(void*)>
copy( strdup(columns), free );
35 unsigned long nItems = 0;
37 for(
const char *item=strtok_r(copy.get(),delimeter,&saveptr); item !=
NULL; item = strtok_r(
NULL,delimeter,&saveptr), nItems++){
39 size_t pos=0, len = strlen(item);
40 while( pos<len && isspace(item[pos]) ) pos++;
41 while( len>0 && isspace(item[--len]) );
42 string str = (pos<len+1 ?
string(item+pos,len+1-pos) : item);
44 colIndexToName.insert( make_pair(nItems,str) );
45 columnNameToIndex.insert( make_pair(str,nItems) );
46 if( table.insert( make_pair(str,vector<string>(rows.size())) ).
second ==
false )
47 throw runtime_error(
"Duplicate column name: '" + str +
"'");
50 for(
unsigned int r=0;
r<rows.size();
r++){
51 unique_ptr<char,void(*)(void*)>
copy( strdup(rows[
r].c_str()), free );
52 for(
unsigned int pos=0;
pos<nItems;
pos++){
53 char *item = strtok_r((
pos==0?copy.get():
NULL),delimeter,&saveptr);
55 throw runtime_error(
"Too few elements in '" + rows[
r] +
"'");
58 size_t p=0, len = strlen(item);
59 while( p<len && isspace(item[p]) ) p++;
60 while( len>0 && isspace(item[--len]) );
62 table[ colIndexToName[
pos] ][
r] = (
pos<len+1 ?
string(item+p,len+1-p) : item);
64 if( strtok_r(
NULL,delimeter,&saveptr) !=
NULL )
65 throw runtime_error(
"Too many elements in '" + rows[
r] +
"', expected " + to_string(nItems));
68 this->
delim = delimeter;
74 long long retval = strtoll(
arg,&endptr,0);
75 if( *endptr ==
'\0' )
return retval;
76 else throw runtime_error(
"Cannot convert '" +
string(
arg)+
"' to integral type");
81 if( strlen(
arg) > 3 ){
83 if( strstr(
arg,
"true") !=
NULL && strstr(
arg,
"false") ==
NULL )
return true;
85 if( strstr(
arg,
"true") ==
NULL && strstr(
arg,
"false") !=
NULL )
return false;
89 long retval = strtol(
arg,&endptr,0);
90 if( *endptr ==
'\0' )
return retval;
92 throw runtime_error(
"Cannot convert '" +
string(
arg)+
"' to boolean");
102 long double retval = strtold(
arg,&endptr);
103 if( *endptr ==
'\0' )
return retval;
104 else throw runtime_error(
"Cannot convert '" +
string(
arg) +
"' to floating point type");
111 unsigned long long retval = strtoull(
arg,&endptr,0);
112 if( *endptr ==
'\0' )
return retval;
113 else 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)