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 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - federico@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/*
23 * This software has been developed by Federico Guerra and SIGNET lab,
24 * University of Padova, in collaboration with the NATO Centre for
25 * Maritime Research and Experimentation (http://www.cmre.nato.int ;
26 * E-mail: pao@cmre.nato.int), whose support is gratefully acknowledged.
27 */
28
29
40#ifndef WOSS_MANAGER_SIMPLE_DEFINITIONS_H
41#define WOSS_MANAGER_SIMPLE_DEFINITIONS_H
42
43
45#include <definitions-handler.h>
46#include "woss-manager.h"
47
48
49namespace woss {
50
51
60 template< typename WMResDb = WossManagerResDb >
61 class WossManagerSimple : public WMResDb {
62
63
64 public:
65
66
71
72 virtual ~WossManagerSimple() { reset(); }
73
74
75 virtual WossManagerSimple& eraseActiveWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency );
76
81 virtual bool reset();
82
83
89 virtual bool timeEvolve( const Time& time_value );
90
91
96 static void setSpaceSampling( double radius ) { space_sampling = radius; }
97
102 static double getSpaceSampling() { return space_sampling; }
103
104
105 protected:
106
107
111 typedef typename ::std::map< CoordZ, Woss*, CoordComparator< WossManagerSimple, CoordZ > > WossCoordZMap;
112 typedef typename WossCoordZMap::iterator WCZIter;
113 typedef typename WossCoordZMap::reverse_iterator WCZRIter;
114
115
119 typedef typename ::std::map< CoordZ, WossCoordZMap, CoordComparator< WossManagerSimple, CoordZ > > WossContainer;
120 typedef typename WossContainer::iterator WCIter;
121 typedef typename WossContainer::reverse_iterator WCRIter;
122
123
128 static double space_sampling;
129
134
135
144 virtual Woss* const getWoss( const CoordZ& tx, const CoordZ& rx, double start_frequency, double end_frequency );
145
146
147 };
148
149
150 template< typename WMResDb >
152
153
154 template< typename WMResDb >
156 : woss_map()
157 {
158
159
160 }
161
162
163 template< typename WMResDb >
165 if (WMResDb::debug)
166 ::std::cout << "WossManagerSimple::reset() map size = " << woss_map.size() << ::std::endl;
167
168 for (WCIter it1 = woss_map.begin(); it1 != woss_map.end(); it1++) {
169 for (WCZIter it2 = (it1->second).begin(); it2 != (it1->second).end(); it2++) {
170 delete it2->second;
171 it2->second = NULL;
172 }
173 }
174 woss_map.clear();
175 return true;
176 }
177
178
179 template< typename WMResDb >
181 for (WCIter it1 = woss_map.begin(); it1 != woss_map.end(); it1++) {
182 for (WCZIter it2 = (it1->second).begin(); it2 != (it1->second).end(); it2++) {
183 it2->second->timeEvolve(time_value);
184 }
185 }
186 return true;
187 }
188
189
190 template< typename WMResDb >
191 Woss* const WossManagerSimple< WMResDb >::getWoss( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency ) {
192 if (WMResDb::debug) ::std::cout << "WossManagerSimple::getWoss() tx coords " << tx_coordz << "; rx coords "
193 << rx_coordz << "; start freq " << start_frequency << "; end freq "
194 << end_frequency << ::std::endl;
195
196 WCIter it1 = woss_map.find( tx_coordz );
197
198 if (it1 == woss_map.end() ) { // no tx CoordZ found
199
200 if (WMResDb::debug) ::std::cout << "WossManagerSimple::getWoss() no tx CoordZ found" << ::std::endl;
201
202 Woss* const curr_woss = this->woss_creator->createWoss( tx_coordz, rx_coordz, start_frequency, end_frequency );
203
204 woss_map[tx_coordz][rx_coordz] = curr_woss;
205 return( curr_woss );
206 }
207 else { // start CoordZ found
208 WCZIter it2 = (it1->second).find( rx_coordz );
209
210 if ( it2 == it1->second.end() ) { // no rx CoordZ foundZ
211
212 if (WMResDb::debug) ::std::cout << "WossManagerSimple::getWoss() no rx CoordZ found" << ::std::endl;
213
214 Woss* const curr_woss = WMResDb::woss_creator->createWoss( tx_coordz, rx_coordz, start_frequency, end_frequency );
215
216 woss_map[tx_coordz][rx_coordz] = curr_woss;
217 return( curr_woss );
218 }
219 else return( it2->second );
220 }
221 }
222
223
224 template< typename WMResDb >
225 WossManagerSimple< WMResDb >& WossManagerSimple< WMResDb >::eraseActiveWoss( const CoordZ& tx_coordz, const CoordZ& rx_coordz, double start_frequency, double end_frequency ) {
226 if (WMResDb::debug) ::std::cout << "WossManagerSimple::eraseActiveWoss() tx coords " << tx_coordz << "; rx coords "
227 << rx_coordz << "; start freq " << start_frequency << "; end freq "
228 << end_frequency << ::std::endl;
229
230 WCIter it1 = woss_map.find( tx_coordz );
231
232 if (it1 == woss_map.end() ) return *this;
233 else { // start CoordZ found
234 WCZIter it2 = (it1->second).find( rx_coordz );
235
236 if ( it2 == it1->second.end() ) return *this;
237 else {
238 delete it2->second;
239 it1->second.erase(it2);
240 if ( it1->second.empty() ) woss_map.erase(it1);
241 }
242 }
243 return *this;
244 }
245
246
247}
248
249
250
251#endif /* WOSS_MANAGER_SIMPLE_DEFINITIONS_H */
252
253
3D-Coordinates (lat, long, depth) class definitions and functions library
Definition coordinates-definitions.h:403
a class for time date manipulation
Definition time-definitions.h:95
simple template extension of WossManagerResDb or WossManagerResDbMT
Definition woss-manager-simple.h:61
static double space_sampling
Definition woss-manager-simple.h:128
WossContainer woss_map
Definition woss-manager-simple.h:133
virtual WossManagerSimple & eraseActiveWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency)
Definition woss-manager-simple.h:225
static void setSpaceSampling(double radius)
Definition woss-manager-simple.h:96
virtual bool reset()
Definition woss-manager-simple.h:164
::std::map< CoordZ, Woss *, CoordComparator< WossManagerSimple, CoordZ > > WossCoordZMap
Definition woss-manager-simple.h:111
::std::map< CoordZ, WossCoordZMap, CoordComparator< WossManagerSimple, CoordZ > > WossContainer
Definition woss-manager-simple.h:119
WossManagerSimple()
Definition woss-manager-simple.h:155
virtual Woss *const getWoss(const CoordZ &tx, const CoordZ &rx, double start_frequency, double end_frequency)
Definition woss-manager-simple.h:191
virtual bool timeEvolve(const Time &time_value)
Definition woss-manager-simple.h:180
static double getSpaceSampling()
Definition woss-manager-simple.h:102
Abstract class that provides the interface for initializing and running a channel simulator.
Definition woss.h:89
Provides the interface for woss::DefHandler class.
Definitions and library for woss::TimeArr class.
Provides the interface for woss::WossManager, woss::WossManagerResDb and woss::WossManagerResDbMT cla...