]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGOutputFile.h
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / JSBSim / input_output / FGOutputFile.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGOutputFile.h
4  Author:       Bertrand Coconnier
5  Date started: 09/10/11
6
7  ------------- Copyright (C) 2011 Bertrand Coconnier  -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 09/10/11   BC    Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGOUTPUTFILE_H
35 #define FGOUTPUTFILE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGFDMExec.h"
42 #include "FGOutputType.h"
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 #define ID_OUTPUTFILE "$Id: FGOutputFile.h,v 1.3 2012/12/15 16:13:57 bcoconni Exp $"
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 FORWARD DECLARATIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 namespace JSBSim {
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS DOCUMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 /** Abstract class that provide functions that are generic to all the outputs
61     that are directed to a file. A new class derived from FGOutputFile should
62     be created for each file format that JSBSim is able to output.
63
64     This class provides all the machinery necessary to manage the file naming
65     including the sequence in which the file should be opened then closed. The
66     logic of SetStartNewOutput() is also managed in this class. Derived class
67     should normally not need to reimplement this method. In most cases, derived
68     classes only need to implement the methods OpenFile(), CloseFile() and
69     Print().
70  */
71
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 CLASS DECLARATION
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75
76 class FGOutputFile : public FGOutputType
77 {
78 public:
79   /// Constructor
80   FGOutputFile(FGFDMExec* fdmex);
81
82   /// Destructor : closes the file.
83   virtual ~FGOutputFile() { CloseFile(); }
84
85   /** Init the output directives from an XML file.
86       @param element XML Element that is pointing to the output directives
87   */
88   bool Load(Element* el);
89
90   /** Initializes the instance. This method basically opens the file to which
91       outputs will be directed.
92       @result true if the execution succeeded.
93    */
94   bool InitModel(void);
95   /** Reset the output prior to a restart of the simulation. This method should
96       be called when the simulation is restarted with, for example, new initial
97       conditions. The current file is closed and reopened with a new name. The
98       new name is contructed from the base file name set by the class
99       constructor or SetOutputName() and is appended with an underscore _ and
100       an ID that is incremented at each call to this method.
101   */
102   void SetStartNewOutput(void);
103   /** Overwrites the name identifier under which the output will be logged.
104       For this method to take effect, it must be called prior to
105       FGFDMExec::RunIC(). If it is called after, it will not take effect before
106       the next call to SetStartNewOutput().
107       @param name new name */
108   void SetOutputName(const std::string& fname) {
109     Name = Filename = FDMExec->GetRootDir() + fname;
110     runID_postfix = 0;
111   }
112   /** Generate the output. This is a pure method so it must be implemented by
113       the classes that inherits from FGOutputFile.
114    */
115   void Print(void) = 0;
116
117 protected:
118   std::string Filename;
119
120   /// Opens the file
121   virtual bool OpenFile(void) = 0;
122   /// Closes the file
123   virtual void CloseFile(void) {}
124
125 private:
126   int runID_postfix;
127 };
128 }
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 #endif
131