diff --git a/include/config-parser.h b/include/config-parser.h index 41bef023a0ed0551d241ea89b20332749e463c59..3f0b9d923db8915665283cab306a75ddf18477ce 100644 --- a/include/config-parser.h +++ b/include/config-parser.h @@ -13,6 +13,8 @@ typedef std::map<std::string,std::string> ConfigMap; class ConfigParser { + friend std::ostream& operator<<( std::ostream& os, const ConfigParser& obj ); + public: static ConfigParser UserSettings(); @@ -20,9 +22,13 @@ class ConfigParser ConfigMap userSettings(){ return this->readFile( "settings.cfg" ); } + void set( std::string key, std::string value ); + std::string get( std::string key ); + std::string toString() const; private: + std::string _path; ConfigParser( std::string path ); const std::string CONFIG_DIRECTORY = "config"; const char DELIMINATOR = ':'; diff --git a/src/config-parser.cpp b/src/config-parser.cpp index 58df3c1d27a595365f48e51e007d5529557eecac..e6266e06911a94b4928f19c9080ffbf6ee373345 100644 --- a/src/config-parser.cpp +++ b/src/config-parser.cpp @@ -6,19 +6,27 @@ ConfigParser ConfigParser::UserSettings() return parser; } +void ConfigParser::set( std::string key, std::string value ) + { this->_config[key] = value; } + +std::string ConfigParser::get( std::string key ) + { return this->_config[key]; } std::string ConfigParser::toString() const { - std::string str = ""; + std::string str = "Config File: "+this->_path+"\n"; for( const auto [key, value] : this->_config ) { str += "["+key+"] "+value+"\n"; } return str; } -std::ostream& operator<<( std::ostream& os, const ConfigParser& obj ) { return os << obj.toString(); } + ConfigParser::ConfigParser( std::string path ) - : _logger( Logger::instance() ) -{ this->_logger.info( "Creating config parser" ); } + : _path(path), _logger( Logger::instance() ) +{ + this->_logger.info( "Creating config parser" ); + this->readFile( path ); +} ConfigParser::~ConfigParser() { this->_logger.info( "Closing config parser" ); } @@ -46,7 +54,9 @@ ConfigMap ConfigParser::readFile( std::string path ) std::string key = this->getKey( line ); std::string value = this->getKey( line ); if( ! key.empty() && ! value.empty() ) - { confMap.insert( keyPair(key, value) ); } + { confMap[key] = value; } + std::cout << key << "," << value << std::endl; + // { confMap.insert( keyPair(key, value) ); } } } } else @@ -82,3 +92,8 @@ std::string ConfigParser::getValue( std::string line ) } return value; } + +std::ostream& operator<<( std::ostream& os, const ConfigParser& obj ) +{ + return os << obj.toString(); +} diff --git a/src/main.cpp b/src/main.cpp index 36a585e7d598eb3f4d34ae5743336ff6ad241e70..6f24692b1860ea7f55e6bcd1455d4aacd0ef7c7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,7 +60,8 @@ int main() { _frame++; } - // std::cout << userSettings; + userSettings.set( "exit", "teset" ); + std::cout << userSettings; // Clean-up while( entities.size() > 0 )