diff options
| author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-12-19 12:19:41 +0100 | 
|---|---|---|
| committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-12-19 12:19:41 +0100 | 
| commit | 94a1189d757f0269ac081ad2d750152e30564986 (patch) | |
| tree | 71da6c79ce4f96795e3ddd3ef374c617a57c8d08 /common/config.cpp | |
| parent | 5824342e0ffbcac84bfb2c1c6ed3590fd1cdfc4d (diff) | |
Linked common as submodule.
Diffstat (limited to 'common/config.cpp')
| m--------- | common | 0 | ||||
| -rw-r--r-- | common/config.cpp | 84 | 
2 files changed, 0 insertions, 84 deletions
| diff --git a/common b/common new file mode 160000 +Subproject dd64a35c949738c2c321989d065e0754556823d diff --git a/common/config.cpp b/common/config.cpp deleted file mode 100644 index f106304..0000000 --- a/common/config.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "config.h" - -#include <fstream> -#include <iostream> -#include <sstream> - -Config::Config() { -	path = "aotenjou.conf"; -	load_conf(); -} - -Config::Config(std::string path) { -	path = path; -	load_conf(); -} - -Config::~Config() { -	save_conf(); -} - -/* -  Adds a config-element to the list -  */ -void Config::add_element(std::string keyword, std::string value) { -    config[keyword] = value; -} - -void Config::add_element(std::string keyword, int value) { -	std::stringstream out; -	out << value; -	config[keyword] = out.str(); -} - -/* -Load a value from the config. -  */ -std::string Config::get_element(std::string keyword) { -    return config[keyword]; -} - -/* -  Initializes and loads the config from disk if it exists -  */ -void Config::load_conf(){ -		 -	std::ifstream config_file(path.c_str()); -	 -	if(config_file.is_open()) { -		while(config_file.good()) { -			std::string config_line; -			std::getline(config_file, config_line); -			std::string id    = config_line.substr(0, config_line.find("=") - 1); -			//Skip empty lines -			if (id != "") { -				std::string value = config_line.substr(config_line.find("=") + 2, config_line.length()-1); -				config[id] = value; -			} -		} -		 -		config_file.close(); -		 -	} else { -		std::cerr << "Unable to open configuration file..." << std::endl; -	} -} - -/* -  Saves the current config to disk -  */ -void Config::save_conf(){ - -	std::ofstream config_file(path.c_str(), std::ios::out | std::ios::trunc); -	 -	if(config_file.is_open()) { -		for(std::map<std::string, std::string>::iterator it = config.begin(); it != config.end(); ++it) { -			config_file << it->first << " = " << it->second << std::endl; -		} -		 -		config_file.close(); -	} else { -		std::cerr << "Unable to save to configuration file..." << std::endl; -	} -} - | 
