Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
f7ea1a6c
Commit
f7ea1a6c
authored
Dec 13, 2018
by
Simon Spannagel
Browse files
Core: update ConfigReader
parent
f3d45219
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/core/config/ConfigReader.cpp
View file @
f7ea1a6c
/**
* @file
* @brief Implementation of config reader
* @copyright Copyright (c) 2017 CERN and the
Allpix Squared
authors.
* @copyright Copyright (c) 2017 CERN and the
Corryvreckan
authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
...
...
@@ -127,16 +127,29 @@ void ConfigReader::add(std::istream& stream, std::string file_name) {
}
// Check if section header or key-value pair
if
(
line
.
front
()
==
'['
&&
line
[
line
.
length
()
-
1
]
==
']'
)
{
// Ignore empty sections if they contain no configurations
if
(
!
conf
.
getName
().
empty
()
||
conf
.
countSettings
()
>
0
)
{
// Add previous section
addConfiguration
(
std
::
move
(
conf
));
if
(
line
.
front
()
==
'['
)
{
// Line should be a section header with an alphanumeric name
size_t
idx
=
1
;
for
(;
idx
<
line
.
length
()
-
1
;
++
idx
)
{
if
(
isalnum
(
line
[
idx
])
==
0
&&
line
[
idx
]
!=
'_'
)
{
break
;
}
}
std
::
string
remain
=
corryvreckan
::
trim
(
line
.
substr
(
idx
+
1
));
if
(
line
[
idx
]
==
']'
&&
(
remain
.
empty
()
||
remain
.
front
()
==
'#'
))
{
// Ignore empty sections if they contain no configurations
if
(
!
conf
.
getName
().
empty
()
||
conf
.
countSettings
()
>
0
)
{
// Add previous section
addConfiguration
(
std
::
move
(
conf
));
}
// Begin new section
section_name
=
std
::
string
(
line
,
1
,
line
.
length
()
-
2
);
conf
=
Configuration
(
section_name
,
file_name
);
// Begin new section
section_name
=
std
::
string
(
line
,
1
,
idx
-
1
);
conf
=
Configuration
(
section_name
,
file_name
);
}
else
{
// Section header is not valid
throw
ConfigParseError
(
file_name
,
line_num
);
}
}
else
if
(
isalpha
(
line
.
front
())
!=
0
)
{
// Line should be a key / value pair with an equal sign
try
{
...
...
src/core/config/ConfigReader.hpp
View file @
f7ea1a6c
/**
* @file
* @brief Provides a reader for configuration files
* @copyright Copyright (c) 2017 CERN and the
Allpix Squared
authors.
* @copyright Copyright (c) 2017 CERN and the
Corryvreckan
authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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