scaffold some common services
This commit is contained in:
35
common/config/ConfigService.cpp
Normal file
35
common/config/ConfigService.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
#include "ConfigService.hpp"
|
||||
|
||||
#include <exception>
|
||||
|
||||
ConfigService::ConfigService(const std::string& filePath) {
|
||||
|
||||
if(!loadFromFile(filePath)) {
|
||||
std::cout << "Error loading file " << filePath << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ConfigService::loadFromFile(const std::string& filePath) {
|
||||
try {
|
||||
config_.clear();
|
||||
config_.readFile(filePath.c_str());
|
||||
lastError_.clear();
|
||||
return true;
|
||||
} catch (const libconfig::FileIOException&) {
|
||||
lastError_ = "Unable to read config file: " + filePath;
|
||||
} catch (const libconfig::ParseException& error) {
|
||||
lastError_ = std::string("Parse error in ") + error.getFile() + ":" +
|
||||
std::to_string(error.getLine()) + " - " + error.getError();
|
||||
} catch (const std::exception& error) {
|
||||
lastError_ = error.what();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& ConfigService::lastError() const {
|
||||
return lastError_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user