-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamedata.cpp
64 lines (55 loc) · 1.66 KB
/
gamedata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "gamedata.h"
Gamedata* Gamedata::getInstance() {
if ( instance == NULL ) instance = new Gamedata;
return instance;
}
Gamedata::Gamedata(const string& fn ) :
parser(fn),
gameData(parser.getXmlData())
{ }
bool Gamedata::getXmlBool(const string& tag) const {
std::map<string, string>::const_iterator ptr = gameData.find(tag);
if ( ptr == gameData.end() )
throw string("Game: Didn't find boolean tag ")+tag+string(" in xml");
else {
if ( ptr->second == "true" ) return true;
else return false;
}
}
int Gamedata::getXmlInt(const string& tag) const {
std::map<string, string>::const_iterator ptr = gameData.find(tag);
if ( ptr == gameData.end() )
throw string("Game: Didn't find integer tag ")+tag+string(" in xml");
else {
std::stringstream strm;
strm << ptr->second;
int data;
strm >> data;
return data;
}
}
float Gamedata::getXmlFloat(const string& tag) const {
std::map<string, string>::const_iterator ptr = gameData.find(tag);
if ( ptr == gameData.end() )
throw string("Game: Didn't find float tag ")+tag+string(" in xml");
else {
std::stringstream strm;
strm << ptr->second;
float data;
strm >> data;
return data;
}
}
const string& Gamedata::getXmlStr(const string& tag) const {
std::map<string, string>::const_iterator ptr = gameData.find(tag);
if ( ptr == gameData.end() )
throw string("Game: Didn't find string tag ")+tag+string(" in xml");
else return ptr->second;
}
void Gamedata::displayData() const {
std::map<string, string>::const_iterator ptr = gameData.begin();
while ( ptr != gameData.end() ) {
cout << ptr->first << ", " << ptr->second << endl;
++ptr;
}
}