In der Headerdatei folgende Includes:
Code:
#include <irrlicht.h>
#include <irrXML.h>
#include <string>
#include <iostream> // Wobei ich gerade nicht weiss wofür ich das brauchte.
Code:
void CSettings::Load(std::string fileName)
{
irr::io::IrrXMLReader* xml = irr::io::createIrrXMLReader(fileName.c_str());
if (xml == 0)
return; // file could not be opened
bool isScreenOpen = false;
bool isWidthOpen = false;
bool isHeightOpen = false;
bool isBppOpen = false;
bool isFullScreenOpen = false;
// parse the file until end reached
while(xml->read())
{
switch(xml->getNodeType())
{
case irr::io::EXN_ELEMENT:
{
std::string data = xml->getNodeData();
if (data == "width")
{
isWidthOpen = true;
} else if(data == "height") {
isHeightOpen = true;
} else if( data == "bpp") {
isBppOpen = true;
} else if(data == "fullscreen") {
isFullScreenOpen = true;
}
break;
} // end irr::io::EXN_ELEMENT
case irr::io::EXN_ELEMENT_END:
{
std::string data = xml->getNodeData();
if (data == "width")
{
isWidthOpen = false;
} else if(data == "height") {
isHeightOpen = false;
} else if( data == "bpp") {
isBppOpen = false;
} else if(data == "fullscreen") {
isFullScreenOpen = false;
}
break;
} // end irr::io::EXN_ELEMENT_END
case irr::io::EXN_TEXT:
{
std::string data = xml->getNodeData();
if(isWidthOpen)
{
this->screenWidthValue = atoi(data.c_str());
} else if(isHeightOpen) {
this->screenHeightValue = atoi(data.c_str());
} else if(isBppOpen) {
this->screenBppValue = atoi(data.c_str());
} else if(isFullScreenOpen) {
__int32 i = atoi(data.c_str());
if (i == 0) {
this->isFullScreenValue = false;
} else {
this->isFullScreenValue = true;
}
}
break;
} // end irr::io::EXN_TEXT
} // end switch
} // end while
delete xml;
}
Die Datei dazu sieht so aus:
Code:
<xml>
<screen>
<width>1024</width>
<height>768</height>
<bpp>16</bpp>
<fullscreen>0</fullscreen>
</screen>
</xml>
Das ganze wäre auch noch variabler machbar, in dem man eine Klasse baut die von std::map<std::string, std::string> erbt. Und entsprechende Methoden zum Konvertieren hat.
Also in etwa so.
Code:
class MySett : std::map<std::string, std::string>
{
public:
__int16 GetInt16(std::string key);
__int32 GetInt32(std::string key);
std::string GetString(std::string key);
// etc.
};
Das ganze , in dem man z.B. alle Werte in eine std::map<std::string, std::string> einliest, dann hätte man wieder sowas wie *.ini Dateien.