System:
Ubuntu 9.10 64bit
EDIT: i see its already on the tracker....
example:
Code: Select all
#include <irrlicht.h>
class CClientConnectionData
{
public:
class Connection
{
public:
Connection(void)
{
Port = 0;
}
Connection(const Connection& con)
{
IP = con.IP;
Port = con.Port;
Nick = con.Nick;
Password = con.Password;
}
Connection(const irr::c8* ip, const irr::s32& port, const irr::c8* nick, const irr::c8* password)
{
IP = ip;
Port = port;
Nick = nick;
Password = password;
}
irr::core::stringc IP;
irr::s32 Port;
irr::core::stringc Nick;
irr::core::stringc Password;
Connection& operator=(const Connection& con)
{
IP = con.IP;
Port = con.Port;
Nick = con.Nick;
Password = con.Password;
return *this;
}
};
CClientConnectionData(irr::io::IFileSystem* system) : System(system){}
virtual ~CClientConnectionData(){}
irr::core::array<Connection> Connections;
void save(const irr::c8* file)
{
irr::io::IXMLWriter* xml = System->createXMLWriter(file);
xml->writeXMLHeader();
xml->writeElement(L"Connections");
for (irr::u32 i=0;i<Connections.size();++i)
{
irr::io::IAttributes* attributes = System->createEmptyAttributes();
attributes->addString("Server", Connections[i].IP.c_str());
attributes->addInt("Port", Connections[i].Port);
attributes->addString("Nick", Connections[i].Nick.c_str());
attributes->addString("Password", Connections[i].Password.c_str());
attributes->write(xml, false, L"Connection");
attributes->drop();
}
xml->writeClosingTag(L"Connections");
xml->drop();
}
void load(const irr::c8* file)
{
Connections.clear();
irr::io::IXMLReader* xml = System->createXMLReader(file);
bool isConnectionsFile = false;
//printf("ParserFormat: %s\n", xml->getParserFormat() == irr::io::ETF_UTF32_LE ? "ETF_UTF32_LE" : "wtf");
//printf("SourceFormat: %s\n", xml->getSourceFormat() == irr::io::ETF_UTF16_LE ? "ETF_UTF16_LE" : "wtf");
while (xml->read())
{
switch (xml->getNodeType())
{
case irr::io::EXN_COMMENT:
//printf("irr::io::EXN_COMMENT\n");
break;
case irr::io::EXN_CDATA:
//printf("irr::io::EXN_CDATA\n");
break;
case irr::io::EXN_NONE:
//printf("irr::io::EXN_NONE\n");
break;
case irr::io::EXN_TEXT:
//printf("irr::io::EXN_TEXT\n");
break;
case irr::io::EXN_UNKNOWN:
//printf("irr::io::EXN_UNKNOWN\n");
break;
case irr::io::EXN_ELEMENT:
//printf("NodeName: %s\n", xml->getNodeName());
if (irr::core::stringc("Connections") == xml->getNodeName())
isConnectionsFile = true;
else if (irr::core::stringc("Connection") == xml->getNodeName() && isConnectionsFile)
{
irr::io::IAttributes* attributes = System->createEmptyAttributes();
attributes->read(xml, false, L"Connection");
Connection con;
con.IP = attributes->getAttributeAsString("Server");
con.Port = attributes->getAttributeAsInt("Port");
con.Nick = attributes->getAttributeAsString("Nick");
con.Password = attributes->getAttributeAsString("Password");
Connections.push_back(con);
attributes->drop();
}
break;
case irr::io::EXN_ELEMENT_END:
if (irr::core::stringc("Connections") == xml->getNodeName())
isConnectionsFile = false;
break;
}
}
xml->drop();
}
void print(void)
{
printf("Connections[%i]:\n", Connections.size());
for (irr::u32 i=0;i<Connections.size();++i)
{
printf("\tServer: %s\n", Connections[i].IP.c_str());
printf("\tPort: %i\n", Connections[i].Port);
printf("\tNick: %s\n", Connections[i].Nick.c_str());
printf("\tPassword: %s\n", Connections[i].Password.c_str());
}
}
protected:
irr::io::IFileSystem* System;
private:
};
int main(void)
{
irr::IrrlichtDevice* device = irr::createDevice(irr::video::EDT_NULL);
irr::io::IFileSystem* system = device->getFileSystem();
CClientConnectionData data(system);
data.Connections.push_back(CClientConnectionData::Connection("localhost", 5, "sudi", "blubb"));
data.Connections.push_back(CClientConnectionData::Connection("localhost", 5, "master", "haha"));
data.save("test.xml");
data.load("test.xml");
data.print();
data.load("t.xml");
data.print();
device->closeDevice();
device->drop();
return 0;
}
Code: Select all
<?xml version="1.0"?>
<Connections>
<Connection>
<string name="Server" value="localhost"/>
<int name="Port" value="5"/>
<string name="Nick" value="Sudi"/>
<string name="Password" value="blubb"/>
</Connection>
<Connection>
<string name="Server" value="localhost"/>
<int name="Port" value="5"/>
<string name="Nick" value="Master"/>
<string name="Password" value="haha"/>
</Connection>
</Connections>