|
@@ -0,0 +1,31 @@
|
|
|
|
+#include "../include/config.h"
|
|
|
|
+
|
|
|
|
+bool Config::init() {
|
|
|
|
+ std::ifstream ifile("config.txt");
|
|
|
|
+ std::string line;
|
|
|
|
+ if(ifile) {
|
|
|
|
+ while(getline(ifile,line)) {
|
|
|
|
+ std::stringstream ss(line);
|
|
|
|
+ std::string segment;
|
|
|
|
+ std::vector<std::string> v;
|
|
|
|
+ while(getline(ss, segment, '=')) {
|
|
|
|
+ v.push_back(segment);
|
|
|
|
+ }
|
|
|
|
+ if(v.size()!=2) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ storage.insert(std::pair<std::string,std::string>(v.at(0),v.at(1)));
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+std::string Config::getValue(std::string key) {
|
|
|
|
+ auto it = storage.find(key);
|
|
|
|
+ if(it != storage.end()) {
|
|
|
|
+ return it->second;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return "";
|
|
|
|
+}
|