From ee69b21fa3ab601d0e31f946281b1b0bda79af93 Mon Sep 17 00:00:00 2001
From: Alfred Burgess <aburgess@ucc.gu.uwa.edu.au>
Date: Thu, 7 Dec 2023 15:46:38 +0800
Subject: [PATCH] Expanded config

---
 config/settings.cfg     |  5 +++++
 include/config-parser.h |  1 +
 src/config-parser.cpp   | 24 ++++++++++++++++++++----
 src/main.cpp            |  2 ++
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/config/settings.cfg b/config/settings.cfg
index 82f2412..f5194b4 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 53c8cc0..0868867 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 8781bfd..81c39be 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 9d425ac..5e11d8e 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 )
 	{
-- 
GitLab