Debian Codegraph @

src/ATC/ATISEncoder.hxx

raw symbols SCIP
1 /*
2 * SPDX-FileName: ATISEncoder.hxx
3 * SPDX-FileComment: Encode an ATIS into spoken words
4 * SPDX-FileCopyrightText: Copyright (C) 2014 Torsten Dreyer
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #pragma once
9
10 #include <map>
11 #include <string>
12
13 #include <Airports/airport.hxx>
14 #include <simgear/props/props.hxx>
15
16
17 class ATCSpeech
18 {
19 public:
20 static std::string getSpokenDigit(int i);
21 static std::string getSpokenNumber(std::string number);
22 static std::string getSpokenNumber(int number, bool leadingZero = false, int digits = 1);
23 static std::string getSpokenAltitude(int altitude);
24 };
25
26 class ATISInformationProvider
27 {
28 public:
29 virtual ~ATISInformationProvider() {}
30 virtual bool isValid() const = 0;
31 virtual std::string airportId() const = 0;
32
33 static long makeAtisTime(int day, int hour, int minute)
34 {
35 return 100 * 100l * day + 100l * hour + minute;
36 }
37 inline int getAtisTimeDay(long atisTime) { return atisTime / (100l * 100l); }
38 inline int getAtisTimeHour(long atisTime) { return (atisTime % (100l * 100l)) / 100l; }
39 inline int getAtisTimeMinute(long atisTime) { return atisTime % 100l; }
40 virtual long getTime() const = 0; // see makeAtisTime
41
42 virtual int getWindDeg() const = 0;
43 virtual int getWindMinDeg() const = 0;
44 virtual int getWindMaxDeg() const = 0;
45 virtual int getWindSpeedKt() const = 0;
46 virtual int getGustsKt() const = 0;
47 virtual int getQnh() const = 0;
48 virtual double getQnhInHg() const = 0;
49 virtual bool isCavok() const = 0;
50 virtual int getVisibilityMeters() const = 0;
51 virtual std::string getPhenomena() const = 0;
52
53 typedef std::map<int, std::string> CloudEntries;
54 virtual CloudEntries getClouds() = 0;
55 virtual int getTemperatureDeg() const = 0;
56 virtual int getDewpointDeg() const = 0;
57 virtual std::string getTrend() const = 0;
58 };
59
60 class ATISEncoder : public ATCSpeech
61 {
62 public:
63 ATISEncoder();
64 virtual ~ATISEncoder();
65 virtual std::string encodeATIS(ATISInformationProvider* atisInformationProvider);
66
67 protected:
68 virtual std::string getAtisId(SGPropertyNode_ptr);
69 virtual std::string getAirportName(SGPropertyNode_ptr);
70 virtual std::string getTime(SGPropertyNode_ptr);
71 virtual std::string getApproachType(SGPropertyNode_ptr);
72 virtual std::string getLandingRunway(SGPropertyNode_ptr);
73 virtual std::string getTakeoffRunway(SGPropertyNode_ptr);
74 virtual std::string getTransitionLevel(SGPropertyNode_ptr);
75 virtual std::string getWindDirection(SGPropertyNode_ptr);
76 virtual std::string getWindMinDirection(SGPropertyNode_ptr);
77 virtual std::string getWindMaxDirection(SGPropertyNode_ptr);
78 virtual std::string getWindspeedKnots(SGPropertyNode_ptr);
79 virtual std::string getGustsKnots(SGPropertyNode_ptr);
80 virtual std::string getCavok(SGPropertyNode_ptr);
81 virtual std::string getVisibilityMetric(SGPropertyNode_ptr);
82 virtual std::string getVisibilityMiles(SGPropertyNode_ptr);
83 virtual std::string getPhenomena(SGPropertyNode_ptr);
84 virtual std::string getClouds(SGPropertyNode_ptr);
85 virtual std::string getCloudsBrief(SGPropertyNode_ptr);
86 virtual std::string getTemperatureDeg(SGPropertyNode_ptr);
87 virtual std::string getDewpointDeg(SGPropertyNode_ptr);
88 virtual std::string getQnh(SGPropertyNode_ptr);
89 virtual std::string getInhgInteger(SGPropertyNode_ptr);
90 virtual std::string getInhgFraction(SGPropertyNode_ptr);
91 virtual std::string getInhg(SGPropertyNode_ptr);
92 virtual std::string getTrend(SGPropertyNode_ptr);
93
94 typedef std::string (ATISEncoder::*handler_t)(SGPropertyNode_ptr baseNode);
95 typedef std::map<std::string, handler_t> HandlerMap;
96 HandlerMap handlerMap;
97
98 SGPropertyNode_ptr atisSchemaNode;
99
100 std::string processTokens(SGPropertyNode_ptr baseNode);
101 std::string processToken(SGPropertyNode_ptr baseNode);
102
103 std::string processTextToken(SGPropertyNode_ptr baseNode);
104 std::string processTokenToken(SGPropertyNode_ptr baseNode);
105 std::string processIfToken(SGPropertyNode_ptr baseNode);
106
107 bool checkEmptyCondition(SGPropertyNode_ptr node, bool isEmpty);
108
109 // Wrappers that can be passed as function pointers to checkCondition
110 // @see simgear::strutils::starts_with
111 // @see simgear::strutils::ends_with
112 static bool contains(const std::string& s, const std::string& substring)
113 {
114 return s.find(substring) != std::string::npos;
115 };
116 static bool equals(const std::string& s1, const std::string& s2)
117 {
118 return s1 == s2;
119 };
120
121 bool checkCondition(SGPropertyNode_ptr node, bool notInverted,
122 bool (*fp)(const std::string&, const std::string&),
123 const std::string& name);
124
125 FGAirportRef airport;
126 ATISInformationProvider* _atis{nullptr};
127 };