]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGXMLParse.cpp
Compile under MSVC9 again
[flightgear.git] / src / FDM / JSBSim / input_output / FGXMLParse.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGXMLParse.cpp
4  Author:       Jon Berndt
5  Date started: 08/20/2004
6  Purpose:      Config file read-in class and XML parser
7  Called by:    Various
8
9  ------------- Copyright (C) 2001  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
19  details.
20
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 INCLUDES
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31
32 #include "FGXMLParse.h"
33 #include <cstdlib>
34 #include "input_output/string_utilities.h"
35
36 namespace JSBSim {
37
38 static const char *IdSrc = "$Id$";
39 static const char *IdHdr = ID_XMLPARSE;
40
41 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 CLASS IMPLEMENTATION
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44
45 #include "FGXMLParse.h"
46
47 using namespace std;
48
49 FGXMLParse::FGXMLParse(void)
50 {
51   first_element_read = false;
52   current_element = document = 0L;
53 }
54
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 FGXMLParse::~FGXMLParse(void)
58 {
59   delete document;
60 }
61
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 void FGXMLParse::startXML(void)
65 {
66 }
67
68 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70 void FGXMLParse::reset(void)
71 {
72   delete document;
73   first_element_read = false;
74   current_element = document = 0L;
75 }
76
77 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79 void FGXMLParse::endXML(void)
80 {
81   // At this point, document should equal current_element ?
82 }
83
84 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86 void FGXMLParse::startElement (const char * name, const XMLAttributes &atts)
87 {
88   string Name(name);
89   Element *temp_element;
90
91   working_string.erase();
92
93   if (!first_element_read) {
94     document = new Element(Name);
95     current_element = document;
96     first_element_read = true;
97   } else {
98     temp_element = new Element(Name);
99     temp_element->SetParent(current_element);
100     current_element->AddChildElement(temp_element);
101     current_element = temp_element;
102   }
103
104   if (current_element == 0L) {
105     cerr << "No current element read (no top-level element in XML file?)" << endl;
106     exit (-1);
107   }
108
109   for (int i=0; i<atts.size();i++) {
110     current_element->AddAttribute(atts.getName(i), atts.getValue(i));
111   }
112 }
113
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116 void FGXMLParse::endElement (const char * name)
117 {
118   if (!working_string.empty()) {
119     vector <string> work_strings = split(working_string, '\n');
120     for (int i=0; i<work_strings.size(); i++) current_element->AddData(work_strings[i]);
121   }
122
123   current_element = current_element->GetParent();
124 }
125
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 void FGXMLParse::data (const char * s, int length)
129 {
130   working_string += string(s, length);
131 }
132
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135 void FGXMLParse::pi (const char * target, const char * data)
136 {
137 }
138
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140
141 void FGXMLParse::warning (const char * message, int line, int column)
142 {
143   cerr << "Warning: " << message << " line: " << line << " column: " << column << endl;
144 }
145
146 } // end namespace JSBSim