Commit f7ea1a6c authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Core: update ConfigReader

parent f3d45219
/**
* @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 {
......
/**
* @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.
......
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