2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-02-22 22:21:06 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 18:46:50 +01:00
|
|
|
#include "utilities/debug_file_reader.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
SettingsFileReader::SettingsFileReader(const char *filePath) {
|
|
|
|
|
std::ifstream settingsFile;
|
|
|
|
|
|
|
|
|
|
if (filePath == nullptr)
|
|
|
|
|
settingsFile.open(settingsFileName);
|
|
|
|
|
else
|
|
|
|
|
settingsFile.open(filePath);
|
|
|
|
|
|
|
|
|
|
if (settingsFile.is_open()) {
|
2019-03-02 08:27:21 +01:00
|
|
|
parseStream(settingsFile);
|
2017-12-21 00:45:38 +01:00
|
|
|
settingsFile.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsFileReader::~SettingsFileReader() {
|
|
|
|
|
settingStringMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t SettingsFileReader::getSetting(const char *settingName, int32_t defaultValue) {
|
|
|
|
|
int32_t value = defaultValue;
|
2019-09-13 12:14:06 +02:00
|
|
|
|
|
|
|
|
map<string, string>::iterator it = settingStringMap.find(string(settingName));
|
|
|
|
|
if (it != settingStringMap.end()) {
|
|
|
|
|
value = atoi(it->second.c_str());
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SettingsFileReader::getSetting(const char *settingName, bool defaultValue) {
|
|
|
|
|
return getSetting(settingName, static_cast<int32_t>(defaultValue)) ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SettingsFileReader::getSetting(const char *settingName, const std::string &value) {
|
|
|
|
|
std::string returnValue = value;
|
|
|
|
|
map<string, string>::iterator it = settingStringMap.find(string(settingName));
|
|
|
|
|
if (it != settingStringMap.end())
|
|
|
|
|
returnValue = it->second;
|
|
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
|
}
|
2018-10-10 16:02:19 +02:00
|
|
|
|
|
|
|
|
const char *SettingsFileReader::appSpecificLocation(const std::string &name) {
|
|
|
|
|
return name.c_str();
|
|
|
|
|
}
|
2019-03-02 08:27:21 +01:00
|
|
|
|
|
|
|
|
void SettingsFileReader::parseStream(std::istream &inputStream) {
|
|
|
|
|
stringstream ss;
|
|
|
|
|
string key;
|
2019-09-13 12:14:06 +02:00
|
|
|
string value;
|
2019-03-02 08:27:21 +01:00
|
|
|
char temp = 0;
|
|
|
|
|
|
|
|
|
|
while (!inputStream.eof()) {
|
|
|
|
|
string tempString;
|
|
|
|
|
string tempStringValue;
|
|
|
|
|
getline(inputStream, tempString);
|
|
|
|
|
|
|
|
|
|
ss << tempString;
|
|
|
|
|
ss >> key;
|
|
|
|
|
ss >> temp;
|
|
|
|
|
ss >> value;
|
|
|
|
|
|
2019-09-13 12:14:06 +02:00
|
|
|
if (!ss.fail()) {
|
|
|
|
|
settingStringMap.insert(pair<string, string>(key, value));
|
2019-03-02 08:27:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ss.str(string()); // for reset string inside stringstream
|
|
|
|
|
ss.clear();
|
|
|
|
|
key.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
}; // namespace NEO
|