Add operator [], allow access directly

dev v0.3
marcelb 1 year ago
parent c5b7ceff3e
commit 695eaa2787
  1. 12
      lib/config.hpp
  2. 4
      src/config.cpp
  3. 6
      test/test.cpp
  4. BIN
      test/test.o

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

@ -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 * Otvaram config.cfg datoteku, čitam je i inicijaliziram map kontenjer configs prema cnf_fields

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

Binary file not shown.
Loading…
Cancel
Save