git repos / blockattack-game

blame: source/code/common.cpp

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
c53e6443 sago007 2012-04-17 11:04 20
http://blockattack.sf.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
89c4a3a6 sago007 2008-08-29 14:32 22
*/
89c4a3a6 sago007 2008-08-29 14:32 23
89c4a3a6 sago007 2008-08-29 14:32 24
#include "common.h"
769a41a0 sago007 2008-09-24 12:54 25
#include <sstream>
769a41a0 sago007 2008-09-24 12:54 26
53001fa2 sago007 2015-11-08 15:13 27
using namespace std;
53001fa2 sago007 2015-11-08 15:13 28
using boost::format;
53001fa2 sago007 2015-11-08 15:13 29
444cec07 sago007 2012-05-05 16:42 30
static stringstream converter;
444cec07 sago007 2012-05-05 16:42 31
769a41a0 sago007 2008-09-24 12:54 32
//Function to convert numbers to string
769a41a0 sago007 2008-09-24 12:54 33
string itoa(int num)
769a41a0 sago007 2008-09-24 12:54 34
{
444cec07 sago007 2012-05-05 16:42 35
	converter.str(std::string());
444cec07 sago007 2012-05-05 16:42 36
	converter.clear();
c53e6443 sago007 2012-04-17 11:04 37
	converter << num;
c53e6443 sago007 2012-04-17 11:04 38
	return converter.str();
769a41a0 sago007 2008-09-24 12:54 39
}
769a41a0 sago007 2008-09-24 12:54 40
769a41a0 sago007 2008-09-24 12:54 41
string double2str(double num)
769a41a0 sago007 2008-09-24 12:54 42
{
444cec07 sago007 2012-05-05 16:42 43
	converter.str(std::string());
444cec07 sago007 2012-05-05 16:42 44
	converter.clear();
c53e6443 sago007 2012-04-17 11:04 45
	converter << num;
c53e6443 sago007 2012-04-17 11:04 46
	return converter.str();
c53e6443 sago007 2012-04-17 11:04 47
}
769a41a0 sago007 2008-09-24 12:54 48
d07b805e sago007 2009-01-27 13:15 49
/**
d07b805e sago007 2009-01-27 13:15 50
 * str2double parses a string and returns a double with the value of the string.
fcd5a134 sago007 2008-12-19 01:11 51
 * if the string is not a double then 0.0 is returned instead of throing an error
fcd5a134 sago007 2008-12-19 01:11 52
 * in that way this function will always return a useable value.
fcd5a134 sago007 2008-12-19 01:11 53
 */
af35c39d sago007 2013-11-16 16:37 54
double str2double(const string &str2parse)
769a41a0 sago007 2008-09-24 12:54 55
{
c53e6443 sago007 2012-04-17 11:04 56
	try
c53e6443 sago007 2012-04-17 11:04 57
	{
444cec07 sago007 2012-05-05 16:42 58
		converter.clear();
444cec07 sago007 2012-05-05 16:42 59
		converter.str(str2parse);
c53e6443 sago007 2012-04-17 11:04 60
		double val = 0.0;
c53e6443 sago007 2012-04-17 11:04 61
		converter >> val;
c53e6443 sago007 2012-04-17 11:04 62
		return val;
c53e6443 sago007 2012-04-17 11:04 63
	}
af35c39d sago007 2013-11-16 16:37 64
	catch(ios_base::failure &f)
c53e6443 sago007 2012-04-17 11:04 65
	{
c53e6443 sago007 2012-04-17 11:04 66
		return 0.0;
c53e6443 sago007 2012-04-17 11:04 67
	}
769a41a0 sago007 2008-09-24 12:54 68
}
769a41a0 sago007 2008-09-24 12:54 69
d07b805e sago007 2009-01-27 13:15 70
/**
d07b805e sago007 2009-01-27 13:15 71
 * str2int parses a string and returns an int with the value of the string.
fcd5a134 sago007 2008-12-19 01:11 72
 * if the string is not an int then 0 is returned instead of throing an error
fcd5a134 sago007 2008-12-19 01:11 73
 * in that way this function will always return a useable value.
fcd5a134 sago007 2008-12-19 01:11 74
 */
af35c39d sago007 2013-11-16 16:37 75
int str2int(const string &str2parse)
769a41a0 sago007 2008-09-24 12:54 76
{
c53e6443 sago007 2012-04-17 11:04 77
	try
c53e6443 sago007 2012-04-17 11:04 78
	{
444cec07 sago007 2012-05-05 16:42 79
		converter.clear();
444cec07 sago007 2012-05-05 16:42 80
		converter.str(str2parse);
c53e6443 sago007 2012-04-17 11:04 81
		int val = 0;
c53e6443 sago007 2012-04-17 11:04 82
		converter >> val;
c53e6443 sago007 2012-04-17 11:04 83
		return val;
c53e6443 sago007 2012-04-17 11:04 84
	}
af35c39d sago007 2013-11-16 16:37 85
	catch(ios_base::failure &f)
c53e6443 sago007 2012-04-17 11:04 86
	{
c53e6443 sago007 2012-04-17 11:04 87
		return 0;
c53e6443 sago007 2012-04-17 11:04 88
	}
769a41a0 sago007 2008-09-24 12:54 89
}
89c4a3a6 sago007 2008-08-29 14:32 90
89c4a3a6 sago007 2008-08-29 14:32 91
#ifdef WIN32
89c4a3a6 sago007 2008-08-29 14:32 92
//Returns path to "my Documents" in windows:
89c4a3a6 sago007 2008-08-29 14:32 93
string getMyDocumentsPath()
89c4a3a6 sago007 2008-08-29 14:32 94
{
c53e6443 sago007 2012-04-17 11:04 95
	TCHAR pszPath[MAX_PATH];
acd79baf sago007 2015-11-22 19:37 96
	//if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) {
acd79baf sago007 2015-11-22 19:37 97
	if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, 0, pszPath)))
c53e6443 sago007 2012-04-17 11:04 98
	{
c53e6443 sago007 2012-04-17 11:04 99
		// pszPath is now the path that you want
724439a5 sago007 2008-09-11 15:52 100
#if DEBUG
c53e6443 sago007 2012-04-17 11:04 101
		cout << "MyDocuments Located: " << pszPath << endl;
89c4a3a6 sago007 2008-08-29 14:32 102
#endif
c53e6443 sago007 2012-04-17 11:04 103
		string theResult= pszPath;
c53e6443 sago007 2012-04-17 11:04 104
		return theResult;
c53e6443 sago007 2012-04-17 11:04 105
	}
c53e6443 sago007 2012-04-17 11:04 106
	else
c53e6443 sago007 2012-04-17 11:04 107
	{
c53e6443 sago007 2012-04-17 11:04 108
		cout << "Warning: My Documents not found!" << endl;
c53e6443 sago007 2012-04-17 11:04 109
		string theResult ="";
c53e6443 sago007 2012-04-17 11:04 110
		return theResult;
c53e6443 sago007 2012-04-17 11:04 111
	}
89c4a3a6 sago007 2008-08-29 14:32 112
}
89c4a3a6 sago007 2008-08-29 14:32 113
89c4a3a6 sago007 2008-08-29 14:32 114
#endif
89c4a3a6 sago007 2008-08-29 14:32 115
d07b805e sago007 2009-01-27 13:15 116
/**
d07b805e sago007 2009-01-27 13:15 117
 * Returns the path to where all settings must be saved.
d07b805e sago007 2009-01-27 13:15 118
 * On unix-like systems this is the home-folder under: ~/.gamesaves/GAMENAME
d07b805e sago007 2009-01-27 13:15 119
 * In Windows it is My Documents/My Games
d07b805e sago007 2009-01-27 13:15 120
 * Consider changing this for Vista that has a special save games folder
d07b805e sago007 2009-01-27 13:15 121
 */
89c4a3a6 sago007 2008-08-29 14:32 122
string getPathToSaveFiles()
89c4a3a6 sago007 2008-08-29 14:32 123
{
89c4a3a6 sago007 2008-08-29 14:32 124
#ifdef __unix__
c53e6443 sago007 2012-04-17 11:04 125
	return (string)getenv("HOME")+(string)"/.gamesaves/"+GAMENAME;
89c4a3a6 sago007 2008-08-29 14:32 126
#elif WIN32
c53e6443 sago007 2012-04-17 11:04 127
	return getMyDocumentsPath()+(string)"/My Games/"+GAMENAME;
89c4a3a6 sago007 2008-08-29 14:32 128
#else
c53e6443 sago007 2012-04-17 11:04 129
	return ".";
89c4a3a6 sago007 2008-08-29 14:32 130
#endif
89c4a3a6 sago007 2008-08-29 14:32 131
}
89c4a3a6 sago007 2008-08-29 14:32 132
d07b805e sago007 2009-01-27 13:15 133
/**
d07b805e sago007 2009-01-27 13:15 134
 * Takes a number of milliseconds and returns the value in commonTime format.
d07b805e sago007 2009-01-27 13:15 135
 */
cd12e0fe sago007 2009-01-29 08:47 136
commonTime TimeHandler::ms2ct(unsigned int milliseconds)
c09d0e4f sago007 2009-01-27 01:15 137
{
c53e6443 sago007 2012-04-17 11:04 138
	commonTime ct;
c53e6443 sago007 2012-04-17 11:04 139
	ct.days = 0;
c53e6443 sago007 2012-04-17 11:04 140
	unsigned int time = milliseconds;
c53e6443 sago007 2012-04-17 11:04 141
	ct.hours = time/(1000*60*60);
c53e6443 sago007 2012-04-17 11:04 142
	time = time % (1000*60*60);
c53e6443 sago007 2012-04-17 11:04 143
	ct.minutes = time/(1000*60);
c53e6443 sago007 2012-04-17 11:04 144
	time = time % (1000*60);
c53e6443 sago007 2012-04-17 11:04 145
	ct.seconds = time/1000;
c53e6443 sago007 2012-04-17 11:04 146
	return ct;
c09d0e4f sago007 2009-01-27 01:15 147
}
89c4a3a6 sago007 2008-08-29 14:32 148
af35c39d sago007 2013-11-16 16:37 149
commonTime TimeHandler::getTime(const string &name)
89c4a3a6 sago007 2008-08-29 14:32 150
{
c53e6443 sago007 2012-04-17 11:04 151
	commonTime ct;
c53e6443 sago007 2012-04-17 11:04 152
	ct.days = Config::getInstance()->getInt(name+"Days");
c53e6443 sago007 2012-04-17 11:04 153
	ct.hours = Config::getInstance()->getInt(name+"Hours");
c53e6443 sago007 2012-04-17 11:04 154
	ct.minutes = Config::getInstance()->getInt(name+"Minutes");
c53e6443 sago007 2012-04-17 11:04 155
	ct.seconds = Config::getInstance()->getInt(name+"Seconds");
c53e6443 sago007 2012-04-17 11:04 156
	return ct;
89c4a3a6 sago007 2008-08-29 14:32 157
}
89c4a3a6 sago007 2008-08-29 14:32 158
d07b805e sago007 2009-01-27 13:15 159
/**
c53e6443 sago007 2012-04-17 11:04 160
 * Returns the total runtime with toAdd added but without writing it to config file.
d07b805e sago007 2009-01-27 13:15 161
 * Used for stats
c09d0e4f sago007 2009-01-27 01:15 162
 */
af35c39d sago007 2013-11-16 16:37 163
commonTime TimeHandler::peekTime(const string &name, const commonTime &toAdd)
89c4a3a6 sago007 2008-08-29 14:32 164
{
c53e6443 sago007 2012-04-17 11:04 165
	commonTime ct = getTime(name);
c09d0e4f sago007 2009-01-27 01:15 166
c53e6443 sago007 2012-04-17 11:04 167
	ct.seconds +=toAdd.seconds;
c53e6443 sago007 2012-04-17 11:04 168
	ct.minutes +=ct.seconds/60;
c53e6443 sago007 2012-04-17 11:04 169
	ct.seconds = ct.seconds%60;
c09d0e4f sago007 2009-01-27 01:15 170
c53e6443 sago007 2012-04-17 11:04 171
	ct.minutes += toAdd.minutes;
c53e6443 sago007 2012-04-17 11:04 172
	ct.hours += ct.minutes/60;
c53e6443 sago007 2012-04-17 11:04 173
	ct.minutes = ct.minutes%60;
c09d0e4f sago007 2009-01-27 01:15 174
c53e6443 sago007 2012-04-17 11:04 175
	ct.hours += toAdd.hours;
c53e6443 sago007 2012-04-17 11:04 176
	ct.days += ct.hours/24;
c53e6443 sago007 2012-04-17 11:04 177
	ct.hours = ct.hours%24;
c09d0e4f sago007 2009-01-27 01:15 178
c53e6443 sago007 2012-04-17 11:04 179
	ct.days += toAdd.days;
c53e6443 sago007 2012-04-17 11:04 180
	return ct;
c09d0e4f sago007 2009-01-27 01:15 181
}
c09d0e4f sago007 2009-01-27 01:15 182
d07b805e sago007 2009-01-27 13:15 183
/**
c09d0e4f sago007 2009-01-27 01:15 184
 * Same as peekTotalTime but writes the time to the config file.
d07b805e sago007 2009-01-27 13:15 185
 * Should only be called only once! when the program shuts down
c09d0e4f sago007 2009-01-27 01:15 186
 */
