World Ocean Simulation System (WOSS) library
woss-db.h
Go to the documentation of this file.
1/* WOSS - World Ocean Simulation System -
2 *
3 * Copyright (C) 2009 2025 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - WOSS@guerra-tlc.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
32#ifndef WOSS_DB_H
33#define WOSS_DB_H
34
35#include <fstream>
36#include <memory>
37#include <utility>
38#include <string>
39#if defined(WOSS_NETCDF4_SUPPORT)
40#include <ncFile.h>
41#elif defined(WOSS_NETCDF_SUPPORT)
42#include <netcdfcpp.h>
43#endif
44#include <definitions.h>
48#include <ssp-definitions.h>
50
51namespace woss {
52
53 class Time;
54
55
59 static constexpr inline const char* DB_NAME_NOT_SET = "DB_NAME_NOT_SET";
60
66 using PathName = std::pair< std::string, std::string >; // path , filename
67
68
79 class WossDb {
80
81
82 public:
83
84
89 WossDb( const std::string& name );
90
91 virtual ~WossDb() = default;
92
93
98 void setDbName( const std::string& pathname ) { db_name = pathname; }
99
104 std::string getDbName() const { return db_name; }
105
106
111 void setDebug( double flag = true ) { debug = flag; }
112
117 bool isUsingDebug() const { return debug; }
118
119
124 virtual bool isValid() const { return( db_name.length() > 0 ); }
125
126
131 virtual bool openConnection() = 0;
132
133
138 virtual bool finalizeConnection() = 0;
139
140
145 virtual bool closeConnection() = 0;
146
147 protected:
148
152 std::string db_name;
153
157 bool debug;
158
164 PathName getPathName( const std::string& complete_path ) const;
165
166 };
167
169#ifdef WOSS_NETCDF_SUPPORT
178 class WossNetcdfDb : public WossDb {
179
180 public:
181
186 WossNetcdfDb( const std::string& name );
187
188 virtual ~WossNetcdfDb() override;
189
194 virtual bool openConnection() override;
195
200 virtual bool closeConnection() override;
201
202 protected:
203
207#if defined(WOSS_NETCDF4_SUPPORT)
208 std::unique_ptr< netCDF::NcFile > netcdf_db = nullptr;
209#else
210 std::unique_ptr< NcFile> netcdf_db = nullptr;
211#endif // defined(WOSS_NETCDF4_SUPPORT)
212
213 };
214#endif // WOSS_NETCDF_SUPPORT
215
216
224 class WossTextualDb : public WossDb {
225
226 public:
227
232 WossTextualDb( const std::string& name );
233
234 virtual ~WossTextualDb() override;
235
240 virtual bool openConnection() override;
241
246 virtual bool closeConnection() override;
247
248 protected:
249
253 std::fstream textual_db;
254
255 };
256
258
266
267 public:
268
269 WossBathymetryDb() = default;
270
271 virtual ~WossBathymetryDb() = default;
272
279 virtual bool insertValue( const Coord& coordinates, const Bathymetry& bathymetry_value ) = 0;
280
286 virtual Bathymetry getValue( const Coord& coords ) const = 0;
287 };
288
289
297
298 public:
299
300 WossSedimentDb() = default;
301
302 virtual ~WossSedimentDb() = default;
303
310 virtual bool insertValue( const Coord& coordinates, const Sediment& sediment_value ) = 0;
311
318 virtual std::unique_ptr<Sediment> getValue( const CoordZ& coords ) const = 0;
319
327 virtual std::unique_ptr<Sediment> getValue( const CoordZVector& coordz_vector ) const = 0;
328
329 };
330
331
338 class WossSSPDb {
339
340 public:
341
342 WossSSPDb() = default;
343
344 virtual ~WossSSPDb() = default;
345
353 virtual bool insertValue( const Coord& coordinates, const Time& time_value, const SSP& ssp_value ) = 0;
354
363 virtual std::unique_ptr<SSP> getValue( const Coord& coords, const Time& time, long double ssp_depth_precision ) const = 0;
364
365 };
366
367
375
376 public:
377
378 WossResTimeArrDb() = default;
379
380 virtual ~WossResTimeArrDb() = default;
381
391 virtual std::unique_ptr<TimeArr> getValue( const CoordZ& coord_tx, const CoordZ& coord_rx, const double frequency, const Time& time_value ) const = 0;
392
401 virtual bool insertValue( const CoordZ& coord_tx, const CoordZ& coord_rx, const double frequency, const Time& time_value, const TimeArr& channel ) = 0;
402
403 };
404
405
413
414 public:
415
416 WossResPressDb() = default;
417
418 virtual ~WossResPressDb() = default;
419
428 virtual std::unique_ptr<Pressure> getValue( const CoordZ& coord_tx, const CoordZ& coord_rx, const double frequency, const Time& time_value ) const = 0;
429
438 virtual bool insertValue( const CoordZ& coord_tx, const CoordZ& coord_rx, const double frequency, const Time& time_value, const Pressure& pressure ) = 0;
439
440 };
441
442}
443
444#endif /* WOSS_DB_H */
3D-Coordinates (lat, long, depth) class definitions and functions library
Definition coordinates-definitions.h:384
Coordinates (lat, long) class definitions and functions library.
Definition coordinates-definitions.h:98
Complex attenuated pressure class.
Definition pressure-definitions.h:52
SSP class offers multiple creation and manipulation capabilities for sound speed profile.
Definition ssp-definitions.h:247
Surficial sediment geoacoustic parameters definitions.
Definition sediment-definitions.h:54
Channel power delay profile class.
Definition time-arrival-definitions.h:70
a class for time date manipulation
Definition time-definitions.h:83
Data behaviour class for bathymetry database.
Definition woss-db.h:265
virtual bool insertValue(const Coord &coordinates, const Bathymetry &bathymetry_value)=0
virtual Bathymetry getValue(const Coord &coords) const =0
virtual ~WossBathymetryDb()=default
Abstract class that provides the interface of databases.
Definition woss-db.h:79
void setDbName(const std::string &pathname)
Definition woss-db.h:98
std::string db_name
Definition woss-db.h:152
std::string getDbName() const
Definition woss-db.h:104
bool debug
Definition woss-db.h:157
virtual ~WossDb()=default
bool isUsingDebug() const
Definition woss-db.h:117
virtual bool finalizeConnection()=0
virtual bool closeConnection()=0
virtual bool openConnection()=0
virtual bool isValid() const
Definition woss-db.h:124
void setDebug(double flag=true)
Definition woss-db.h:111
PathName getPathName(const std::string &complete_path) const
Definition woss-db.cpp:47
NetCDF implementation of WossDb.
Definition woss-db.h:178
virtual ~WossNetcdfDb() override
Definition woss-db.cpp:83
virtual bool closeConnection() override
Definition woss-db.cpp:105
virtual bool openConnection() override
Definition woss-db.cpp:89
std::unique_ptr< netCDF::NcFile > netcdf_db
Definition woss-db.h:208
Data behaviour class for storing calculated Pressure.
Definition woss-db.h:412
virtual ~WossResPressDb()=default
virtual std::unique_ptr< Pressure > getValue(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value) const =0
WossResPressDb()=default
virtual bool insertValue(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value, const Pressure &pressure)=0
Data behaviour class for storing calculated TimeArr.
Definition woss-db.h:374
virtual std::unique_ptr< TimeArr > getValue(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value) const =0
virtual bool insertValue(const CoordZ &coord_tx, const CoordZ &coord_rx, const double frequency, const Time &time_value, const TimeArr &channel)=0
virtual ~WossResTimeArrDb()=default
Data behaviour class for SSP database.
Definition woss-db.h:338
WossSSPDb()=default
virtual ~WossSSPDb()=default
virtual bool insertValue(const Coord &coordinates, const Time &time_value, const SSP &ssp_value)=0
virtual std::unique_ptr< SSP > getValue(const Coord &coords, const Time &time, long double ssp_depth_precision) const =0
Data behaviour class for Sediment database.
Definition woss-db.h:296
virtual std::unique_ptr< Sediment > getValue(const CoordZ &coords) const =0
virtual std::unique_ptr< Sediment > getValue(const CoordZVector &coordz_vector) const =0
virtual bool insertValue(const Coord &coordinates, const Sediment &sediment_value)=0
WossSedimentDb()=default
virtual ~WossSedimentDb()=default
Textual implementation of WossDb.
Definition woss-db.h:224
virtual ~WossTextualDb() override
Definition woss-db.cpp:120
virtual bool openConnection() override
Definition woss-db.cpp:126
std::fstream textual_db
Definition woss-db.h:253
virtual bool closeConnection() override
Definition woss-db.cpp:131
Provides the interface for the woss::Coord and woss::CoordZ classes.
Generic functions and variables
Definition ac-toolbox-arr-asc-reader.h:44
std::vector< CoordZ > CoordZVector
Definition coordinates-definitions.h:58
double Bathymetry
Definition definitions.h:44
std::pair< std::string, std::string > PathName
Definition woss-db.h:66
Definitions and library for woss::Pressure class.
Definitions and library for woss::Sediment class.
Definitions and library for Sound Speed Profiles.
Definitions and library for woss::TimeArr class.