World Ocean Simulation System (WOSS) library
woss-manager-simple.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
22
33#ifndef WOSS_MANAGER_SIMPLE_DEFINITIONS_H
34#define WOSS_MANAGER_SIMPLE_DEFINITIONS_H
35
36
37#include <iostream>
38#include <memory>
39#include <definitions-handler.h>
40#include "woss-manager.h"
41
42
43namespace woss {
44
53 template< typename WMResDb = WossManagerResDb >
54 class WossManagerSimple : public WMResDb {
55
56 public:
57
62
63 virtual ~WossManagerSimple() override = default;
64
65 virtual WossManagerSimple& eraseActiveWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency ) override;
66
71 virtual bool reset() override;
72
78 virtual bool timeEvolve( const Time& time_value ) override;
79
84 static void setSpaceSampling( double radius ) { space_sampling = radius; }
85
90 static double getSpaceSampling() { return space_sampling; }
91
92 protected:
93
97 using WossCoordZMap = typename std::map< CoordZ, std::shared_ptr<Woss>, CoordComparator< WossManagerSimple, CoordZ > >;
98 using WCZIter = typename WossCoordZMap::iterator;
99 using WCZRIter = typename WossCoordZMap::reverse_iterator;
100
104 using WossContainer = typename std::map< CoordZ, WossCoordZMap, CoordComparator< WossManagerSimple, CoordZ > >;
105 using WCIter = typename WossContainer::iterator;
106 using WCRIter = typename WossContainer::reverse_iterator;
107
112 static double space_sampling;
113
118
127 virtual std::shared_ptr<Woss> getWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency ) override;
128
129 };
130
131
132 template< typename WMResDb >
134
135
136 template< typename WMResDb >
141
142
143 template< typename WMResDb >
145 if (WMResDb::debug)
146 std::cout << "WossManagerSimple::reset() map size = " << woss_map.size() << std::endl;
147
148 woss_map.clear();
149 return true;
150 }
151
152
153 template< typename WMResDb >
155 for (const auto& it1 : woss_map) {
156 for (const auto& it2 : it1.second) {
157 it2.second->timeEvolve(time_value);
158 }
159 }
160 return true;
161 }
162
163
164 template< typename WMResDb >
165 std::shared_ptr<Woss> WossManagerSimple< WMResDb >::getWoss( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency ) {
166 if (WMResDb::debug)
167 std::cout << "WossManagerSimple::getWoss() tx coords " << tx_coordz << "; rx coords "
168 << rx_coordz << "; start freq " << start_frequency << "; end freq "
169 << end_frequency << std::endl;
170
171 auto it1 = woss_map.find( tx_coordz );
172
173 if (it1 == woss_map.end() ) { // no tx CoordZ found
174 if (WMResDb::debug)
175 std::cout << "WossManagerSimple::getWoss() no tx CoordZ found" << std::endl;
176
177 auto curr_woss = this->woss_creator->createWoss( tx_coordz, rx_coordz, start_frequency, end_frequency );
178
179 woss_map[tx_coordz][rx_coordz] = std::move(curr_woss);
180 return( woss_map[tx_coordz][rx_coordz] );
181 }
182 else { // start CoordZ found
183 auto it2 = (it1->second).find( rx_coordz );
184
185 if ( it2 == it1->second.end() ) { // no rx CoordZ foundZ
186
187 if (WMResDb::debug)
188 std::cout << "WossManagerSimple::getWoss() no rx CoordZ found" << std::endl;
189
190 auto curr_woss = WMResDb::woss_creator->createWoss( tx_coordz, rx_coordz, start_frequency, end_frequency );
191
192 woss_map[tx_coordz][rx_coordz] = std::move(curr_woss);
193 return( woss_map[tx_coordz][rx_coordz] );
194 }
195 else
196 return( it2->second );
197 }
198 }
199
200
201 template< typename WMResDb >
202 WossManagerSimple< WMResDb >& WossManagerSimple< WMResDb >::eraseActiveWoss( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency ) {
203 if (WMResDb::debug)
204 std::cout << "WossManagerSimple::eraseActiveWoss() tx coords " << tx_coordz << "; rx coords "
205 << rx_coordz << "; start freq " << start_frequency << "; end freq "
206 << end_frequency << std::endl;
207
208 auto it1 = woss_map.find( tx_coordz );
209
210 if (it1 == woss_map.end() )
211 return *this;
212 else { // start CoordZ found
213 auto it2 = (it1->second).find( rx_coordz );
214
215 if ( it2 == it1->second.end() )
216 return *this;
217 else {
218 it1->second.erase(it2);
219 if ( it1->second.empty() )
220 woss_map.erase(it1);
221 }
222 }
223 return *this;
224 }
225
226}
227
228#endif /* WOSS_MANAGER_SIMPLE_DEFINITIONS_H */
Function object for partial ordering of coordinates.
Definition coordinates-definitions.h:783
3D-Coordinates (lat, long, depth) class definitions and functions library
Definition coordinates-definitions.h:384
a class for time date manipulation
Definition time-definitions.h:83
simple template extension of WossManagerResDb or WossManagerResDbMT
Definition woss-manager-simple.h:54
typename WossCoordZMap::iterator WCZIter
Definition woss-manager-simple.h:98
static double space_sampling
Definition woss-manager-simple.h:112
WossContainer woss_map
Definition woss-manager-simple.h:117
static void setSpaceSampling(double radius)
Definition woss-manager-simple.h:84
virtual std::shared_ptr< Woss > getWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency) override
Definition woss-manager-simple.h:165
typename WossCoordZMap::reverse_iterator WCZRIter
Definition woss-manager-simple.h:99
WossManagerSimple()
Definition woss-manager-simple.h:137
typename std::map< CoordZ, WossCoordZMap, CoordComparator< WossManagerSimple, CoordZ > > WossContainer
Definition woss-manager-simple.h:104
virtual bool timeEvolve(const Time &time_value) override
Definition woss-manager-simple.h:154
typename std::map< CoordZ, std::shared_ptr< Woss >, CoordComparator< WossManagerSimple, CoordZ > > WossCoordZMap
Definition woss-manager-simple.h:97
virtual bool reset() override
Definition woss-manager-simple.h:144
typename WossContainer::reverse_iterator WCRIter
Definition woss-manager-simple.h:106
typename WossContainer::iterator WCIter
Definition woss-manager-simple.h:105
virtual WossManagerSimple & eraseActiveWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency) override
Definition woss-manager-simple.h:202
virtual ~WossManagerSimple() override=default
static double getSpaceSampling()
Definition woss-manager-simple.h:90
Provides the interface for woss::DefHandler class.
Definition ac-toolbox-arr-asc-reader.h:44
Provides the interface for woss::WossManager, woss::WossManagerResDb and woss::WossManagerResDbMT cla...