World Ocean Simulation System (WOSS) library
woss-db-custom-data-container.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_DB_CUSTOM_DATA_CONTAINER_H
34#define WOSS_DB_CUSTOM_DATA_CONTAINER_H
35
36
37#include <map>
38#include <iostream>
39#include <time-definitions.h>
40#include <complex>
41#include <optional>
42#include <memory>
43
44namespace woss {
45
53 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp = std::less<T>, class MidComp = std::less<double>, class InComp = std::less<double> >
55
56 protected:
57
61 using InnerData = typename std::map< double, Data, InComp >;
62 using CDCInnerIt = typename InnerData::iterator;
63 using CDCInnerRIt = typename InnerData::reverse_iterator;
64 using CDCInnerCIt = typename InnerData::const_iterator;
65 using CDCInnerCRIt = typename InnerData::const_reverse_iterator;
66
70 using MediumData = typename std::map< double, InnerData, MidComp >;
71 using CDCMediumIt = typename MediumData::iterator;
72 using CDCMediumCIt = typename MediumData::const_iterator;
73 using CDCMediumRIt = typename MediumData::reverse_iterator;
74 using CDCMediumCRIt = typename MediumData::const_reverse_iterator;
75
79 using CustomContainer = typename std::map< T, MediumData, OutComp >;
80 using CDCIt = typename CustomContainer::iterator;
81 using CDCRIt = typename CustomContainer::reverse_iterator;
82 using CDCCIt = typename CustomContainer::const_iterator;
83 using CDCCRIt = typename CustomContainer::const_reverse_iterator;
84
85 public:
86
87 #if __cplusplus >= 201103L // C++11 or later
88 static constexpr double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
89
90 static constexpr double DB_CDATA_ALL_INNER_KEYS = -10.0;
91 #else
92 static const double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
93
94 static const double DB_CDATA_ALL_INNER_KEYS = -10.0;
95 #endif // __cplusplus == 201103L
96
98
99
104
109
110
116 MediumData& operator[] ( const T& key ) { return data_map[key]; }
117
118
123 bool empty() const { return data_map.empty(); }
124
125
130 int size() const { return data_map.size(); }
131
132
143 const std::optional< Data > get( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS ) const;
144
151 const std::optional< Data > get( const T& tx, const T& rx ) const;
152
164 bool insert( const Data& data, const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS );
165
177 void replace( const Data& data, const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS );
178
179
191
192
196 void clear();
197
198
203 void setDebug( bool flag ) { debug = flag; }
204
205
210 bool usingDebug() { return debug; }
211
212
213 protected:
214
215
219 bool debug = false;
220
225
236 std::optional< Data > find( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS ) const;
237
238 };
239
240
241 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
243
244
245 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
246 const std::optional< Data > CustomDataContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::get( const T& t, double b, double r ) const {
247 if ( data_map.empty() )
248 return {};
249
250 if ( debug )
251 std::cout << "CustomDataContainer::get() t = " << t << "; b = " << b << "; r = " << r << std::endl;
252
253 auto val = find();
254 if ( val )
255 return val;
256
257 CDCCIt it = data_map.find( t );
258 if ( it == data_map.end() )
259 return {};
260
261 CDCMediumCIt it2 = it->second.lower_bound( b );
262 CDCMediumCRIt rit2 = it->second.rbegin();
263
264 CDCInnerCIt it3;
265 CDCInnerCRIt rit3;
266
267 if ( it2 == it->second.end() ) {
268 if( rit2 == it->second.rend() )
269 return {};
270 it3 = rit2->second.lower_bound( r );
271 rit3 = rit2->second.rbegin();
272 if ( it3 != rit2->second.end() )
273 return it3->second;
274 if ( rit3 != rit2->second.rend() )
275 return rit3->second;
276 return {};
277 }
278 else {
279 it3 = it2->second.lower_bound( r );
280 rit3 = it2->second.rbegin();
281 if ( it3 != it2->second.end() )
282 return it3->second;
283 if ( rit3 != it2->second.rend() )
284 return rit3->second;
285 return {};
286 }
287 if ( it3 == it2->second.end() )
288 return {};
289 return (it3->second);
290 }
291
292
293 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
294 const std::optional< Data > CustomDataContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::get( const T& tx, const T& rx ) const {
295 MidFunctor mid_funct;
296 InFunctor in_funct;
297
298 double curr_b;
299 double curr_r;
300 double delta_b;
301 double curr_dist;
302 double min_dist = INFINITY;
303 std::optional< Data > ret_val = {};
304
305 if ( data_map.empty() == true ) {
306 if ( debug ) std::cout << "CustomDataContainer::get() data_map is empty " << std::endl;
307
308 return {};
309 }
310
311 for ( auto it = data_map.cbegin(); it != data_map.cend(); it++ ) {
312 if ( debug )
313 std::cout << "CustomDataContainer::get() start T = " << it->first << "; end T = " << rx << std::endl;
314
315 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
316 if ( debug )
317 std::cout << "CustomDataContainer::get() overriding start T = " << tx << "; end T = " << rx << std::endl;
318
319 curr_b = mid_funct(tx,rx);
320 curr_r = in_funct(tx,rx);
321 }
322 else {
323 curr_b = mid_funct(it->first,rx);
324 curr_r = in_funct(it->first,rx);
325 }
326
327 if ( debug )
328 std::cout << "CustomDataContainer::get() curr bearing = " << curr_b * 180.0 / M_PI
329 << "; curr range = " << curr_r << std::endl;
330
331 auto itb = it->second.cbegin();
332 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS )
333 delta_b = 0;
334 else {
335 itb = it->second.lower_bound( curr_b );
336 if ( itb == it->second.cend() )
337 itb = (++(it->second.rbegin())).base();
338
339 delta_b = curr_b - itb->first;
340 if (delta_b < 0.0)
341 delta_b = -delta_b;
342 if (delta_b > M_PI)
343 delta_b = 2.0*M_PI - delta_b ;
344 }
345
346 double ort_dist = curr_r * sin(delta_b);
347 double ort_projection = std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
348
349 if ( debug )
350 std::cout << "CustomDataContainer::get() nearest bearing = " << itb->first * 180.0 / M_PI
351 << "; diff bearing = " << delta_b * 180.0 / M_PI << "; orthog distance = " << ort_dist
352 << "; orthog range projection = " << ort_projection << std::endl;
353
354 auto itr = itb->second.cbegin();
355 if ( itr->first == DB_CDATA_ALL_INNER_KEYS )
356 curr_dist = ort_dist;
357 else {
358 itr = itb->second.lower_bound( ort_projection );
359 if ( itr == itb->second.cbegin() || itr == itb->second.cend() || itr->first == ort_projection ) {
360 if ( itr == itb->second.cend() )
361 itr = (++(itb->second.rbegin())).base();
362 double adj_distance = std::abs( ort_projection - itr->first );
363 curr_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
364 }
365 else {
366 double adj_distance = std::abs( ort_projection - itr->first );
367 double first_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
368
369 if(debug)
370 std::cout << "CustomDataContainer::get() first try, range = " << itr->first
371 << "; dist = " << first_dist << std::endl;
372
373 itr--;
374 adj_distance = std::abs( ort_projection - itr->first );
375 double before_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
376
377 if (debug)
378 std::cout << "CustomDataContainer::get() second try, range = " << itr->first
379 << "; dist = " << before_dist << std::endl;
380
381 curr_dist = std::min( first_dist, before_dist );
382 if ( curr_dist == first_dist )
383 itr++;
384 }
385 }
386 if ( debug )
387 std::cout << "CustomDataContainer::get() nearest range = " << itr->first << "; distance = " << curr_dist
388 << "; min distance = " << min_dist << std::endl;
389
390 if ( curr_dist < min_dist ) {
391 min_dist = curr_dist;
392 ret_val = itr->second;
393 if ( curr_dist == 0 )
394 break;
395 }
396
397 }
398
399 if ( debug && ret_val )
400 std::cout << "CustomDataContainer::get() ret value " << *ret_val << std::endl;
401
402 return ret_val;
403 }
404
405
406 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
407 std::optional< Data > CustomDataContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::find( const T& t, double b, double r ) const {
408
409 if (this->debug)
410 std::cout << "CustomDataContainer::find() << t = " << t << "; b = " << b << "; r = " << r << std::endl;
411
412 CDCCIt it = data_map.find( t );
413 if ( it == data_map.end() ) {
414
415 if ( debug )
416 std::cout << "CustomDataContainer::find() t not found" << std::endl;
417
418 return {};
419 }
420
421 if ( debug )
422 std::cout << "CustomDataContainer::find() t found" << std::endl;
423
424 CDCMediumCIt it2 = it->second.find( b );
425 if ( it2 == it->second.end() ) {
426 if ( debug )
427 std::cout << "CustomDataContainer::find() b not found" << std::endl;
428
429 return {};
430 }
431
432 if ( debug )
433 std::cout << "CustomDataContainer::find() b found" << std::endl;
434
435 CDCInnerCIt it3 = it2->second.find( r );
436 if ( it3 == it2->second.end() ) {
437
438 if ( debug )
439 std::cout << "CustomDataContainer::find() r not found" << std::endl;
440
441 return {};
442 }
443 if ( debug )
444 std::cout << "CustomDataContainer::find() r found, data = " << it3->second << std::endl;
445 return it3->second;
446 }
447
448
449 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
451 auto res = find( t, b, r );
452 if ( res )
453 return false;
454 data_map[t][b][r] = d;
455 return true;
456 }
457
458
459 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
461 data_map[t][b].erase(r);
462 data_map[t][b][r] = d;
463 }
464
465
466 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
468 data_map[t][b].erase(r);
469 if ( data_map[t][b].empty() )
470 data_map[t].erase(b);
471 if ( data_map[t].empty() )
472 data_map.erase(t);
473 }
474
475
476 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
480
481
489 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp = std::less<T>, class MidComp = std::less<double>, class InComp = std::less<double> >
491
492 protected:
493
497 using TimeData = typename std::map< time_t, Data >;
498 using CDTCTimeIt = typename TimeData::iterator;
499 using CDTCTimeRIt = typename TimeData::reverse_iterator;
500 using CDTCTimeCIt = typename TimeData::const_iterator;
501 using CDTCTimeCRIt = typename TimeData::const_reverse_iterator;
502
506 using InnerData = typename std::map< double, TimeData, InComp >;
507 using CDCInnerIt = typename InnerData::iterator;
508 using CDCInnerRIt = typename InnerData::reverse_iterator;
509 using CDCInnerCIt = typename InnerData::const_iterator;
510 using CDCInnerCRIt = typename InnerData::const_reverse_iterator;
511
515 using MediumData = typename std::map< double, InnerData, MidComp >;
516 using CDCMediumIt = typename MediumData::iterator;
517 using CDCMediumCIt = typename MediumData::const_iterator;
518 using CDCMediumRIt = typename MediumData::reverse_iterator;
519 using CDCMediumCRIt = typename MediumData::const_reverse_iterator;
520
524 using CustomContainer = typename std::map< T, MediumData, OutComp >;
525 using CDCIt = typename CustomContainer::iterator;
526 using CDCRIt = typename CustomContainer::reverse_iterator;
527 using CDCCIt = typename CustomContainer::const_iterator;
528 using CDCCRIt = typename CustomContainer::const_reverse_iterator;
529
530 public:
531
532 static constexpr inline double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
533
534 static constexpr inline double DB_CDATA_ALL_INNER_KEYS = -10.0;
535
536 static const T DB_CDATA_ALL_OUTER_KEYS;
537
539
544
549
555 MediumData& operator[] ( const T& key ) { return data_map[key]; }
556
557
562 bool empty() const { return data_map.empty(); }
563
564
569 int size() const { return data_map.size(); }
570
571
584 std::optional<Data> get( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
585
594 std::optional<Data> get( const T& tx, const T& rx, const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
595
609 bool insert( const Data& data, const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS );
610
624 void replace( const Data& data, const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS );
625
638 void erase( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS);
639
640
644 void clear();
645
646
651 void setDebug( bool flag ) { debug = flag; }
652
653
658 bool usingDebug() const { return debug; }
659
660
661 protected:
662
663
667 bool debug;
668
673
686 std::optional<Data> find( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
687
700 std::optional<Data> calculateData( const TimeData& time_data , const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
701
702 };
703
704 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
706
707
708 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
710
711
712 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
713 std::optional<Data> CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::get( const T& t, double b, double r, const Time& time_key ) const {
714 if ( data_map.empty() )
715 return { };
716
717 if ( debug )
718 std::cout << "CustomDataTimeContainer::get() t = " << t << "; b = " << b << "; r = " << r
719 << "; time_key = " << time_key << std::endl;
720
721 auto ret_val = find();
722 if ( ret_val )
723 return ret_val;
724
725 CDCCIt it = data_map.find( t );
726 if ( it == data_map.end() )
727 return { };
728
729 CDCMediumCIt it2 = it->second.lower_bound( b );
730 CDCMediumCRIt rit2 = it->second.rbegin();
731
732 CDCInnerCIt it3;
733 CDCInnerCRIt rit3;
734
735 if ( it2 == it->second.end() ) {
736 if ( rit2 == it->second.rend() )
737 return { };
738 it3 = rit2->second.lower_bound( r );
739 rit3 = rit2->second.rbegin();
740 if ( it3 != rit2->second.end() )
741 return calculateData( it3->second, time_key);
742 if ( rit3 != rit2->second.rend() )
743 return calculateData( rit3->second, time_key);
744 return { };
745 }
746 else {
747 it3 = it2->second.lower_bound( r );
748 rit3 = it2->second.rbegin();
749 if ( it3 != it2->second.end() )
750 return calculateData(it3->second, time_key);
751 if ( rit3 != it2->second.rend() )
752 return calculateData(rit3->second, time_key);
753 return { };
754 }
755 if ( it3 == it2->second.end() )
756 return { };
757 return calculateData(it3->second, time_key);
758 }
759
760
761 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
762 std::optional< Data > CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::get( const T& tx, const T& rx, const Time& time_key ) const {
763 MidFunctor mid_funct;
764 InFunctor in_funct;
765
766 double curr_b;
767 double curr_r;
768 double delta_b;
769 double delta_r;
770
771 double curr_dist;
772 double min_dist = INFINITY;
773
774 if ( data_map.empty() == true ) {
775 if ( debug )
776 std::cout << "CustomDataTimeContainer::get() data_map is empty " << std::endl;
777
778 return {};
779 }
780 const TimeData* time_data_ptr = nullptr;
781
782 for ( CDCCIt it = data_map.begin(); it != data_map.end(); it++ ) {
783 if ( debug )
784 std::cout << "CustomDataTimeContainer::get() start T = " << it->first << "; end T = " << rx << std::endl;
785
786 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
787 if ( debug )
788 std::cout << "CustomDataTimeContainer::get() overriding start T = " << tx << "; end T = " << rx << std::endl;
789
790 curr_b = mid_funct(tx,rx);
791 curr_r = in_funct(tx,rx);
792 }
793 else {
794 curr_b = mid_funct(it->first,rx);
795 curr_r = in_funct(it->first,rx);
796 }
797
798 if ( debug )
799 std::cout << "CustomDataTimeContainer::get() curr bearing = " << curr_b * 180.0 / M_PI
800 << "; curr range = " << curr_r << std::endl;
801
802 CDCMediumCIt itb = it->second.begin();
803 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS )
804 delta_b = 0;
805 else {
806 itb = it->second.lower_bound( curr_b );
807 if ( itb == it->second.end() )
808 itb = (++(it->second.rbegin())).base();
809
810 delta_b = curr_b - itb->first;
811 if (delta_b < 0.0)
812 delta_b = -delta_b;
813 if (delta_b > M_PI)
814 delta_b = 2.0*M_PI - delta_b ;
815 }
816
817 double ort_dist = curr_r * sin(delta_b);
818 double ort_projection = std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
819
820 if ( debug )
821 std::cout << "CustomDataTimeContainer::get() nearest bearing = " << itb->first * 180.0 / M_PI
822 << "; diff bearing = " << delta_b * 180.0 / M_PI << "; orthog distance = " << ort_dist
823 << "; orthog range projection = " << ort_projection << std::endl;
824
825 CDCInnerCIt itr = itb->second.begin();
826 if ( itr->first == DB_CDATA_ALL_INNER_KEYS )
827 curr_dist = ort_dist;
828 else {
829 itr = itb->second.lower_bound( ort_projection );
830 if ( itr == itb->second.begin() || itr == itb->second.end() || itr->first == ort_projection ) {
831 if ( itr == itb->second.end() ) itr = (++(itb->second.rbegin())).base();
832 double adj_distance = std::abs( ort_projection - itr->first );
833 curr_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
834 }
835 else {
836 double adj_distance = std::abs( ort_projection - itr->first );
837 double first_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
838
839 if (debug)
840 std::cout << "CustomDataTimeContainer::get() first try, range = " << itr->first
841 << "; dist = " << first_dist << std::endl;
842
843 itr--;
844 adj_distance = std::abs( ort_projection - itr->first );
845 double before_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
846
847 if (debug)
848 std::cout << "CustomDataTimeContainer::get() second try, range = " << itr->first
849 << "; dist = " << before_dist << std::endl;
850
851 curr_dist = std::min( first_dist, before_dist );
852 if ( curr_dist == first_dist )
853 itr++;
854 }
855 }
856 if ( debug )
857 std::cout << "CustomDataTimeContainer::get() nearest range = " << itr->first << "; distance = " << curr_dist
858 << "; min distance = " << min_dist << std::endl;
859
860 if ( curr_dist < min_dist ) {
861 min_dist = curr_dist;
862 time_data_ptr = &(itr->second);
863 if ( curr_dist == 0 )
864 break;
865 }
866
867 }
868
869 if ( time_data_ptr != nullptr )
870 return calculateData( *time_data_ptr, time_key);
871 return {};
872 }
873
874
875 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
876 std::optional<Data> CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::find( const T& t, double b, double r, const Time& time_key ) const {
877 if (debug)
878 std::cout << "CustomDataTimeContainer::find() << t = " << t << "; b = " << b << "; r = "
879 << r << "; time_key = " << time_key << std::endl;
880
881 CDCCIt it = data_map.find( t );
882 if ( it == data_map.end() ) {
883
884 if ( debug )
885 std::cout << "CustomDataTimeContainer::find() t not found" << std::endl;
886
887 return { };
888 }
889
890 if ( debug ) std::cout << "CustomDataTimeContainer::find() t found" << std::endl;
891
892 CDCMediumCIt it2 = it->second.find( b );
893 if ( it2 == it->second.end() ) {
894 if ( debug )
895 std::cout << "CustomDataTimeContainer::find() b not found" << std::endl;
896
897 return {};
898 }
899
900 if ( debug ) std::cout << "CustomDataTimeContainer::find() b found" << std::endl;
901
902 CDCInnerCIt it3 = it2->second.find( r );
903 if ( it3 == it2->second.end() ) {
904 if ( debug )
905 std::cout << "CustomDataTimeContainer::find() r not found" << std::endl;
906
907 return {};
908 }
909 if ( debug ) std::cout << "CustomDataTimeContainer::find() r found" << std::endl;
910
911 CDTCTimeCIt it4 = it3->second.find( time_key );
912 if ( it4 == it3->second.end() ) {
913 if ( debug )
914 std::cout << "CustomDataTimeContainer::find() time_key not found" << std::endl;
915
916 return {};
917 }
918
919 if ( debug ) std::cout << "CustomDataTimeContainer::find() time_key found, Data = " << it4->second << std::endl;
920
921 return it4->second;
922 }
923
924
925 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
926 bool CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::insert( const Data& d, const T& t, double b, double r, const Time& time_key ) {
927 auto data = find( t, b, r, time_key );
928 if ( data )
929 return false;
930 data_map[t][b][r][time_key] = d;
931 return true;
932 }
933
934
935 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
936 void CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::replace( const Data& d, const T& t, double b, double r, const Time& time_key ) {
937 data_map[t][b][r][time_key] = d;
938 }
939
940
941 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
943 data_map[t][b][r].erase(time_key);
944 if ( data_map[t][b][r].empty() )
945 data_map[t][b].erase(r);
946 if ( data_map[t][b].empty() )
947 data_map[t].erase(b);
948 if ( data_map[t].empty() )
949 data_map.erase(t);
950 }
951
952
953 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
957
958 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
960 if (debug)
961 std::cout << "CustomDataTimeContainer::calculateData() time_key = " << time_key << std::endl;
962
963 if ( time_data.empty() ) {
964 if (debug)
965 std::cout << "CustomDataTimeContainer::calculateData() time_data is empty." << std::endl;
966
967 return {};
968 }
969
970 if ( time_data.size() == 1 ) {
971 if (debug)
972 std::cout << "CustomDataTimeContainer::calculateData() time_data has size 1. Data created "
973 << time_data.begin()->second << std::endl;
974
975 return time_data.begin()->second;
976 }
977
978 time_t normalized_time = time_key;
979
980 if ( normalized_time < time_data.begin()->first ) {
981 if (debug)
982 std::cout << "CustomDataTimeContainer::calculateData() time_key has time < first key. Data created "
983 << time_data.begin()->second << std::endl;
984
985 return time_data.begin()->second;
986 }
987
988 normalized_time %= ( time_data.rbegin()->first - time_data.begin()->first );
989 if ( normalized_time == 0 )
990 return time_data.begin()->second;
991
992 normalized_time += time_data.begin()->first;
993 auto upper_it = time_data.upper_bound(normalized_time);
994 auto lower_it = upper_it;
995 --lower_it;
996
997 double alpha = ( std::abs((double)(upper_it->first - normalized_time)) / std::abs((double)( upper_it->first - lower_it->first )) );
998 double beta = ( std::abs((double)(normalized_time - lower_it->first)) / std::abs((double)( upper_it->first - lower_it->first )) );
999
1000 if (debug)
1001 std::cout << "CustomDataTimeContainer::calculateData() normalized_time = " << normalized_time
1002 << "; lower_it time = " << lower_it->first
1003 << "; upper_it time = " << upper_it->first
1004 << "; alpha = " << alpha << "; beta " << beta << std::endl;
1005
1006 Data ret_val = lower_it->second * alpha + upper_it->second * beta;
1007
1008 if (debug)
1009 std::cout << "CustomDataTimeContainer::calculateData() return value = "
1010 << ret_val << std::endl;
1011
1012 return ret_val;
1013 }
1014
1019 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1020 class CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >
1021 {
1022
1023 protected:
1024
1028 using TimeData = typename std::map< time_t, std::shared_ptr< Data > >;
1029 using CDTCTimeIt = typename TimeData::iterator;
1030 using CDTCTimeRIt = typename TimeData::reverse_iterator;
1031 using CDTCTimeCIt = typename TimeData::const_iterator;
1032 using CDTCTimeCRIt = typename TimeData::const_reverse_iterator;
1033
1037 using InnerData = typename std::map< double, TimeData, InComp >;
1038 using CDCInnerIt = typename InnerData::iterator;
1039 using CDCInnerRIt = typename InnerData::reverse_iterator;
1040 using CDCInnerCIt = typename InnerData::const_iterator;
1041 using CDCInnerCRIt = typename InnerData::const_reverse_iterator;
1042
1046 using MediumData = typename std::map< double, InnerData, MidComp >;
1047 using CDCMediumIt = typename MediumData::iterator;
1048 using CDCMediumCIt = typename MediumData::const_iterator;
1049 using CDCMediumRIt = typename MediumData::reverse_iterator;
1050 using CDCMediumCRIt = typename MediumData::const_reverse_iterator;
1051
1055 using CustomContainer = typename std::map< T, MediumData, OutComp >;
1056 using CDCIt = typename CustomContainer::iterator;
1057 using CDCRIt = typename CustomContainer::reverse_iterator;
1058 using CDCCIt = typename CustomContainer::const_iterator;
1059 using CDCCRIt = typename CustomContainer::const_reverse_iterator;
1060
1061
1062 public:
1063
1064
1065 static constexpr inline double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
1066
1067 static constexpr inline double DB_CDATA_ALL_INNER_KEYS = -10.0;
1068
1070
1072
1073
1078
1083
1089 MediumData& operator[] ( const T& key ) { return data_map[key]; }
1090
1091
1096 bool empty() const { return data_map.empty(); }
1097
1098
1103 int size() const { return data_map.size(); }
1104
1105
1118 std::optional< std::shared_ptr<Data> > get( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
1119
1128 std::optional< std::shared_ptr<Data> > get( const T& tx, const T& rx, const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
1129
1143 bool insert( const std::shared_ptr<Data>& data, const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS );
1144
1158 void replace( const std::shared_ptr<Data>& data, const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS );
1159
1172 void erase( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS);
1173
1174
1178 void clear();
1179
1180
1185 void setDebug( bool flag ) { debug = flag; }
1186
1187
1192 bool usingDebug() const { return debug; }
1193
1194
1195 protected:
1196
1197
1201 bool debug;
1202
1203
1208
1221 std::optional< std::shared_ptr<Data> > find( const T& t = DB_CDATA_ALL_OUTER_KEYS, double b = DB_CDATA_ALL_MEDIUM_KEYS, double r = DB_CDATA_ALL_INNER_KEYS, const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
1222
1235 std::optional< std::shared_ptr<Data> > calculateData( const TimeData& time_data , const Time& time_key = DB_CDATA_ALL_TIME_KEYS ) const;
1236
1237 };
1238
1239 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1240 const T CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::DB_CDATA_ALL_OUTER_KEYS = T();
1241
1242
1243 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1244 const Time CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::DB_CDATA_ALL_TIME_KEYS = Time(1, 1, 1901, 0, 0, 0);
1245
1246
1247 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1248 std::optional< std::shared_ptr<Data> > CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::get( const T& t, double b, double r, const Time& time_key ) const {
1249 if ( data_map.empty() )
1250 return { };
1251
1252 if ( debug )
1253 std::cout << "CustomDataTimeContainer::get() t = " << t << "; b = " << b << "; r = " << r
1254 << "; time_key = " << time_key << std::endl;
1255
1256 auto ret_val = find();
1257 if ( ret_val )
1258 return ret_val;
1259
1260 CDCCIt it = data_map.find( t );
1261 if ( it == data_map.end() )
1262 return { };
1263
1264 CDCMediumCIt it2 = it->second.lower_bound( b );
1265 CDCMediumCRIt rit2 = it->second.rbegin();
1266
1267 CDCInnerCIt it3;
1268 CDCInnerCRIt rit3;
1269
1270 if ( it2 == it->second.end() ) {
1271 if ( rit2 == it->second.rend() )
1272 return { };
1273 it3 = rit2->second.lower_bound( r );
1274 rit3 = rit2->second.rbegin();
1275 if ( it3 != rit2->second.end() )
1276 return calculateData( it3->second, time_key);
1277 if ( rit3 != rit2->second.rend() )
1278 return calculateData( rit3->second, time_key);
1279 return { };
1280 }
1281 else {
1282 it3 = it2->second.lower_bound( r );
1283 rit3 = it2->second.rbegin();
1284 if ( it3 != it2->second.end() )
1285 return calculateData(it3->second, time_key);
1286 if ( rit3 != it2->second.rend() )
1287 return calculateData(rit3->second, time_key);
1288 return { };
1289 }
1290 if ( it3 == it2->second.end() )
1291 return { };
1292 return calculateData(it3->second, time_key);
1293 }
1294
1295
1296 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1297 std::optional< std::shared_ptr< Data > > CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp > ::get( const T& tx, const T& rx, const Time& time_key ) const {
1298 MidFunctor mid_funct;
1299 InFunctor in_funct;
1300
1301 double curr_b;
1302 double curr_r;
1303 double delta_b;
1304 double delta_r;
1305
1306 double curr_dist;
1307 double min_dist = INFINITY;
1308
1309 if ( data_map.empty() == true ) {
1310 if ( debug )
1311 std::cout << "CustomDataTimeContainer::get() data_map is empty " << std::endl;
1312
1313 return {};
1314 }
1315 const TimeData* time_data_ptr = nullptr;
1316
1317 for ( CDCCIt it = data_map.begin(); it != data_map.end(); it++ ) {
1318 if ( debug )
1319 std::cout << "CustomDataTimeContainer::get() start T = " << it->first << "; end T = " << rx << std::endl;
1320
1321 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
1322 if ( debug )
1323 std::cout << "CustomDataTimeContainer::get() overriding start T = " << tx << "; end T = " << rx << std::endl;
1324
1325 curr_b = mid_funct(tx,rx);
1326 curr_r = in_funct(tx,rx);
1327 }
1328 else {
1329 curr_b = mid_funct(it->first,rx);
1330 curr_r = in_funct(it->first,rx);
1331 }
1332
1333 if ( debug )
1334 std::cout << "CustomDataTimeContainer::get() curr bearing = " << curr_b * 180.0 / M_PI
1335 << "; curr range = " << curr_r << std::endl;
1336
1337 CDCMediumCIt itb = it->second.begin();
1338 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS )
1339 delta_b = 0;
1340 else {
1341 itb = it->second.lower_bound( curr_b );
1342 if ( itb == it->second.end() )
1343 itb = (++(it->second.rbegin())).base();
1344
1345 delta_b = curr_b - itb->first;
1346 if (delta_b < 0.0)
1347 delta_b = -delta_b;
1348 if (delta_b > M_PI)
1349 delta_b = 2.0*M_PI - delta_b ;
1350 }
1351
1352 double ort_dist = curr_r * sin(delta_b);
1353 double ort_projection = std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
1354
1355 if ( debug )
1356 std::cout << "CustomDataTimeContainer::get() nearest bearing = " << itb->first * 180.0 / M_PI
1357 << "; diff bearing = " << delta_b * 180.0 / M_PI << "; orthog distance = " << ort_dist
1358 << "; orthog range projection = " << ort_projection << std::endl;
1359
1360 CDCInnerCIt itr = itb->second.begin();
1361 if ( itr->first == DB_CDATA_ALL_INNER_KEYS )
1362 curr_dist = ort_dist;
1363 else {
1364 itr = itb->second.lower_bound( ort_projection );
1365 if ( itr == itb->second.begin() || itr == itb->second.end() || itr->first == ort_projection ) {
1366 if ( itr == itb->second.end() ) itr = (++(itb->second.rbegin())).base();
1367 double adj_distance = std::abs( ort_projection - itr->first );
1368 curr_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1369 }
1370 else {
1371 double adj_distance = std::abs( ort_projection - itr->first );
1372 double first_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1373
1374 if (debug)
1375 std::cout << "CustomDataTimeContainer::get() first try, range = " << itr->first
1376 << "; dist = " << first_dist << std::endl;
1377
1378 itr--;
1379 adj_distance = std::abs( ort_projection - itr->first );
1380 double before_dist = std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1381
1382 if (debug)
1383 std::cout << "CustomDataTimeContainer::get() second try, range = " << itr->first
1384 << "; dist = " << before_dist << std::endl;
1385
1386 curr_dist = std::min( first_dist, before_dist );
1387 if ( curr_dist == first_dist )
1388 itr++;
1389 }
1390 }
1391 if ( debug )
1392 std::cout << "CustomDataTimeContainer::get() nearest range = " << itr->first << "; distance = " << curr_dist
1393 << "; min distance = " << min_dist << std::endl;
1394
1395 if ( curr_dist < min_dist ) {
1396 min_dist = curr_dist;
1397 time_data_ptr = &(itr->second);
1398 if ( curr_dist == 0 )
1399 break;
1400 }
1401
1402 }
1403
1404 if ( time_data_ptr != nullptr )
1405 return calculateData( *time_data_ptr, time_key);
1406 return {};
1407 }
1408
1409
1410 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1411 std::optional< std::shared_ptr< Data > > CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp > ::find( const T& t, double b, double r, const Time& time_key ) const {
1412 if (debug)
1413 std::cout << "CustomDataTimeContainer::find() << t = " << t << "; b = " << b << "; r = "
1414 << r << "; time_key = " << time_key << std::endl;
1415
1416 CDCCIt it = data_map.find( t );
1417 if ( it == data_map.end() ) {
1418
1419 if ( debug )
1420 std::cout << "CustomDataTimeContainer::find() t not found" << std::endl;
1421
1422 return { };
1423 }
1424
1425 if ( debug ) std::cout << "CustomDataTimeContainer::find() t found" << std::endl;
1426
1427 CDCMediumCIt it2 = it->second.find( b );
1428 if ( it2 == it->second.end() ) {
1429 if ( debug )
1430 std::cout << "CustomDataTimeContainer::find() b not found" << std::endl;
1431
1432 return {};
1433 }
1434
1435 if ( debug ) std::cout << "CustomDataTimeContainer::find() b found" << std::endl;
1436
1437 CDCInnerCIt it3 = it2->second.find( r );
1438 if ( it3 == it2->second.end() ) {
1439 if ( debug )
1440 std::cout << "CustomDataTimeContainer::find() r not found" << std::endl;
1441
1442 return {};
1443 }
1444 if ( debug ) std::cout << "CustomDataTimeContainer::find() r found" << std::endl;
1445
1446 CDTCTimeCIt it4 = it3->second.find( time_key );
1447 if ( it4 == it3->second.end() ) {
1448 if ( debug )
1449 std::cout << "CustomDataTimeContainer::find() time_key not found" << std::endl;
1450
1451 return {};
1452 }
1453
1454 if ( debug )
1455 std::cout << "CustomDataTimeContainer::find() time_key found, Data = " << it4->second << std::endl;
1456
1457 return it4->second;
1458 }
1459
1460
1461 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1462 bool CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::insert( const std::shared_ptr< Data >& d, const T& t, double b, double r, const Time& time_key ) {
1463 auto data = find( t, b, r, time_key );
1464 if ( data )
1465 return false;
1466 data_map[t][b][r][time_key] = d;
1467 return true;
1468 }
1469
1470
1471 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1472 void CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::replace( const std::shared_ptr< Data >& d, const T& t, double b, double r, const Time& time_key ) {
1473 data_map[t][b][r][time_key] = d;
1474 }
1475
1476
1477 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1478 void CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::erase( const T& t, double b, double r, const Time& time_key ) {
1479 data_map[t][b][r].erase(time_key);
1480 if ( data_map[t][b][r].empty() )
1481 data_map[t][b].erase(r);
1482 if ( data_map[t][b].empty() )
1483 data_map[t].erase(b);
1484 if ( data_map[t].empty() )
1485 data_map.erase(t);
1486 }
1487
1488
1489 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1491 data_map.clear();
1492 }
1493
1494
1495 template < class T, class MidFunctor, class InFunctor, class Data, class OutComp, class MidComp, class InComp >
1496 std::optional< std::shared_ptr< Data > > CustomDataTimeContainer< T, MidFunctor, InFunctor, std::shared_ptr< Data >, OutComp, MidComp, InComp >::calculateData( const TimeData& time_data, const Time& time_key ) const {
1497 if (debug)
1498 std::cout << "CustomDataTimeContainer::calculateData() time_key = " << time_key << std::endl;
1499
1500 if ( time_data.empty() ) {
1501 if (debug)
1502 std::cout << "CustomDataTimeContainer::calculateData() time_data is empty." << std::endl;
1503
1504 return {};
1505 }
1506
1507 if ( time_data.size() == 1 ) {
1508 if (debug)
1509 std::cout << "CustomDataTimeContainer::calculateData() time_data has size 1. Data created "
1510 << time_data.begin()->second << std::endl;
1511
1512 return time_data.begin()->second;
1513 }
1514
1515 time_t normalized_time = time_key;
1516
1517 if ( normalized_time < time_data.begin()->first ) {
1518 if (debug)
1519 std::cout << "CustomDataTimeContainer::calculateData() time_key has time < first key. Data created "
1520 << time_data.begin()->second << std::endl;
1521
1522 return time_data.begin()->second;
1523 }
1524
1525 normalized_time %= ( time_data.rbegin()->first - time_data.begin()->first );
1526 if ( normalized_time == 0 )
1527 return time_data.begin()->second;
1528
1529 normalized_time += time_data.begin()->first;
1530 auto upper_it = time_data.upper_bound(normalized_time);
1531 auto lower_it = upper_it;
1532 --lower_it;
1533
1534 double alpha = ( std::abs((double)(upper_it->first - normalized_time)) / std::abs((double)( upper_it->first - lower_it->first )) );
1535 double beta = ( std::abs((double)(normalized_time - lower_it->first)) / std::abs((double)( upper_it->first - lower_it->first )) );
1536
1537 if (debug)
1538 std::cout << "CustomDataTimeContainer::calculateData() normalized_time = " << normalized_time
1539 << "; lower_it time = " << lower_it->first
1540 << "; upper_it time = " << upper_it->first
1541 << "; alpha = " << alpha << "; beta " << beta << std::endl;
1542
1543 std::shared_ptr< Data > ret_val = std::move(lower_it->second->clone());
1544
1545 *ret_val *= alpha + *(upper_it->second) * beta;
1546
1547 if (debug)
1548 std::cout << "CustomDataTimeContainer::calculateData() return value = "
1549 << ret_val << std::endl;
1550
1551 return ret_val;
1552 }
1553
1554}
1555
1556#endif /* WOSS_DB_CUSTOM_DATA_CONTAINER_H */
1557
Class for managing custom db data.
Definition woss-db-custom-data-container.h:54
MediumData & operator[](const T &key)
Definition woss-db-custom-data-container.h:116
typename CustomContainer::reverse_iterator CDCRIt
Definition woss-db-custom-data-container.h:81
typename std::map< double, InnerData, MidComp > MediumData
Definition woss-db-custom-data-container.h:70
typename CustomContainer::const_reverse_iterator CDCCRIt
Definition woss-db-custom-data-container.h:83
int size() const
Definition woss-db-custom-data-container.h:130
bool usingDebug()
Definition woss-db-custom-data-container.h:210
static constexpr double DB_CDATA_ALL_MEDIUM_KEYS
Definition woss-db-custom-data-container.h:88
typename MediumData::const_reverse_iterator CDCMediumCRIt
Definition woss-db-custom-data-container.h:74
typename InnerData::iterator CDCInnerIt
Definition woss-db-custom-data-container.h:62
bool insert(const Data &data, const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS)
Definition woss-db-custom-data-container.h:450
typename InnerData::reverse_iterator CDCInnerRIt
Definition woss-db-custom-data-container.h:63
typename MediumData::reverse_iterator CDCMediumRIt
Definition woss-db-custom-data-container.h:73
const std::optional< Data > get(const T &tx, const T &rx) const
Definition woss-db-custom-data-container.h:294
void replace(const Data &data, const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS)
Definition woss-db-custom-data-container.h:460
bool debug
Definition woss-db-custom-data-container.h:219
typename std::map< T, MediumData, OutComp > CustomContainer
Definition woss-db-custom-data-container.h:79
const std::optional< Data > get(const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS) const
Definition woss-db-custom-data-container.h:246
bool empty() const
Definition woss-db-custom-data-container.h:123
typename InnerData::const_iterator CDCInnerCIt
Definition woss-db-custom-data-container.h:64
typename CustomContainer::iterator CDCIt
Definition woss-db-custom-data-container.h:80
void setDebug(bool flag)
Definition woss-db-custom-data-container.h:203
void clear()
Definition woss-db-custom-data-container.h:477
CustomContainer data_map
Definition woss-db-custom-data-container.h:224
typename MediumData::iterator CDCMediumIt
Definition woss-db-custom-data-container.h:71
std::optional< Data > find(const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS) const
Definition woss-db-custom-data-container.h:407
typename InnerData::const_reverse_iterator CDCInnerCRIt
Definition woss-db-custom-data-container.h:65
typename CustomContainer::const_iterator CDCCIt
Definition woss-db-custom-data-container.h:82
typename MediumData::const_iterator CDCMediumCIt
Definition woss-db-custom-data-container.h:72
static constexpr double DB_CDATA_ALL_INNER_KEYS
Definition woss-db-custom-data-container.h:90
void erase(const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS)
Definition woss-db-custom-data-container.h:467
typename std::map< double, Data, InComp > InnerData
Definition woss-db-custom-data-container.h:61
static const T DB_CDATA_ALL_OUTER_KEYS
Definition woss-db-custom-data-container.h:97
typename TimeData::const_iterator CDTCTimeCIt
Definition woss-db-custom-data-container.h:1031
typename TimeData::iterator CDTCTimeIt
Definition woss-db-custom-data-container.h:1029
typename TimeData::reverse_iterator CDTCTimeRIt
Definition woss-db-custom-data-container.h:1030
typename InnerData::reverse_iterator CDCInnerRIt
Definition woss-db-custom-data-container.h:1039
typename TimeData::const_reverse_iterator CDTCTimeCRIt
Definition woss-db-custom-data-container.h:1032
typename InnerData::const_reverse_iterator CDCInnerCRIt
Definition woss-db-custom-data-container.h:1041
typename MediumData::const_iterator CDCMediumCIt
Definition woss-db-custom-data-container.h:1048
typename CustomContainer::reverse_iterator CDCRIt
Definition woss-db-custom-data-container.h:1057
typename MediumData::reverse_iterator CDCMediumRIt
Definition woss-db-custom-data-container.h:1049
typename std::map< double, InnerData, MidComp > MediumData
Definition woss-db-custom-data-container.h:1046
typename CustomContainer::const_reverse_iterator CDCCRIt
Definition woss-db-custom-data-container.h:1059
typename MediumData::const_reverse_iterator CDCMediumCRIt
Definition woss-db-custom-data-container.h:1050
typename MediumData::iterator CDCMediumIt
Definition woss-db-custom-data-container.h:1047
typename CustomContainer::const_iterator CDCCIt
Definition woss-db-custom-data-container.h:1058
typename std::map< T, MediumData, OutComp > CustomContainer
Definition woss-db-custom-data-container.h:1055
typename std::map< double, TimeData, InComp > InnerData
Definition woss-db-custom-data-container.h:1037
typename InnerData::const_iterator CDCInnerCIt
Definition woss-db-custom-data-container.h:1040
typename InnerData::iterator CDCInnerIt
Definition woss-db-custom-data-container.h:1038
typename CustomContainer::iterator CDCIt
Definition woss-db-custom-data-container.h:1056
typename std::map< time_t, std::shared_ptr< Data > > TimeData
Definition woss-db-custom-data-container.h:1028
Class for managing custom db data.
Definition woss-db-custom-data-container.h:490
typename MediumData::const_iterator CDCMediumCIt
Definition woss-db-custom-data-container.h:517
typename CustomContainer::iterator CDCIt
Definition woss-db-custom-data-container.h:525
std::optional< Data > calculateData(const TimeData &time_data, const Time &time_key=DB_CDATA_ALL_TIME_KEYS) const
Definition woss-db-custom-data-container.h:959
bool insert(const Data &data, const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS, const Time &time_key=DB_CDATA_ALL_TIME_KEYS)
Definition woss-db-custom-data-container.h:926
bool empty() const
Definition woss-db-custom-data-container.h:562
typename std::map< T, MediumData, OutComp > CustomContainer
Definition woss-db-custom-data-container.h:524
typename std::map< double, InnerData, MidComp > MediumData
Definition woss-db-custom-data-container.h:515
typename CustomContainer::const_reverse_iterator CDCCRIt
Definition woss-db-custom-data-container.h:528
typename MediumData::iterator CDCMediumIt
Definition woss-db-custom-data-container.h:516
static constexpr double DB_CDATA_ALL_INNER_KEYS
Definition woss-db-custom-data-container.h:534
typename TimeData::iterator CDTCTimeIt
Definition woss-db-custom-data-container.h:498
typename std::map< time_t, Data > TimeData
Definition woss-db-custom-data-container.h:497
typename InnerData::const_reverse_iterator CDCInnerCRIt
Definition woss-db-custom-data-container.h:510
std::optional< Data > find(const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS, const Time &time_key=DB_CDATA_ALL_TIME_KEYS) const
Definition woss-db-custom-data-container.h:876
bool usingDebug() const
Definition woss-db-custom-data-container.h:658
static constexpr double DB_CDATA_ALL_MEDIUM_KEYS
Definition woss-db-custom-data-container.h:532
void erase(const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS, const Time &time_key=DB_CDATA_ALL_TIME_KEYS)
Definition woss-db-custom-data-container.h:942
typename TimeData::const_iterator CDTCTimeCIt
Definition woss-db-custom-data-container.h:500
typename std::map< double, TimeData, InComp > InnerData
Definition woss-db-custom-data-container.h:506
typename InnerData::iterator CDCInnerIt
Definition woss-db-custom-data-container.h:507
typename CustomContainer::reverse_iterator CDCRIt
Definition woss-db-custom-data-container.h:526
MediumData & operator[](const T &key)
Definition woss-db-custom-data-container.h:555
std::optional< Data > get(const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS, const Time &time_key=DB_CDATA_ALL_TIME_KEYS) const
Definition woss-db-custom-data-container.h:713
void replace(const Data &data, const T &t=DB_CDATA_ALL_OUTER_KEYS, double b=DB_CDATA_ALL_MEDIUM_KEYS, double r=DB_CDATA_ALL_INNER_KEYS, const Time &time_key=DB_CDATA_ALL_TIME_KEYS)
Definition woss-db-custom-data-container.h:936
typename TimeData::reverse_iterator CDTCTimeRIt
Definition woss-db-custom-data-container.h:499
static const Time DB_CDATA_ALL_TIME_KEYS
Definition woss-db-custom-data-container.h:538
typename InnerData::const_iterator CDCInnerCIt
Definition woss-db-custom-data-container.h:509
bool debug
Definition woss-db-custom-data-container.h:667
CustomContainer data_map
Definition woss-db-custom-data-container.h:672
typename MediumData::reverse_iterator CDCMediumRIt
Definition woss-db-custom-data-container.h:518
typename TimeData::const_reverse_iterator CDTCTimeCRIt
Definition woss-db-custom-data-container.h:501
int size() const
Definition woss-db-custom-data-container.h:569
CustomDataTimeContainer()
Definition woss-db-custom-data-container.h:543
static const T DB_CDATA_ALL_OUTER_KEYS
Definition woss-db-custom-data-container.h:536
typename MediumData::const_reverse_iterator CDCMediumCRIt
Definition woss-db-custom-data-container.h:519
void clear()
Definition woss-db-custom-data-container.h:954
std::optional< Data > get(const T &tx, const T &rx, const Time &time_key=DB_CDATA_ALL_TIME_KEYS) const
Definition woss-db-custom-data-container.h:762
typename InnerData::reverse_iterator CDCInnerRIt
Definition woss-db-custom-data-container.h:508
void setDebug(bool flag)
Definition woss-db-custom-data-container.h:651
typename CustomContainer::const_iterator CDCCIt
Definition woss-db-custom-data-container.h:527
a class for time date manipulation
Definition time-definitions.h:83
Definition ac-toolbox-arr-asc-reader.h:44
Definitions and library for woss::Time, woss::SimTime, woss::TimeReference and woss::TimeReferenceTcl...