Skip to content
Snippets Groups Projects
Commit 356e238f authored by Alfred Burgess's avatar Alfred Burgess
Browse files

Config now reads file on start-up and has a method to output to standard IO stream

parent 6c14e7be
Branches
No related merge requests found
......@@ -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 = ':';
......
......@@ -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();
}
......@@ -60,7 +60,8 @@ int main() {
_frame++;
}
// std::cout << userSettings;
userSettings.set( "exit", "teset" );
std::cout << userSettings;
// Clean-up
while( entities.size() > 0 )
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment