]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/transmission.hxx
Clean up header file use of iostream and "using" declarations
[flightgear.git] / src / ATCDCL / 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 struct TransCode {
52   int c1;
53   int c2;
54   int c3;
55 };
56
57 // TransPar - a representation of the logic of a parsed speech transmission
58 struct TransPar {
59   std::string  station;
60   std::string  callsign;
61   std::string  airport;
62   std::string  intention;      // landing, crossing
63   std::string  intid;          // (airport) ID for intention
64   bool    request;        // is the transmission a request or an answer?
65   int     tdir;           // turning direction: 1=left, 2=right
66   double  heading;
67   int     VDir;           // vertical direction: 1=descent, 2=maintain, 3=climb
68   double  alt;
69   double  miles;
70   std::string  runway;
71   double  freq;
72   double  time;
73 };
74
75 // FGTransmission - a class to encapsulate a speech transmission
76 class FGTransmission {
77
78   //int       StationType;    // Type of ATC station: 1 Approach
79   atc_type  StationType;
80   TransCode Code;           // DCL - no idea what this is.
81   std::string    TransText;      // The text of the spoken transmission
82   std::string    MenuText;       // An abbreviated version of the text for the menu entry
83
84 public:
85
86   FGTransmission(void);
87   ~FGTransmission(void);
88
89   void Init();
90
91   inline atc_type  get_station()   const { return StationType; }
92   inline const TransCode& get_code()      { return Code; }
93   inline const std::string&    get_transtext() { return TransText; }
94   inline const std::string&    get_menutext()  { return MenuText; }
95
96   // Return the parsed logic of the transmission  
97   TransPar Parse();
98
99 private:
100
101   friend std::istream& operator>> ( std::istream&, FGTransmission& );
102
103 };
104
105
106 inline std::istream&
107 operator >> ( std::istream& in, FGTransmission& a ) {
108         char ch;
109         int tmp;
110         
111         static bool first_time = true;
112         static double julian_date = 0;
113         static const double MJD0    = 2415020.0;
114         if ( first_time ) {
115                 julian_date = sgTimeCurrentMJD(0, 0) + MJD0;
116                 first_time = false;
117         }
118         // Ugly hack alert - eventually we'll use xml format for the transmissions file
119         in >> tmp;
120         if(tmp == 1) {
121                 a.StationType = APPROACH;
122         } else {
123                 a.StationType = INVALID;
124         }
125         in >> a.Code.c1;
126         in >> a.Code.c2;
127         in >> a.Code.c3;
128         a.TransText = "";
129         in >> ch;
130         if ( ch != '"' ) a.TransText += ch;
131         while(1) {
132                 //in >> noskipws
133                 in.unsetf(ios::skipws);
134                 in >> ch;
135                 if ( ch != '"' ) a.TransText += ch;
136                 if((ch == '"') || (ch == 0x0A)) {
137                         break;
138                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
139         }
140         in.setf(ios::skipws);
141         
142         a.MenuText = "";
143         in >> ch;
144         if ( ch != '"' ) a.MenuText += ch;
145         while(1) {
146                 //in >> noskipws
147                 in.unsetf(ios::skipws);
148                 in >> ch;
149                 if ( ch != '"' ) a.MenuText += ch;
150                 if((ch == '"') || (ch == 0x0A)) {
151                         break;
152                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
153         }
154         in.setf(ios::skipws);
155         
156         //cout << "Code = " << a.Code << "   Transmission text = " << a.TransText 
157         //     << "   Menu text = " << a.MenuText << endl;
158         
159         return in >> skipeol;
160 }
161
162
163 #endif // _FG_TRANSMISSION_HXX