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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
struct nxaNode {
public:
int* iVertex;
int* iIndex;
int iNumOfVerts, iNumOfIndex;
void output(std::fstream& f) {
f.write((char*)iNumOfVerts, sizeof(int));
f.write((char*)iVertex, sizeof(int)*iNumOfVerts);
f.write((char*)iNumOfIndex, sizeof(int));
f.write((char*)iIndex, sizeof(int)*iNumOfIndex);
}
void input(std::fstream& f) {
f.read((char*)&iNumOfVerts, sizeof(int));
f.read((char*)&iVertex, sizeof(int)*iNumOfVerts);
f.read((char*)&iNumOfIndex, sizeof(int));
f.read((char*)&iIndex, sizeof(int)*iNumOfIndex);
}
};
struct nxaFile {
public:
nxaNode* nodes;
int iNumOfNodes;
void output(std::fstream& f) {
f.write((char*)iNumOfNodes, sizeof(int));
f.write((char*)nodes, sizeof(nxaNode)*iNumOfNodes);
for(int i = 0; i < iNumOfNodes; i++) {
nodes[i].output(f);
}
}
void input(std::fstream& f) {
f.read((char*)&iNumOfNodes, sizeof(int));
nodes = new nxaNode[iNumOfNodes + 1];
f.read((char*)&nodes, sizeof(nxaNode)*iNumOfNodes);
for(int i = 0; i < iNumOfNodes; i++) {
nodes[i].input(f);
}
}
};
nxaFile theNXA;
void save() {
std::fstream f("test.nxa", std::ios::out | std::ios::binary);
theNXA.output(f);
f.close();
}
int main(int argc, char* argv[])
{
std::cout << "Dumping file..." << std::endl;
theNXA.iNumOfNodes = 10;
theNXA.nodes = new nxaNode[10];
for(int i = 0; i < 10; i++) {
theNXA.nodes[i].iNumOfIndex = 10;
theNXA.nodes[i].iNumOfVerts = 10;
theNXA.nodes[i].iVertex = new int[10];
theNXA.nodes[i].iIndex = new int[10];
for(int x = 0; x < 10; x++) {
theNXA.nodes[i].iVertex[x] = x;
theNXA.nodes[i].iIndex[x] = x + x;
}
}
save();
for(int i = 0; i < 10; i++) {
delete[] theNXA.nodes[i].iIndex;
delete[] theNXA.nodes[i].iVertex;
}
delete[] theNXA.nodes;
return 0;
}
|