Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Backofen, Rainer
amdis
Commits
709dcdda
Commit
709dcdda
authored
May 30, 2012
by
Praetorius, Simon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initfileparser extended
parent
7f2fd286
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
4 deletions
+42
-4
AMDiS/src/Initfile.cc
AMDiS/src/Initfile.cc
+40
-4
AMDiS/src/Initfile.h
AMDiS/src/Initfile.h
+2
-0
No files found.
AMDiS/src/Initfile.cc
View file @
709dcdda
...
...
@@ -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
(
whitespace
s
,
posVar
+
1
);
}
else
if
(
inputSwap
[
posVar
+
1
]
!=
'('
&&
inputSwap
[
posVar
+
1
]
!=
'['
)
{
posVarEnd
=
inputSwap
.
find_first_
not_of
(
allowedChar
s
,
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
)
{
...
...
AMDiS/src/Initfile.h
View file @
709dcdda
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment