Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
f3e37b9e
Commit
f3e37b9e
authored
Oct 11, 2016
by
Guolin Ke
Browse files
better parameter parse logic.
parent
8de2bac5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
src/application/application.cpp
src/application/application.cpp
+12
-3
No files found.
src/application/application.cpp
View file @
f3e37b9e
...
...
@@ -58,7 +58,7 @@ Application::~Application() {
void
Application
::
LoadParameters
(
int
argc
,
char
**
argv
)
{
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
std
::
vector
<
std
::
string
>
tmp_strs
=
Common
::
Split
(
argv
[
i
],
'='
);
if
(
tmp_strs
.
size
()
==
2
)
{
std
::
string
key
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
0
]));
...
...
@@ -68,6 +68,9 @@ void Application::LoadParameters(int argc, char** argv) {
}
params
[
key
]
=
value
;
}
else
{
Log
::
Stdout
(
"Warning: unknown parameter in command line: %s"
,
argv
[
i
]);
}
}
// check for alias
ParameterAlias
::
KeyAliasTransform
(
&
params
);
...
...
@@ -77,9 +80,12 @@ void Application::LoadParameters(int argc, char** argv) {
config_reader
.
ReadAllLines
();
if
(
config_reader
.
Lines
().
size
()
>
0
)
{
for
(
auto
&
line
:
config_reader
.
Lines
())
{
// remove str after #
if
(
line
.
size
()
>
0
&&
std
::
string
::
npos
!=
line
.
find_first_of
(
"#"
))
{
line
.
erase
(
line
.
find_first_of
(
"#"
));
}
line
=
Common
::
Trim
(
line
);
// skip comment
if
(
line
.
size
()
==
0
||
line
[
0
]
==
'#'
)
{
if
(
line
.
size
()
==
0
)
{
continue
;
}
std
::
vector
<
std
::
string
>
tmp_strs
=
Common
::
Split
(
line
.
c_str
(),
'='
);
...
...
@@ -94,6 +100,9 @@ void Application::LoadParameters(int argc, char** argv) {
params
[
key
]
=
value
;
}
}
else
{
Log
::
Stdout
(
"Warning: unknown parameter in config file: %s"
,
line
.
c_str
());
}
}
}
else
{
Log
::
Stdout
(
"config file: %s doesn't exist, will ignore"
,
...
...
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