Add operator [], allow access directly

This commit is contained in:
marcelb 2023-09-21 22:01:00 +02:00
parent c5b7ceff3e
commit 695eaa2787
4 changed files with 13 additions and 11 deletions

View File

@ -14,15 +14,17 @@ bool clearComments(string &a);
void parseConfigLine(const string a, string &b, string &c);
class config {
public:
vector<string> necessary; // = {"Username", "API", "Domain", "consolePrintLogs", "DinioServer1", "DinioServer2", "DinioGetIPURL", "DinioServer1Port", "DinioServer2Port" };
vector<string> necessary;
map<string, string> element;
config(const string _configFilePath, const vector<string> _necessary = {});
void print();
bool init(const string _configFilePath);
bool isHaveNecessary();
bool init(const string _configFilePath);
public:
config(const string _configFilePath, const vector<string> _necessary = {});
string operator[] (const string& key);
void print();
};

View File

@ -11,6 +11,10 @@ config::config(const string _configFilePath, const vector<string> _necessary) {
}
}
string config::operator[](const string& key) {
return element[key];
}
/**
* Otvaram config.cfg datoteku, čitam je i inicijaliziram map kontenjer configs prema cnf_fields

View File

@ -1,5 +1,4 @@
#include <iostream>
#include "../lib/config.hpp"
using namespace std;
@ -7,10 +6,7 @@ using namespace std;
int main() {
config mycfg ("../example/config.cfg", {"Username", "API", "Domain" });
// cout << "HAloooo" << endl;
cout << mycfg.element["consolePrintLogs"];
cout << mycfg["consolePrintLogs"];
return 0;
}

Binary file not shown.