1 /*
2 * CRRCsim - the Charles River Radio Control Club Flight Simulator Project
3 * Copyright (C) 2010 - Jens Wilhelm Wulf (original author)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty off
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 */
20 #include "robotfile.h"
21
22 #include <iostream>
23
RobotFile(std::string filename)24 RobotFile::RobotFile(std::string filename)
25 {
26 char buf[7*sizeof(double)+1];
27 SimpleXMLTransfer* tmp;
28 std::ifstream infile;
29
30 infile.open(filename.c_str(), std::ios::binary);
31
32 try
33 {
34 // Read mandatory XML header
35 tmp = new SimpleXMLTransfer(infile);
36 xmls.push_back(tmp);
37 // skip trailing '\n'
38 infile.read(buf, 1);
39
40 do
41 {
42 infile.read(buf, 1);
43 switch (buf[0])
44 {
45 case 0x00:
46 infile.read(&(buf[1]), 8+3*4+3*2);
47 break;
48
49 case 0x02: // marker
50 RobotFile::ReadInt32(infile);
51 break;
52
53 case 0x03: // xml
54 tmp = new SimpleXMLTransfer(infile);
55 // skip trailing '\n'
56 infile.read(&(buf[1]), 1);
57 xmls.push_back(tmp);
58 break;
59
60 default:
61 std::cerr << "unknown record type: " << (int)(buf[0]) << "\n";
62 break;
63 }
64 }
65 while (!infile.eof());
66 }
67 catch (XMLException e)
68 {
69 }
70 infile.close();
71 }
72
~RobotFile()73 RobotFile::~RobotFile()
74 {
75 for (unsigned int n=0; n<xmls.size(); n++)
76 delete xmls[n];
77 }
78
ReadDescription()79 std::string RobotFile::ReadDescription()
80 {
81 for (unsigned int n=0; n<xmls.size(); n++)
82 if (xmls[n]->getName().compare("descr") == 0)
83 return(xmls[n]->getContentString());
84 return("");
85 }
86
87