From 04a54af0ae27099cd6966ec8a019579f2ab415f4 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 10 Feb 2003 03:04:46 +0000 Subject: [PATCH] Added Get/SetFloat. --- src/ZE_ZConfigFile.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ZE_ZConfigFile.cpp b/src/ZE_ZConfigFile.cpp index 9c14afb..ead6791 100644 --- a/src/ZE_ZConfigFile.cpp +++ b/src/ZE_ZConfigFile.cpp @@ -13,7 +13,7 @@ File: ZE_ZConfigFile.cpp
Description: Implementation source file for ZConfigFile, the ZEngine INI-Style Config File.
Author(s): James Turk
-$Id: ZE_ZConfigFile.cpp,v 1.4 2003/01/16 05:45:58 cozman Exp $
+$Id: ZE_ZConfigFile.cpp,v 1.5 2003/02/10 03:04:46 cozman Exp $
\file ZE_ZConfigFile.cpp \brief Source file for ZConfigFile. @@ -199,6 +199,25 @@ void ZConfigFile::Process(string filename) cfile.close(); } +float ZConfigFile::GetFloat(string section, string var, float defVal) const +{ + string val; + char tmp[20]; + + section = CleanString(section); + var = CleanString(var); + + section = '[' + section + ']'; + + sprintf(tmp,"%d",defVal); + val = GetVariable(section,var,tmp); + + if(!atof(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero + return defVal; + else + return static_cast(atof(val.c_str())); //atof returns a double(?!) +} + int ZConfigFile::GetInt(string section, string var, int defVal) const { string val; @@ -258,6 +277,15 @@ string ZConfigFile::GetString(string section, string var, string defVal) const return val; } +void ZConfigFile::SetFloat(string section, string var, float val) +{ + char buf[20]; + sprintf(buf,"%f",val); + + section = '[' + section + ']'; + SetVariable(section,var,buf); +} + void ZConfigFile::SetInt(string section, string var, int val) { char buf[20];