Text-Renderer/src/Config.cpp

67 lines
1.5 KiB
C++

//
// Created by my on 2019/11/12.
//
#include "Config.h"
Config::Config() {
init();
}
void Config::init() {
std::ifstream infile(CONFIG_FILE_PATH);
std::string line;
std::getline(infile, line);
line = line.substr(BORDER_COLOR_STARTPOSITION);
border_color = readColor(line);
std::getline(infile, line);
line = line.substr(BACKGROUND_COLOR_STARTPOSITION);
background_color = readColor(line);
std::getline(infile, line);
line = line.substr(FONT_COLOR_STARTPOSITION);
font_color = readColor(line);
std::getline(infile, line);
line = line.substr(BORDER_WIDTH_STARTPOSITION);
border_width = readInteger(line);
std::getline(infile, line);
line = line.substr(ROW_STARTPOSITION);
row = readInteger(line);
std::getline(infile, line);
line = line.substr(COLUMN_STARTPOSITION);
column = readInteger(line);
std::getline(infile, line);
line = line.substr(COLUMN_OF_FINAL_ROW_STARTPOSITION);
column_of_finalRow = readInteger(line);
}
int Config::readInteger(std::string line) {
int value;
std::istringstream iss(line);
if(!(iss >> value)) {
std::cout << "failed when read interger from config" << std::endl;
}
return value;
}
Color Config::readColor(std::string line) {
int red, green, blue;
std::istringstream iss(line);
if(!(iss >> red >> green >> blue)) {
std::cout << "failed when read color from config" << std::endl;
}
Color color(red, green, blue);
return color;
}