JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGXMLFileRead.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGXMLFileRead.h
4  Author: Jon S. Berndt
5  Date started: 02/04/07
6  Purpose: Shared base class that wraps the XML file reading logic
7 
8  ------------- Copyright (C) 2007 Jon S. Berndt (jon@jsbsim.org) -------------
9 
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  details.
19 
20  You should have received a copy of the GNU Lesser General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Further information about the GNU Lesser General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26 
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 SENTRY
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30 
31 #ifndef FGXMLFILEREAD_HEADER_H
32 #define FGXMLFILEREAD_HEADER_H
33 
34 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 
38 #include <iostream>
39 #include <fstream>
40 
41 #include "input_output/FGXMLParse.h"
42 #include "simgear/misc/sg_path.hxx"
43 #include "simgear/io/iostreams/sgstream.hxx"
44 
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 
49 #define ID_XMLFILEREAD "$Id: FGXMLFileRead.h,v 1.10 2017/02/25 14:23:18 bcoconni Exp $"
50 
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 
55 namespace JSBSim {
56 
58 public:
59  FGXMLFileRead(void) {}
60  ~FGXMLFileRead(void) {}
61 
62  Element* LoadXMLDocument(const SGPath& XML_filename, bool verbose=true)
63  {
64  return LoadXMLDocument(XML_filename, file_parser, verbose);
65  }
66 
67  Element* LoadXMLDocument(const SGPath& XML_filename, FGXMLParse& fparse, bool verbose=true)
68  {
69  sg_ifstream infile;
70  SGPath filename(XML_filename);
71 
72  if (!filename.isNull()) {
73  if (filename.extension().empty())
74  filename.concat(".xml");
75 
76  infile.open(filename);
77  if ( !infile.is_open()) {
78  if (verbose) std::cerr << "Could not open file: " << filename << std::endl;
79  return 0L;
80  }
81  } else {
82  std::cerr << "No filename given." << std::endl;
83  return 0L;
84  }
85 
86  readXML(infile, fparse, filename.utf8Str());
87  Element* document = fparse.GetDocument();
88  infile.close();
89 
90  return document;
91  }
92 
93  void ResetParser(void) {file_parser.reset();}
94 
95 private:
96  FGXMLParse file_parser;
97 };
98 }
99 #endif
Encapsulates an XML parser based on the EasyXML parser from the SimGear library.
Definition: FGXMLParse.h:68