From 72a1107e594b1745026241d323f9fc44813bd91d Mon Sep 17 00:00:00 2001 From: Alexander Baldeck Date: Sun, 26 Dec 2004 11:39:53 +0000 Subject: - replaced default ini creation routine with new system - testing version of write support for config system --- src/configuration.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'src/configuration.cpp') diff --git a/src/configuration.cpp b/src/configuration.cpp index 07e6005f..0b1f24a7 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -54,17 +54,64 @@ void Configuration::Init(std::string filename) { #ifdef __DEBUG for (iter = iniOptions.begin(); iter != iniOptions.end(); iter++) { optionTmp = *iter; - std::cout << "key=(" << optionTmp.key << ") stringValue=(" << optionTmp.stringValue << ") numericValue=(" << optionTmp.numericValue << ")\n"; + std::cout << "Configuration::Init(" << optionTmp.key << ", \"" << optionTmp.stringValue << "\" / " << optionTmp.numericValue << ")\n"; } #endif } -bool Configuration::Write() { +bool Configuration::Write(std::string filename) { + std::ofstream out(filename.c_str(), std::ofstream::out | std::ofstream::trunc); + char tmp[20]; + + INI_OPTION optionTmp; + for (iter = iniOptions.begin(); iter != iniOptions.end(); iter++) { + optionTmp = *iter; + out.write(optionTmp.key.c_str(), optionTmp.key.length()); + out.write("=", 1); + + if(optionTmp.numericValue == 0) { + out.write(optionTmp.stringValue.c_str(), optionTmp.stringValue.length()); + }else{ + sprintf(tmp, "%19f", optionTmp.numericValue); + out.write(tmp, strlen(tmp)); + strcpy(tmp, ""); + } + + out.write("\n", 1); + } + + out.close(); return true; } -bool Configuration::setValue(std::string, std::string) { - return true; +void Configuration::setValue(std::string key, std::string value) { + if(getValue(key, value) == value) { + #ifdef __DEBUG + std::cout << "Configuration::setValue(" << key << ", \"" << value << "\")\n"; + #endif + INI_OPTION optionTmp; + + optionTmp.key = key; + optionTmp.stringValue = value; + optionTmp.numericValue = 0; + + iniOptions.push_back(optionTmp); + } +} + +void Configuration::setValue(std::string key, float value) { + if(getValue(key, value) == value) { + #ifdef __DEBUG + std::cout << "Configuration::setValue(" << key << ", " << value << ")\n"; + #endif + + INI_OPTION optionTmp; + + optionTmp.key = key; + optionTmp.numericValue = value; + + iniOptions.push_back(optionTmp); + } } /** -- cgit v1.2.3-60-g2f50