]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGGlobalWeatherDatabase.h
Added first stab at a socket class.
[flightgear.git] / src / WeatherCM / FGGlobalWeatherDatabase.h
1 /*****************************************************************************
2
3  Header:       FGGlobalWeatherDatabase.h        
4  Author:       Christian Mayer
5  Date started: 28.05.99
6
7  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Database for the global weather
29 This database is only called by the local database and by the weather
30 simulator driving this database
31
32 HISTORY
33 ------------------------------------------------------------------------------
34 28.05.1999 Christian Mayer      Created
35 16.06.1999 Durk Talsma          Portability for Linux
36 20.06.1999 Christian Mayer      added lots of consts
37 30.06.1999 Christian Mayer      STL portability
38 11.10.1999 Christian Mayer      changed set<> to map<> on Bernie Bright's 
39                                 suggestion
40 19.10.1999 Christian Mayer      change to use PLIB's sg instead of Point[2/3]D
41                                 and lots of wee code cleaning
42 *****************************************************************************/
43
44 /****************************************************************************/
45 /* SENTRY                                                                   */
46 /****************************************************************************/
47 #ifndef FGGlobalWeatherDatabase_H
48 #define FGGlobalWeatherDatabase_H
49
50 /****************************************************************************/
51 /* INCLUDES                                                                 */
52 /****************************************************************************/
53 #ifdef HAVE_CONFIG_H
54 #  include <config.h>
55 #endif
56
57 #include <Include/compiler.h>
58
59 #include <vector>
60 #include STL_IOSTREAM
61
62 #include <sg.h>
63
64 #include "FGPhysicalProperties.h"
65 #include "FGPhysicalProperty.h"
66                 
67 /****************************************************************************/
68 /* DEFINES                                                                  */
69 /****************************************************************************/
70 FG_USING_STD(vector);
71 #ifndef FG_HAVE_NATIVE_SGI_COMPILERS
72 FG_USING_STD(iostream);
73 #endif
74 FG_USING_NAMESPACE(std);
75
76 enum FGGlobalWeatherDatabaseStatus {
77     FGGlobalWeatherDatabase_not_used,
78     FGGlobalWeatherDatabase_switched_off,
79     FGGlobalWeatherDatabase_only_static,
80     FGGlobalWeatherDatabase_working
81 };
82
83 class FGGlobalWeatherDatabase;
84 ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p );
85
86 /****************************************************************************/
87 /* CLASS DECLARATION                                                        */
88 /****************************************************************************/
89 class FGGlobalWeatherDatabase
90 {
91 private:
92 protected:
93     FGGlobalWeatherDatabaseStatus DatabaseStatus;
94     FGPhysicalProperties2DVector database;
95
96 public:
97     /************************************************************************/
98     /* Constructor and Destructor                                           */
99     /************************************************************************/
100     FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus s = FGGlobalWeatherDatabase_not_used);
101     ~FGGlobalWeatherDatabase();
102
103     /************************************************************************/
104     /* Get the physical properties on the specified point p                 */
105     /************************************************************************/
106     FGPhysicalProperties get(const sgVec2& p) const; 
107     FGPhysicalProperty   get(const sgVec3& p) const 
108     {
109         sgVec2 temp;
110         sgSetVec2( temp, p[0], p[1] );
111
112         return FGPhysicalProperty( get(temp), p[3] );
113     }
114
115     /************************************************************************/
116     /* update the database. Since the last call we had dt seconds           */
117     /************************************************************************/
118     void update(const WeatherPrecision dt);
119
120     /************************************************************************/
121     /* Add a physical property on the specified point p                     */
122     /************************************************************************/
123     void add(const sgVec2& p, const FGPhysicalProperties& x);
124     void add(const FGPhysicalProperties2D& x) 
125     {
126         database.push_back(x);
127     }
128
129     /************************************************************************/
130     /* Change the closest physical property to p. If p is further away than */
131     /* tolerance I'm returning false otherwise true                         */
132     /************************************************************************/
133     bool change(const FGPhysicalProperties2D& p, const WeatherPrecision tolerance = 0.0000001);
134
135     /************************************************************************/
136     /* Get all stored points in the circle around p with the radius r, but  */
137     /* at least min points.                                                 */
138     /************************************************************************/
139     FGPhysicalProperties2DVector getAll(const sgVec2& p, const WeatherPrecision r, const unsigned int min = 0);
140     FGPhysicalProperties2DVector getAll(const sgVec3& p, const WeatherPrecision r, const unsigned int min = 0)
141     {
142         sgVec2 temp;
143         sgSetVec2(temp, p[0], p[1]);
144
145         return getAll(temp, r, min);
146     }
147
148     /************************************************************************/
149     /* get/set the operating status of the database                         */
150     /************************************************************************/
151     FGGlobalWeatherDatabaseStatus getDatabaseStatus(void) const    { return DatabaseStatus; }
152     void setDatabaseStatus(const FGGlobalWeatherDatabaseStatus& s) { DatabaseStatus = s; }
153
154     /************************************************************************/
155     /* Dump the whole database                                              */
156     /************************************************************************/
157     friend ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p );
158
159 };
160
161 inline ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p )
162 {
163     //out << "Database status: " << DatabaseStatus << "\n";
164     out << "Database number of entries: " << p.database.size() << "\n";
165
166     for (FGPhysicalProperties2DVector::const_iterator it = p.database.begin(); it != p.database.end(); it++)
167         out << "Next entry: " << *it;
168
169     return out;
170 }
171
172 /****************************************************************************/
173 #endif /*FGGlobalWeatherDatabase_H*/