diff --git a/config/settings.cfg b/config/settings.cfg index 82f24127d8e2d3e78be977a2bd1c25070a13770c..f5194b45e584bcb17e35f1d7d511f8d005e0f9d9 100644 --- a/config/settings.cfg +++ b/config/settings.cfg @@ -1,2 +1,7 @@ +# comment test test1: test test2: tedfh +duplicate: test1 +duplicate: test2 +duplicate: test3 +comment: Example comment # this should not render diff --git a/include/config-parser.h b/include/config-parser.h index 53c8cc01b5068f189c3fb7deaea6c8e505586c5b..08688673056711edd619c5f75f232a3c7e765036 100644 --- a/include/config-parser.h +++ b/include/config-parser.h @@ -22,6 +22,7 @@ class ConfigParser private: const std::string CONFIG_DIRECTORY = "config"; const char DELIMINATOR = ':'; + const char COMMENT_CHAR = '#'; Logger& _logger; ConfigMap readFile( std::string path ); diff --git a/src/config-parser.cpp b/src/config-parser.cpp index 8781bfd488ae68c3b4fa8e43847677edf79d49a2..81c39be24995c790cddeb8d466f10ae24b0cf9c3 100644 --- a/src/config-parser.cpp +++ b/src/config-parser.cpp @@ -1,8 +1,19 @@ #include "config-parser.h" +std::ostream& operator<<( std::ostream& os, const ConfigMap& obj ) +{ + for( const auto& [ key, value ] : obj ) + { + os << "[" << key.c_str() << "]" << value.c_str() << std::endl; + } + return os; +} + ConfigParser::ConfigParser() : _logger( Logger::instance() ) -{ this->_logger.info( "Creating config parser" ); } +{ + this->_logger.info( "Creating config parser" ); +} ConfigParser::~ConfigParser() { @@ -27,9 +38,10 @@ ConfigMap ConfigParser::readFile( std::string path ) { if( ! line.empty() ) { + if( line.at(0) == COMMENT_CHAR ) + { continue; } std::string key = this->getKey( line ); std::string value = this->getKey( line ); - std::cout << "[" << key << "] " << value << std::endl; if( ! key.empty() && ! value.empty() ) { confMap.insert( keyPair(key, value) ); } } @@ -45,7 +57,9 @@ std::string ConfigParser::getKey( std::string line ) std::string key = ""; for( char ch : line ) { - if( ch == DELIMINATOR ) { break; } + if( ch == DELIMINATOR + || ch == COMMENT_CHAR + ) { break; } else if ( ! std::isspace(ch) ) { key.push_back( ch ) ; } } return key; @@ -57,7 +71,9 @@ std::string ConfigParser::getValue( std::string line ) bool hasFound = false; for( char ch : line ) { - if( ch == DELIMINATOR ) { break; } + if( ch == DELIMINATOR + || COMMENT_CHAR == ch + ) { break; } else if ( hasFound ) { value.push_back( ch ) ; } } return value; diff --git a/src/main.cpp b/src/main.cpp index 9d425ac51b8d32dbaffa3280631fcea63ed1ca52..5e11d8edc6a7c23ab9273fc877cec309541122d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,6 +60,8 @@ int main() { _frame++; } + // std::cout << userSettings; + // Clean-up while( entities.size() > 0 ) {