af35c39d sago007 2013-11-16 16:37 187
commonTime TimeHandler::addTime(const string &name, const commonTime &toAdd)
c09d0e4f sago007 2009-01-27 01:15 188
{
c53e6443 sago007 2012-04-17 11:04 189
	commonTime ct = peekTime(name,toAdd);
c53e6443 sago007 2012-04-17 11:04 190
c53e6443 sago007 2012-04-17 11:04 191
	Config::getInstance()->setInt(name+"Days",ct.days);
c53e6443 sago007 2012-04-17 11:04 192
	Config::getInstance()->setInt(name+"Hours",ct.hours);
c53e6443 sago007 2012-04-17 11:04 193
	Config::getInstance()->setInt(name+"Minutes",ct.minutes);
c53e6443 sago007 2012-04-17 11:04 194
	Config::getInstance()->setInt(name+"Seconds",ct.seconds);
c53e6443 sago007 2012-04-17 11:04 195
	return ct;
89c4a3a6 sago007 2008-08-29 14:32 196
}
769a41a0 sago007 2008-09-24 12:54 197
769a41a0 sago007 2008-09-24 12:54 198
Config* Config::instance = 0;
769a41a0 sago007 2008-09-24 12:54 199
769a41a0 sago007 2008-09-24 12:54 200
Config::Config()
769a41a0 sago007 2008-09-24 12:54 201
{
c53e6443 sago007 2012-04-17 11:04 202
	configMap.clear();
c53e6443 sago007 2012-04-17 11:04 203
	load();
c53e6443 sago007 2012-04-17 11:04 204
	shuttingDown = 0; // Not shutting down
769a41a0 sago007 2008-09-24 12:54 205
}
769a41a0 sago007 2008-09-24 12:54 206
769a41a0 sago007 2008-09-24 12:54 207
void Config::load()
769a41a0 sago007 2008-09-24 12:54 208
{
c53e6443 sago007 2012-04-17 11:04 209
	string filename = getPathToSaveFiles()+"/configFile";
c53e6443 sago007 2012-04-17 11:04 210
	ifstream inFile(filename.c_str());
c53e6443 sago007 2012-04-17 11:04 211
	string key;
c53e6443 sago007 2012-04-17 11:04 212
	string previuskey;
c53e6443 sago007 2012-04-17 11:04 213
	char value[MAX_VAR_LENGTH];
c53e6443 sago007 2012-04-17 11:04 214
	if(inFile)
c53e6443 sago007 2012-04-17 11:04 215
	{
c53e6443 sago007 2012-04-17 11:04 216
		while(!inFile.eof())
c53e6443 sago007 2012-04-17 11:04 217
		{
c53e6443 sago007 2012-04-17 11:04 218
			inFile >> key;
acd79baf sago007 2015-11-22 19:37 219
			if(key==previuskey) { //the last entry will be read 2 times if a linebreak is missing in the end
c53e6443 sago007 2012-04-17 11:04 220
				continue;
acd79baf sago007 2015-11-22 19:37 221
			}
c53e6443 sago007 2012-04-17 11:04 222
			previuskey = key;
c53e6443 sago007 2012-04-17 11:04 223
			inFile.get(); //Read the space between the key and the content
c53e6443 sago007 2012-04-17 11:04 224
			inFile.getline(value,MAX_VAR_LENGTH);
c53e6443 sago007 2012-04-17 11:04 225
#if DEBUG
c53e6443 sago007 2012-04-17 11:04 226
			cout << "Config "<< "read: " << key << " with:\"" << value << "\"" << endl;
c53e6443 sago007 2012-04-17 11:04 227
#endif
c53e6443 sago007 2012-04-17 11:04 228
			configMap[key] = (string)value;
c53e6443 sago007 2012-04-17 11:04 229
		}
c53e6443 sago007 2012-04-17 11:04 230
		inFile.close();
c53e6443 sago007 2012-04-17 11:04 231
	}
769a41a0 sago007 2008-09-24 12:54 232
}
769a41a0 sago007 2008-09-24 12:54 233
769a41a0 sago007 2008-09-24 12:54 234
Config* Config::getInstance()
769a41a0 sago007 2008-09-24 12:54 235
{
c53e6443 sago007 2012-04-17 11:04 236
	if(Config::instance==0)
c53e6443 sago007 2012-04-17 11:04 237
	{
c53e6443 sago007 2012-04-17 11:04 238
		Config::instance = new Config();
c53e6443 sago007 2012-04-17 11:04 239
c53e6443 sago007 2012-04-17 11:04 240
	}
c53e6443 sago007 2012-04-17 11:04 241
	return Config::instance;
769a41a0 sago007 2008-09-24 12:54 242
}
769a41a0 sago007 2008-09-24 12:54 243
769a41a0 sago007 2008-09-24 12:54 244
void Config::save()
769a41a0 sago007 2008-09-24 12:54 245
{
c53e6443 sago007 2012-04-17 11:04 246
	string filename = getPathToSaveFiles()+"/configFile";
c53e6443 sago007 2012-04-17 11:04 247
	ofstream outFile(filename.c_str(),ios::trunc);
c53e6443 sago007 2012-04-17 11:04 248
c53e6443 sago007 2012-04-17 11:04 249
	if(outFile)
c53e6443 sago007 2012-04-17 11:04 250
	{
c53e6443 sago007 2012-04-17 11:04 251
		map<string,string>::iterator iter;
c53e6443 sago007 2012-04-17 11:04 252
		for(iter = configMap.begin(); iter != configMap.end(); iter++)
c53e6443 sago007 2012-04-17 11:04 253
		{
c53e6443 sago007 2012-04-17 11:04 254
			outFile << iter->first << " " << iter->second << endl;
c53e6443 sago007 2012-04-17 11:04 255
		}
c53e6443 sago007 2012-04-17 11:04 256
		outFile << "\n"; //The last entry in the file will be read double if a linebreak is missing
c53e6443 sago007 2012-04-17 11:04 257
		//This is checked on load too in case a user changes it himself.
c53e6443 sago007 2012-04-17 11:04 258
	}
c53e6443 sago007 2012-04-17 11:04 259
	outFile.close();
769a41a0 sago007 2008-09-24 12:54 260
}
769a41a0 sago007 2008-09-24 12:54 261
af35c39d sago007 2013-11-16 16:37 262
bool Config::exists(const string &varName) const
769a41a0 sago007 2008-09-24 12:54 263
{
c53e6443 sago007 2012-04-17 11:04 264
	//Using that find returns an iterator to the end of the map if not found
c53e6443 sago007 2012-04-17 11:04 265
	return configMap.find(varName) != configMap.end();
769a41a0 sago007 2008-09-24 12:54 266
}
769a41a0 sago007 2008-09-24 12:54 267
af35c39d sago007 2013-11-16 16:37 268
void Config::setDefault(const string &varName,const string &content)
42f8ed5f sago007 2009-03-05 11:47 269
{
acd79baf sago007 2015-11-22 19:37 270
	if(exists(varName)) {
acd79baf sago007 2015-11-22 19:37 271
		return;    //Already exists do not change
acd79baf sago007 2015-11-22 19:37 272
	}
c53e6443 sago007 2012-04-17 11:04 273
	setString(varName,content);
42f8ed5f sago007 2009-03-05 11:47 274
}
42f8ed5f sago007 2009-03-05 11:47 275
c53e6443 sago007 2012-04-17 11:04 276
void Config::setShuttingDown(long shuttingDown)
c53e6443 sago007 2012-04-17 11:04 277
{
c53e6443 sago007 2012-04-17 11:04 278
	this->shuttingDown = shuttingDown;
cc3ef158 sago007 2011-07-03 16:13 279
}
cc3ef158 sago007 2011-07-03 16:13 280
c53e6443 sago007 2012-04-17 11:04 281
long Config::isShuttingDown() const
c53e6443 sago007 2012-04-17 11:04 282
{
c53e6443 sago007 2012-04-17 11:04 283
	return shuttingDown;
cc3ef158 sago007 2011-07-03 16:13 284
}
cc3ef158 sago007 2011-07-03 16:13 285
af35c39d sago007 2013-11-16 16:37 286
void Config::setString(const string &varName, const string &content)
769a41a0 sago007 2008-09-24 12:54 287
{
c53e6443 sago007 2012-04-17 11:04 288
	configMap[varName] = content;
769a41a0 sago007 2008-09-24 12:54 289
}
769a41a0 sago007 2008-09-24 12:54 290
af35c39d sago007 2013-11-16 16:37 291
void Config::setInt(const string &varName, int content)
769a41a0 sago007 2008-09-24 12:54 292
{
c53e6443 sago007 2012-04-17 11:04 293
	configMap[varName] = itoa(content);
769a41a0 sago007 2008-09-24 12:54 294
}
769a41a0 sago007 2008-09-24 12:54 295
af35c39d sago007 2013-11-16 16:37 296
void Config::setValue(const string &varName,double content)
769a41a0 sago007 2008-09-24 12:54 297
{
c53e6443 sago007 2012-04-17 11:04 298
	configMap[varName] = double2str(content);
769a41a0 sago007 2008-09-24 12:54 299
}
769a41a0 sago007 2008-09-24 12:54 300
af35c39d sago007 2013-11-16 16:37 301
string Config::getString(const string &varName)
769a41a0 sago007 2008-09-24 12:54 302
{
c53e6443 sago007 2012-04-17 11:04 303
	if(exists(varName))
c53e6443 sago007 2012-04-17 11:04 304
	{
c53e6443 sago007 2012-04-17 11:04 305
		return configMap[varName];
c53e6443 sago007 2012-04-17 11:04 306
	}
acd79baf sago007 2015-11-22 19:37 307
	else {
c53e6443 sago007 2012-04-17 11:04 308
		return "";
acd79baf sago007 2015-11-22 19:37 309
	}
769a41a0 sago007 2008-09-24 12:54 310
}
769a41a0 sago007 2008-09-24 12:54 311
af35c39d sago007 2013-11-16 16:37 312
int Config::getInt(const string &varName)
769a41a0 sago007 2008-09-24 12:54 313
{
c53e6443 sago007 2012-04-17 11:04 314
	if(exists(varName))
c53e6443 sago007 2012-04-17 11:04 315
	{
c53e6443 sago007 2012-04-17 11:04 316
		return str2int(configMap[varName]);
c53e6443 sago007 2012-04-17 11:04 317
	}
acd79baf sago007 2015-11-22 19:37 318
	else {
c53e6443 sago007 2012-04-17 11:04 319
		return 0;
acd79baf sago007 2015-11-22 19:37 320
	}
769a41a0 sago007 2008-09-24 12:54 321
}
769a41a0 sago007 2008-09-24 12:54 322
af35c39d sago007 2013-11-16 16:37 323
double Config::getValue(const string &varName)
769a41a0 sago007 2008-09-24 12:54 324
{
c53e6443 sago007 2012-04-17 11:04 325
	if(exists(varName))
c53e6443 sago007 2012-04-17 11:04 326
	{
c53e6443 sago007 2012-04-17 11:04 327
		return str2double(configMap[varName]);
c53e6443 sago007 2012-04-17 11:04 328
	}
acd79baf sago007 2015-11-22 19:37 329
	else {
c53e6443 sago007 2012-04-17 11:04 330
		return 0.0;
acd79baf sago007 2015-11-22 19:37 331
	}
769a41a0 sago007 2008-09-24 12:54 332
}
1970-01-01 00:00 333