summaryrefslogtreecommitdiff
path: root/src/CommonAPI/IniFileReader.cpp
diff options
context:
space:
mode:
authorJuergen Gehring <juergen.gehring@bmw.de>2017-06-19 07:47:01 -0700
committerJuergen Gehring <juergen.gehring@bmw.de>2017-06-19 07:47:01 -0700
commit008f6c11f5371e93c06b3ed337326008d2031084 (patch)
treef25b96bab93d4b71496793d5944e054fc8d303af /src/CommonAPI/IniFileReader.cpp
parent66de998220d90116aa603d7458e245fe6094b4eb (diff)
downloadgenivi-common-api-runtime-008f6c11f5371e93c06b3ed337326008d2031084.tar.gz
CommonAPI 3.1.123.1.12
Diffstat (limited to 'src/CommonAPI/IniFileReader.cpp')
-rw-r--r--src/CommonAPI/IniFileReader.cpp103
1 files changed, 52 insertions, 51 deletions
diff --git a/src/CommonAPI/IniFileReader.cpp b/src/CommonAPI/IniFileReader.cpp
index c91e91f..94057e0 100644
--- a/src/CommonAPI/IniFileReader.cpp
+++ b/src/CommonAPI/IniFileReader.cpp
@@ -29,65 +29,66 @@ IniFileReader::Section::getValue(const std::string &_key) const {
bool
IniFileReader::load(const std::string &_path) {
std::ifstream configStream(_path);
- if (configStream.is_open()) {
- //COMMONAPI_INFO("Loading ini file from ", _path);
+ if (!configStream.is_open()) {
+ COMMONAPI_ERROR("Failed to load ini file: ", _path);
+ return false;
+ }
- int lineCounter(0);
- std::string currentSectionName;
- std::shared_ptr<Section> currentSection;
+ int lineCounter(0);
+ std::string currentSectionName;
+ std::shared_ptr<Section> currentSection;
- while (!configStream.eof()) {
- std::string line;
- std::getline(configStream, line);
- lineCounter++;
+ while (!configStream.eof()) {
+ std::string line;
+ std::getline(configStream, line);
+ lineCounter++;
- trim(line);
+ trim(line);
- std::size_t start = line.find('[');
- if (start == 0) {
- std::size_t end = line.find(']');
- if (end != line.npos) {
- currentSectionName = line.substr(++start, --end);
- if (sections_.end() == sections_.find(currentSectionName)) {
- currentSection = std::make_shared<Section>();
- if (currentSection) {
- sections_[currentSectionName] = currentSection;
- }
- } else {
- COMMONAPI_ERROR("Double definition of section \'",
- currentSectionName,
- "\' ignoring definition (line ",
- lineCounter,
- ")");
- currentSection = nullptr;
+ std::size_t start = line.find('[');
+ if (start == 0) {
+ std::size_t end = line.find(']');
+ if (end != line.npos) {
+ currentSectionName = line.substr(++start, --end);
+ if (sections_.end() == sections_.find(currentSectionName)) {
+ currentSection = std::make_shared<Section>();
+ if (currentSection) {
+ sections_[currentSectionName] = currentSection;
}
} else {
- COMMONAPI_ERROR("Missing \']\' in section definition (line ",
- lineCounter, ")");
+ COMMONAPI_ERROR("Double definition of section \'",
+ currentSectionName,
+ "\' ignoring definition (line ",
+ lineCounter,
+ ")");
+ currentSection = nullptr;
}
- } else if (currentSection) {
- std::size_t pos = line.find('=');
- if (pos != line.npos) {
- std::string key = line.substr(0, pos);
- trim(key);
- if (currentSection->mappings_.end()
- != currentSection->mappings_.find(key)) {
- COMMONAPI_ERROR("Double definition for key \'",
- key,
- "'\' in section \'",
- currentSectionName,
- "\' (line ",
- lineCounter,
- ")");
- } else {
- std::string value = line.substr(pos+1);
- trim(value);
- currentSection->mappings_[key] = value;
- }
- } else if (line.size() > 0) {
- COMMONAPI_ERROR("Missing \'=\' in key=value definition (line ",
- lineCounter, ")");
+ } else {
+ COMMONAPI_ERROR("Missing \']\' in section definition (line ",
+ lineCounter, ")");
+ }
+ } else if (currentSection) {
+ std::size_t pos = line.find('=');
+ if (pos != line.npos) {
+ std::string key = line.substr(0, pos);
+ trim(key);
+ if (currentSection->mappings_.end()
+ != currentSection->mappings_.find(key)) {
+ COMMONAPI_ERROR("Double definition for key \'",
+ key,
+ "'\' in section \'",
+ currentSectionName,
+ "\' (line ",
+ lineCounter,
+ ")");
+ } else {
+ std::string value = line.substr(pos+1);
+ trim(value);
+ currentSection->mappings_[key] = value;
}
+ } else if (line.size() > 0) {
+ COMMONAPI_ERROR("Missing \'=\' in key=value definition (line ",
+ lineCounter, ")");
}
}
}