]> git.mxchange.org Git - flightgear.git/blob - src/ATC/transmission.hxx
try to fix yet another crash bug (don't worry, there's one for anybody!)
[flightgear.git] / src / ATC / transmission.hxx
1 // transmission.hxx -- Transmission class
2 //
3 // Written by Alexander Kappes, started March 2002.
4 // Based on nav.hxx by Curtis Olson, started April 2000.
5 //
6 // Copyright (C) 2001  David C. Luff - david.luff@nottingham.ac.uk
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22
23 #ifndef _FG_TRANSMISSION_HXX
24 #define _FG_TRANSMISSION_HXX
25
26 #include <stdio.h>
27
28 #include <simgear/compiler.h>
29 #include <simgear/math/sg_geodesy.hxx>
30 #include <simgear/misc/sgstream.hxx>
31 #include <simgear/magvar/magvar.hxx>
32 #include <simgear/timing/sg_time.hxx>
33 #include <simgear/bucket/newbucket.hxx>
34
35 #include <Main/fg_props.hxx>
36
37 #ifdef SG_HAVE_STD_INCLUDES
38 #  include <istream>
39 #include <iomanip>
40 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
41 #  include <iostream.h>
42 #elif defined( __BORLANDC__ )
43 #  include <iostream>
44 #else
45 #  include <istream.h>
46 #include <iomanip.h>
47 #endif
48
49 #include "ATC.hxx"
50
51 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
52 SG_USING_STD(istream);
53 #endif
54
55 SG_USING_STD(string);
56
57 struct TransCode {
58   int c1;
59   int c2;
60   int c3;
61 };
62
63 // TransPar - a representation of the logic of a parsed speech transmission
64 struct TransPar {
65   string  station;
66   string  callsign;
67   string  airport;
68   string  intention;      // landing, crossing
69   string  intid;          // (airport) ID for intention
70   bool    request;        // is the transmission a request or an answer?
71   int     tdir;           // turning direction: 1=left, 2=right
72   double  heading;
73   int     VDir;           // vertical direction: 1=descent, 2=maintain, 3=climb
74   double  alt;
75   double  miles;
76   string  runway;
77   double  freq;
78   double  time;
79 };
80
81 // FGTransmission - a class to encapsulate a speech transmission
82 class FGTransmission {
83
84   //int       StationType;    // Type of ATC station: 1 Approach
85   atc_type  StationType;
86   TransCode Code;           // DCL - no idea what this is.
87   string    TransText;      // The text of the spoken transmission
88   string    MenuText;       // An abbreviated version of the text for the menu entry
89
90 public:
91
92   FGTransmission(void);
93   ~FGTransmission(void);
94
95   void Init();
96
97   inline atc_type  get_station()   const { return StationType; }
98   inline const TransCode& get_code()      { return Code; }
99   inline const string&    get_transtext() { return TransText; }
100   inline const string&    get_menutext()  { return MenuText; }
101
102   // Return the parsed logic of the transmission  
103   TransPar Parse();
104
105 private:
106
107   friend istream& operator>> ( istream&, FGTransmission& );
108
109 };
110
111
112 inline istream&
113 operator >> ( istream& in, FGTransmission& a ) {
114         char ch;
115         int tmp;
116         
117         static bool first_time = true;
118         static double julian_date = 0;
119         static const double MJD0    = 2415020.0;
120         if ( first_time ) {
121                 julian_date = sgTimeCurrentMJD(0, 0) + MJD0;
122                 first_time = false;
123         }
124         // Ugly hack alert - eventually we'll use xml format for the transmissions file
125         in >> tmp;
126         if(tmp == 1) {
127                 a.StationType = APPROACH;
128         } else {
129                 a.StationType = INVALID;
130         }
131         in >> a.Code.c1;
132         in >> a.Code.c2;
133         in >> a.Code.c3;
134         a.TransText = "";
135         in >> ch;
136         if ( ch != '"' ) a.TransText += ch;
137         while(1) {
138                 //in >> noskipws
139                 in.unsetf(ios::skipws);
140                 in >> ch;
141                 if ( ch != '"' ) a.TransText += ch;
142                 if((ch == '"') || (ch == 0x0A)) {
143                         break;
144                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
145         }
146         in.setf(ios::skipws);
147         
148         a.MenuText = "";
149         in >> ch;
150         if ( ch != '"' ) a.MenuText += ch;
151         while(1) {
152                 //in >> noskipws
153                 in.unsetf(ios::skipws);
154                 in >> ch;
155                 if ( ch != '"' ) a.MenuText += ch;
156                 if((ch == '"') || (ch == 0x0A)) {
157                         break;
158                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
159         }
160         in.setf(ios::skipws);
161         
162         //cout << "Code = " << a.Code << "   Transmission text = " << a.TransText 
163         //     << "   Menu text = " << a.MenuText << endl;
164         
165         return in >> skipeol;
166 }
167
168
169 #endif // _FG_TRANSMISSION_HXX