Add operator [], allow access directly
This commit is contained in:
		
							parent
							
								
									c5b7ceff3e
								
							
						
					
					
						commit
						695eaa2787
					
				| @ -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 = {}); |  | ||||||
| 
 |  | ||||||
|     void print(); |  | ||||||
|     bool init(const string _configFilePath);    |  | ||||||
|     bool isHaveNecessary();  |     bool isHaveNecessary();  | ||||||
|  |     bool init(const string _configFilePath);    | ||||||
|  | 
 | ||||||
|  |     public: | ||||||
|  | 
 | ||||||
|  |     config(const string _configFilePath, const vector<string> _necessary = {}); | ||||||
|  |     string operator[] (const string& key); | ||||||
|  |     void print(); | ||||||
|      |      | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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; | ||||||
| } | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								test/test.o
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/test.o
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user