Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer, es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Ein Anmelden über dieses erzeugt ein neues Konto. Das alte Konto ist über den Reiter "Standard" erreichbar. Die Administratoren

Dear Gitlab user, it is now possible to log in to our service using the ZIH login/LDAP. Logging in via this will create a new account. The old account can be accessed via the "Standard" tab. The administrators

Commit 709dcdda authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Initfileparser extended

parent 7f2fd286
......@@ -86,6 +86,8 @@ namespace AMDiS {
// add parameter to map after variable replacement
std::string paramName = variableReplacement(InitfileInternal::trim(parser.name));
std::string paramValue = variableReplacement(InitfileInternal::trim(parser.value));
paramValue = variableEvaluation(paramValue);
operator[](paramName) = paramValue;
int info = 0;
get("parameter information", info, 0);
......@@ -133,19 +135,25 @@ namespace AMDiS {
std::string Initfile::variableReplacement(const std::string& input) const
{
std::string whitespaces = " \t\r\f";
std::string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
std::string inputSwap = input;
size_t posVar = inputSwap.find_first_of('$');
while (posVar != string::npos) {
size_t posVarBegin, posVarEnd;
if(inputSwap[posVar+1] == '{') {
if(inputSwap[posVar+1] == '{') { // ${var_name}
posVarEnd = inputSwap.find_first_of('}',posVar + 2);
posVarBegin = posVar + 1;
} else {
posVarEnd = inputSwap.find_first_of(whitespaces, posVar + 1);
} else if (inputSwap[posVar+1] != '(' && inputSwap[posVar+1] != '[') {
posVarEnd = inputSwap.find_first_not_of(allowedChars, posVar + 1);
posVarBegin = posVar;
} else {
posVar = inputSwap.find_first_of('$',posVar+1);
continue;
}
std::string varName = inputSwap.substr(posVarBegin + 1 , posVarEnd - posVarBegin - 1);
// if varname is found in parameter list then replace variable by value
// otherwise throw tagNotFound exception
std::string varParam;
......@@ -156,12 +164,40 @@ namespace AMDiS {
std::string replaceName = inputSwap.substr(posVar , posVarEnd - posVar + (posVarBegin - posVar));
inputSwap.replace(inputSwap.find(replaceName), replaceName.length(), varParam);
posVar = inputSwap.find_first_of('$');
posVar = inputSwap.find_first_of('$',posVarEnd);
}
return inputSwap;
}
std::string Initfile::variableEvaluation(const std::string& input) const
{
std::string whitespaces = " \t\r\f";
std::string inputSwap = input;
size_t posVar = inputSwap.find_first_of('$');
while (posVar != string::npos) {
size_t posVarBegin, posVarEnd;
if(inputSwap[posVar+1] == '(') { // $(expr)
posVarEnd = inputSwap.find_first_of(')',posVar + 2);
posVarBegin = posVar + 1;
} else {
posVar = inputSwap.find_first_of('$',posVar+1);
continue;
}
std::string varName = inputSwap.substr(posVarBegin + 1 , posVarEnd - posVarBegin - 1);
double value = 0.0;
InitfileInternal::convert(varName, value); // string -> double (using muparser)
InitfileInternal::convert(value, varName); // double -> string
std::string replaceName = inputSwap.substr(posVar , posVarEnd - posVar + (posVarBegin - posVar));
inputSwap.replace(inputSwap.find(replaceName), replaceName.length(), varName);
posVar = inputSwap.find_first_of('$');
}
return inputSwap;
}
void Initfile::readArgv(int argc, char **argv)
{
......
......@@ -611,6 +611,8 @@ protected:
/// the last version only for variablenames without whitespaces
std::string variableReplacement(const std::string& input) const;
std::string variableEvaluation(const std::string& input) const;
/** Fill the initfile from an input stream.
* @param in: the stream to fill the data from.
* Current dataformat: tag:value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment