40#ifndef WOSS_DB_CUSTOM_DATA_CONTAINER_H
41#define WOSS_DB_CUSTOM_DATA_CONTAINER_H
59 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp = ::std::less<T>,
class M
idComp = ::std::less<
double>,
class InComp = ::std::less<
double> >
69 typedef typename ::std::map< double, Data, InComp >
InnerData;
70 typedef typename InnerData::iterator CDCInnerIt;
71 typedef typename InnerData::reverse_iterator CDCInnerRIt;
72 typedef typename InnerData::const_iterator CDCInnerCIt;
73 typedef typename InnerData::const_reverse_iterator CDCInnerCRIt;
78 typedef typename ::std::map< double, InnerData, MidComp >
MediumData;
79 typedef typename MediumData::iterator CDCMediumIt;
80 typedef typename MediumData::const_iterator CDCMediumCIt;
81 typedef typename MediumData::reverse_iterator CDCMediumRIt;
82 typedef typename MediumData::const_reverse_iterator CDCMediumCRIt;
88 typedef typename CustomContainer::iterator CDCIt;
89 typedef typename CustomContainer::reverse_iterator CDCRIt;
90 typedef typename CustomContainer::const_iterator CDCCIt;
91 typedef typename CustomContainer::const_reverse_iterator CDCCRIt;
96#if __cplusplus >= 201103L
97 static constexpr double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
99 static constexpr double DB_CDATA_ALL_INNER_KEYS = -10.0;
101 static const double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
103 static const double DB_CDATA_ALL_INNER_KEYS = -10.0;
106 static const T DB_CDATA_ALL_OUTER_KEYS;
152 const 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;
160 const Data*
get(
const T& tx,
const T& rx )
const;
174 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 );
187 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 );
200 void erase(
const T& t = DB_CDATA_ALL_OUTER_KEYS,
double b = DB_CDATA_ALL_MEDIUM_KEYS,
double r = DB_CDATA_ALL_INNER_KEYS );
251 const 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;
257 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
261 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
263 if ( data_map.empty() )
return NULL;
265 if ( debug ) ::std::cout <<
"CustomDataContainer::get() t = " << t <<
"; b = " << b <<
"; r = " << r << ::std::endl;
267 const Data* ptr = find();
268 if ( ptr != NULL )
return ptr;
270 CDCCIt it = data_map.find( t );
271 if ( it == data_map.end() )
return NULL;
273 CDCMediumCIt it2 = it->second.lower_bound( b );
274 CDCMediumCRIt rit2 = it->second.rbegin();
279 if ( it2 == it->second.end() ) {
280 if( rit2 == it->second.rend() )
return NULL;
281 it3 = rit2->second.lower_bound( r );
282 rit3 = rit2->second.rbegin();
283 if ( it3 != rit2->second.end() )
return &it3->second;
284 if ( rit3 != rit2->second.rend() )
return &rit3->second;
288 it3 = it2->second.lower_bound( r );
289 rit3 = it2->second.rbegin();
290 if ( it3 != it2->second.end() )
return &it3->second;
291 if ( rit3 != it2->second.rend() )
return &rit3->second;
294 if ( it3 == it2->second.end() )
return NULL;
295 return &(it3->second);
299 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
301 MidFunctor mid_funct;
308 const Data* ret_val = NULL;
311 double min_dist = INFINITY;
313 if ( data_map.empty() ==
true ) {
314 if ( debug ) ::std::cout <<
"CustomDataContainer::get() data_map is empty " << ::std::endl;
319 for ( CDCCIt it = data_map.begin(); it != data_map.end(); it++ ) {
321 if ( debug ) ::std::cout <<
"CustomDataContainer::get() start T = " << it->first <<
"; end T = " << rx << ::std::endl;
323 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
324 if ( debug ) ::std::cout <<
"CustomDataContainer::get() overriding start T = " << tx <<
"; end T = " << rx << ::std::endl;
326 curr_b = mid_funct(tx,rx);
327 curr_r = in_funct(tx,rx);
330 curr_b = mid_funct(it->first,rx);
331 curr_r = in_funct(it->first,rx);
334 if ( debug ) ::std::cout <<
"CustomDataContainer::get() curr bearing = " << curr_b * 180.0 / M_PI
335 <<
"; curr range = " << curr_r << ::std::endl;
337 CDCMediumCIt itb = it->second.begin();
338 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS ) delta_b = 0;
340 itb = it->second.lower_bound( curr_b );
341 if ( itb == it->second.end() ) itb = (++(it->second.rbegin())).base();
343 delta_b = curr_b - itb->first;
344 if (delta_b < 0.0) delta_b = -delta_b;
345 if (delta_b > M_PI) delta_b = 2.0*M_PI - delta_b ;
348 double ort_dist = curr_r * sin(delta_b);
349 double ort_projection = ::std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
351 if ( debug ) ::std::cout <<
"CustomDataContainer::get() nearest bearing = " << itb->first * 180.0 / M_PI
352 <<
"; diff bearing = " << delta_b * 180.0 / M_PI <<
"; orthog distance = " << ort_dist
353 <<
"; orthog range projection = " << ort_projection << ::std::endl;
355 CDCInnerCIt itr = itb->second.begin();
356 if ( itr->first == DB_CDATA_ALL_INNER_KEYS ) curr_dist = ort_dist;
358 itr = itb->second.lower_bound( ort_projection );
359 if ( itr == itb->second.begin() || itr == itb->second.end() || itr->first == ort_projection ) {
360 if ( itr == itb->second.end() ) itr = (++(itb->second.rbegin())).base();
361 double adj_distance = ::std::abs( ort_projection - itr->first );
362 curr_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
365 double adj_distance = ::std::abs( ort_projection - itr->first );
366 double first_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
368 if(debug) ::std::cout <<
"CustomDataContainer::get() first try, range = " << itr->first
369 <<
"; dist = " << first_dist << ::std::endl;
372 adj_distance = ::std::abs( ort_projection - itr->first );
373 double before_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
375 if (debug) ::std::cout <<
"CustomDataContainer::get() second try, range = " << itr->first
376 <<
"; dist = " << before_dist << ::std::endl;
378 curr_dist = ::std::min( first_dist, before_dist );
379 if ( curr_dist == first_dist ) itr++;
382 if ( debug ) ::std::cout <<
"CustomDataContainer::get() nearest range = " << itr->first <<
"; distance = " << curr_dist
383 <<
"; min distance = " << min_dist << ::std::endl;
385 if ( curr_dist < min_dist ) {
386 min_dist = curr_dist;
387 ret_val = &(itr->second);
388 if ( curr_dist == 0 )
break;
393 if ( debug && ret_val != NULL ) ::std::cout <<
"CustomDataContainer::get() ret value " << *ret_val << ::std::endl;
399 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
402 if (this->debug) ::std::cout <<
"CustomDataContainer::find() << t = " << t <<
"; b = " << b <<
"; r = " << r << ::std::endl;
404 CDCCIt it = data_map.find( t );
405 if ( it == data_map.end() ) {
407 if ( debug ) ::std::cout <<
"CustomDataContainer::find() t not found" << ::std::endl;
412 if ( debug ) ::std::cout <<
"CustomDataContainer::find() t found" << ::std::endl;
414 CDCMediumCIt it2 = it->second.find( b );
415 if ( it2 == it->second.end() ) {
417 if ( debug ) ::std::cout <<
"CustomDataContainer::find() b not found" << ::std::endl;
422 if ( debug ) ::std::cout <<
"CustomDataContainer::find() b found" << ::std::endl;
424 CDCInnerCIt it3 = it2->second.find( r );
425 if ( it3 == it2->second.end() ) {
427 if ( debug ) ::std::cout <<
"CustomDataContainer::find() r not found" << ::std::endl;
431 if ( debug ) ::std::cout <<
"CustomDataContainer::find() r found, data = " << it3->second << ::std::endl;
432 return &(it3->second);
436 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
438 const Data* ptr = find( t, b, r );
439 if ( ptr != NULL )
return false;
440 data_map[t][b][r] = d;
518 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
520 data_map[t][b][r] = d;
524 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
526 data_map[t][b].erase(r);
527 if ( data_map[t][b].empty() ) data_map[t].erase(b);
528 if ( data_map[t].empty() ) data_map.erase(t);
532 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
543 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
550 typedef typename ::std::map< double, Data*, InComp > InnerData;
551 typedef typename InnerData::iterator CDCInnerIt;
552 typedef typename InnerData::reverse_iterator CDCInnerRIt;
553 typedef typename InnerData::const_iterator CDCInnerCIt;
554 typedef typename InnerData::const_reverse_iterator CDCInnerCRIt;
556 typedef typename ::std::map< double, InnerData, MidComp > MediumData;
557 typedef typename MediumData::iterator CDCMediumIt;
558 typedef typename MediumData::const_iterator CDCMediumCIt;
559 typedef typename MediumData::reverse_iterator CDCMediumRIt;
560 typedef typename MediumData::const_reverse_iterator CDCMediumCRIt;
562 typedef ::std::map< T, MediumData, OutComp > CustomContainer;
563 typedef typename CustomContainer::iterator CDCIt;
564 typedef typename CustomContainer::reverse_iterator CDCRIt;
565 typedef typename CustomContainer::const_iterator CDCCIt;
566 typedef typename CustomContainer::const_reverse_iterator CDCCRIt;
571#if __cplusplus >= 201103L
572 static constexpr double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
574 static constexpr double DB_CDATA_ALL_INNER_KEYS = -10.0;
576 static const double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
578 static const double DB_CDATA_ALL_INNER_KEYS = -10.0;
580 static const T DB_CDATA_ALL_OUTER_KEYS;
589 bool empty()
const {
return data_map.empty(); }
592 int size()
const {
return data_map.size(); }
595 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;
597 Data* get(
const T& tx,
const T& rx )
const;
611 bool insert( Data* data,
const T& t = DB_CDATA_ALL_OUTER_KEYS,
double b = DB_CDATA_ALL_MEDIUM_KEYS,
double r = DB_CDATA_ALL_INNER_KEYS );
613 void replace( Data* data,
const T& t = DB_CDATA_ALL_OUTER_KEYS,
double b = DB_CDATA_ALL_MEDIUM_KEYS,
double r = DB_CDATA_ALL_INNER_KEYS );
626 void erase(
const T& t = DB_CDATA_ALL_OUTER_KEYS,
double b = DB_CDATA_ALL_MEDIUM_KEYS,
double r = DB_CDATA_ALL_INNER_KEYS );
638 void setDebug(
bool flag ) { debug = flag; }
640 bool usingDebug() {
return debug; }
649 CustomContainer data_map;
662 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;
668 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
672 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
675 static Data* not_found = NULL;
677 if (debug) ::std::cout <<
"CustomDataContainer*::find() << t = " << t <<
"; b = " << b <<
"; r = " << r << ::std::endl;
679 CDCCIt it = data_map.find( t );
680 if ( it == data_map.end() ) {
682 if ( debug ) ::std::cout <<
"CustomDataContainer*::find() t not found" << ::std::endl;
687 if ( debug ) ::std::cout <<
"CustomDataContainer*::find() t found" << ::std::endl;
689 CDCMediumCIt it2 = it->second.find( b );
690 if ( it2 == it->second.end() ) {
692 if ( debug ) ::std::cout <<
"CustomDataContainer*::find() b not found" << ::std::endl;
697 if ( debug ) ::std::cout <<
"CustomDataContainer*::find() b found" << ::std::endl;
699 CDCInnerCIt it3 = it2->second.find( r );
700 if ( it3 == it2->second.end() ) {
702 if ( debug ) ::std::cout <<
"CustomDataContainer*::find() r not found" << ::std::endl;
706 if ( debug ) ::std::cout <<
"CustomDataContainer*::find() r found, data = " << *it3->second << ::std::endl;
707 return const_cast<Data*&
>(it3->second);
711 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
714 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() t = " << t <<
"; b = " << b <<
"; r = " << r << ::std::endl;
716 if ( data_map.empty() )
return NULL;
718 Data* ptr = find( DB_CDATA_ALL_OUTER_KEYS, DB_CDATA_ALL_MEDIUM_KEYS, DB_CDATA_ALL_INNER_KEYS );
721 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() found ptr = " << ptr <<
"; object = " << *ptr << ::std::endl;
723 return new Data( *ptr );
726 CDCCIt it = data_map.find( t );
727 if ( it == data_map.end() )
return NULL;
729 CDCMediumCIt it2 = it->second.lower_bound( b );
730 CDCMediumCRIt rit2 = it->second.rbegin();
735 if ( it2 == it->second.end() ) {
736 if( rit2 == it->second.rend() )
return NULL;
737 it3 = rit2->second.lower_bound( r );
738 rit3 = rit2->second.rbegin();
739 if ( it3 != rit2->second.end() )
return new Data( *(it3->second) );
740 if ( rit3 != rit2->second.rend() )
return new Data ( *(rit3->second) );
744 it3 = it2->second.lower_bound( r );
745 rit3 = it2->second.rbegin();
746 if ( it3 != it2->second.end() )
return new Data( *(it3->second) );
747 if ( rit3 != it2->second.rend() )
return new Data( *(rit3->second) );
750 if ( it3 == it2->second.end() )
return NULL;
751 return new Data( *(it3->second) );
755 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
757 MidFunctor mid_funct;
764 const Data* ret_val = NULL;
767 double min_dist = INFINITY;
769 if ( data_map.empty() ==
true ) {
770 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() data_map is empty " << ::std::endl;
775 for ( CDCCIt it = data_map.begin(); it != data_map.end(); it++ ) {
777 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() start T = " << it->first <<
"; end T = " << rx << ::std::endl;
779 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
780 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() overriding start T = " << tx <<
"; end T = " << rx << ::std::endl;
782 curr_b = mid_funct(tx,rx);
783 curr_r = in_funct(tx,rx);
786 curr_b = mid_funct(it->first,rx);
787 curr_r = in_funct(it->first,rx);
790 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() curr bearing = " << curr_b * 180.0 / M_PI
791 <<
"; curr range = " << curr_r << ::std::endl;
793 CDCMediumCIt itb = it->second.begin();
794 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS ) delta_b = 0;
796 itb = it->second.lower_bound( curr_b );
797 if ( itb == it->second.end() ) itb = (++(it->second.rbegin())).base();
799 delta_b = curr_b - itb->first;
800 if (delta_b < 0.0) delta_b = -delta_b;
801 if (delta_b > M_PI) delta_b = 2.0*M_PI - delta_b ;
804 double ort_dist = curr_r * sin(delta_b);
805 double ort_projection = ::std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
807 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() nearest bearing = " << itb->first * 180.0 / M_PI
808 <<
"; diff bearing = " << delta_b * 180.0 / M_PI <<
"; orthog distance = " << ort_dist
809 <<
"; orthog range projection = " << ort_projection << ::std::endl;
811 CDCInnerCIt itr = itb->second.begin();
812 if ( itr->first == DB_CDATA_ALL_INNER_KEYS ) curr_dist = ort_dist;
814 itr = itb->second.lower_bound( ort_projection );
815 if ( itr == itb->second.begin() || itr == itb->second.end() || itr->first == ort_projection ) {
816 if ( itr == itb->second.end() ) itr = (++(itb->second.rbegin())).base();
818 double adj_distance = ::std::abs( ort_projection - itr->first );
819 curr_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
822 double adj_distance = ::std::abs( ort_projection - itr->first );
823 double first_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
825 if (debug) ::std::cout <<
"CustomDataContainer*::get() first try, range = " << itr->first
826 <<
"; dist = " << first_dist << ::std::endl;
829 adj_distance = ::std::abs( ort_projection - itr->first );
830 double before_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
832 if (debug) ::std::cout <<
"CustomDataContainer*::get() second try, range = " << itr->first
833 <<
"; dist = " << before_dist << ::std::endl;
835 curr_dist = ::std::min( first_dist, before_dist );
836 if ( curr_dist == first_dist ) itr++;
840 if ( debug ) ::std::cout <<
"CustomDataContainer*::get() nearest range = " << itr->first <<
"; distance = " << curr_dist
841 <<
"; min distance = " << min_dist << ::std::endl;
843 if ( curr_dist < min_dist ) {
844 min_dist = curr_dist;
845 ret_val = (itr->second);
846 if ( curr_dist == 0 )
break;
851 if ( debug && ( ret_val != NULL ) ) ::std::cout <<
"CustomDataContainer*::get() ret value " << *ret_val << ::std::endl;
853 if ( ret_val != NULL )
return ret_val->clone();
858 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
861 if (debug && d != NULL) ::std::cout <<
"CustomDataContainer*::insert() &d = " << d <<
"; d = " << *d <<
"; t = " << t <<
"; b = " << b <<
"; r = " << r << ::std::endl;
863 Data* ptr = find( t, b, r );
870 data_map[t][b][r] = d;
875 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
878 if (debug) ::std::cout <<
"CustomDataContainer*::replace() d = " << *d <<
"; t = " << t <<
"; b = " << b <<
"; r = " << r << ::std::endl;
880 Data* ptr = find( t, b, r );
886 data_map[t][b][r] = d;
890 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
892 Data* ptr = find( t, b, r );
893 if ( ptr == NULL )
return;
894 if ( ptr != NULL )
delete ptr;
895 data_map[t][b].erase(r);
896 if ( data_map[t][b].empty() ) data_map[t].erase(b);
897 if ( data_map[t].empty() ) data_map.erase(t);
901 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
903 if ( data_map.empty() )
return;
904 for ( CDCIt it = data_map.begin(); it != data_map.end(); it++ ) {
905 for ( CDCMediumIt it2 = it->second.begin(); it2 != it->second.end(); it2++ ) {
906 for ( CDCInnerIt it3 = it2->second.begin(); it3 != it2->second.end(); it3++ ) {
907 if ( it3->second != NULL )
delete it3->second;
921 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp = ::std::less<T>,
class M
idComp = ::std::less<
double>,
class InComp = ::std::less<
double> >
930 typedef typename ::std::map< time_t, Data >
TimeData;
931 typedef typename TimeData::iterator CDTCTimeIt;
932 typedef typename TimeData::reverse_iterator CDTCTimeRIt;
933 typedef typename TimeData::const_iterator CDTCTimeCIt;
934 typedef typename TimeData::const_reverse_iterator CDTCTimeCRIt;
939 typedef typename ::std::map< double, TimeData, InComp >
InnerData;
940 typedef typename InnerData::iterator CDCInnerIt;
941 typedef typename InnerData::reverse_iterator CDCInnerRIt;
942 typedef typename InnerData::const_iterator CDCInnerCIt;
943 typedef typename InnerData::const_reverse_iterator CDCInnerCRIt;
948 typedef typename ::std::map< double, InnerData, MidComp >
MediumData;
949 typedef typename MediumData::iterator CDCMediumIt;
950 typedef typename MediumData::const_iterator CDCMediumCIt;
951 typedef typename MediumData::reverse_iterator CDCMediumRIt;
952 typedef typename MediumData::const_reverse_iterator CDCMediumCRIt;
958 typedef typename CustomContainer::iterator CDCIt;
959 typedef typename CustomContainer::reverse_iterator CDCRIt;
960 typedef typename CustomContainer::const_iterator CDCCIt;
961 typedef typename CustomContainer::const_reverse_iterator CDCCRIt;
967#if __cplusplus >= 201103L
968 static constexpr double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
970 static constexpr double DB_CDATA_ALL_INNER_KEYS = -10.0;
972 static const double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
974 static const double DB_CDATA_ALL_INNER_KEYS = -10.0;
976 static const T DB_CDATA_ALL_OUTER_KEYS;
978 static const Time DB_CDATA_ALL_TIME_KEYS;
1026 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;
1036 Data
get(
const T& tx,
const T& rx,
const Time& time_key = DB_CDATA_ALL_TIME_KEYS )
const;
1052 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 );
1067 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 );
1081 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);
1119 typedef typename ::std::pair< Data, bool > DataFind;
1134 DataFind
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;
1154 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1158 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1159 const Time CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::DB_CDATA_ALL_TIME_KEYS =
Time(1, 1, 1901, 0, 0, 0);
1162 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1164 if ( data_map.empty() )
return Data();
1166 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() t = " << t <<
"; b = " << b <<
"; r = " << r
1167 <<
"; time_key = " << time_key << ::std::endl;
1169 DataFind ret_val = find();
1170 if ( ret_val.second ==
true )
return ret_val.first;
1172 CDCCIt it = data_map.find( t );
1173 if ( it == data_map.end() )
return Data();
1175 CDCMediumCIt it2 = it->second.lower_bound( b );
1176 CDCMediumCRIt rit2 = it->second.rbegin();
1181 if ( it2 == it->second.end() ) {
1182 if ( rit2 == it->second.rend() )
return Data();
1183 it3 = rit2->second.lower_bound( r );
1184 rit3 = rit2->second.rbegin();
1185 if ( it3 != rit2->second.end() )
return calculateData( it3->second, time_key);
1186 if ( rit3 != rit2->second.rend() )
return calculateData( rit3->second, time_key);
1190 it3 = it2->second.lower_bound( r );
1191 rit3 = it2->second.rbegin();
1192 if ( it3 != it2->second.end() )
return calculateData(it3->second, time_key);
1193 if ( rit3 != it2->second.rend() )
return calculateData(rit3->second, time_key);
1196 if ( it3 == it2->second.end() )
return Data();
1197 return calculateData(it3->second, time_key);
1201 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1203 MidFunctor mid_funct;
1212 double min_dist = INFINITY;
1214 if ( data_map.empty() ==
true ) {
1215 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() data_map is empty " << ::std::endl;
1219 const TimeData* time_data_ptr = NULL;
1221 for ( CDCCIt it = data_map.begin(); it != data_map.end(); it++ ) {
1223 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() start T = " << it->first <<
"; end T = " << rx << ::std::endl;
1225 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
1226 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() overriding start T = " << tx <<
"; end T = " << rx << ::std::endl;
1228 curr_b = mid_funct(tx,rx);
1229 curr_r = in_funct(tx,rx);
1232 curr_b = mid_funct(it->first,rx);
1233 curr_r = in_funct(it->first,rx);
1236 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() curr bearing = " << curr_b * 180.0 / M_PI
1237 <<
"; curr range = " << curr_r << ::std::endl;
1239 CDCMediumCIt itb = it->second.begin();
1240 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS ) delta_b = 0;
1242 itb = it->second.lower_bound( curr_b );
1243 if ( itb == it->second.end() ) itb = (++(it->second.rbegin())).base();
1245 delta_b = curr_b - itb->first;
1246 if (delta_b < 0.0) delta_b = -delta_b;
1247 if (delta_b > M_PI) delta_b = 2.0*M_PI - delta_b ;
1250 double ort_dist = curr_r * sin(delta_b);
1251 double ort_projection = ::std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
1253 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() nearest bearing = " << itb->first * 180.0 / M_PI
1254 <<
"; diff bearing = " << delta_b * 180.0 / M_PI <<
"; orthog distance = " << ort_dist
1255 <<
"; orthog range projection = " << ort_projection << ::std::endl;
1257 CDCInnerCIt itr = itb->second.begin();
1258 if ( itr->first == DB_CDATA_ALL_INNER_KEYS ) curr_dist = ort_dist;
1260 itr = itb->second.lower_bound( ort_projection );
1261 if ( itr == itb->second.begin() || itr == itb->second.end() || itr->first == ort_projection ) {
1262 if ( itr == itb->second.end() ) itr = (++(itb->second.rbegin())).base();
1263 double adj_distance = ::std::abs( ort_projection - itr->first );
1264 curr_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1267 double adj_distance = ::std::abs( ort_projection - itr->first );
1268 double first_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1270 if (debug) ::std::cout <<
"CustomDataTimeContainer::get() first try, range = " << itr->first
1271 <<
"; dist = " << first_dist << ::std::endl;
1274 adj_distance = ::std::abs( ort_projection - itr->first );
1275 double before_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1277 if (debug) ::std::cout <<
"CustomDataTimeContainer::get() second try, range = " << itr->first
1278 <<
"; dist = " << before_dist << ::std::endl;
1280 curr_dist = ::std::min( first_dist, before_dist );
1281 if ( curr_dist == first_dist ) itr++;
1284 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() nearest range = " << itr->first <<
"; distance = " << curr_dist
1285 <<
"; min distance = " << min_dist << ::std::endl;
1287 if ( curr_dist < min_dist ) {
1288 min_dist = curr_dist;
1289 time_data_ptr = &(itr->second);
1290 if ( curr_dist == 0 )
break;
1295 if ( time_data_ptr != NULL )
return calculateData( *time_data_ptr, time_key);
1300 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1301 typename CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::DataFind
CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::find(
const T& t,
double b,
double r,
const Time& time_key )
const {
1303 if (debug) ::std::cout <<
"CustomDataTimeContainer::find() << t = " << t <<
"; b = " << b <<
"; r = "
1304 << r <<
"; time_key = " << time_key << ::std::endl;
1306 CDCCIt it = data_map.find( t );
1307 if ( it == data_map.end() ) {
1309 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() t not found" << ::std::endl;
1311 return DataFind( Data(),
false );
1314 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() t found" << ::std::endl;
1316 CDCMediumCIt it2 = it->second.find( b );
1317 if ( it2 == it->second.end() ) {
1319 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() b not found" << ::std::endl;
1321 return DataFind( Data(),
false );
1324 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() b found" << ::std::endl;
1326 CDCInnerCIt it3 = it2->second.find( r );
1327 if ( it3 == it2->second.end() ) {
1329 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() r not found" << ::std::endl;
1331 return DataFind( Data(),
false );
1333 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() r found" << ::std::endl;
1335 CDTCTimeCIt it4 = it3->second.find( time_key );
1336 if ( it4 == it3->second.end() ) {
1338 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() time_key not found" << ::std::endl;
1340 return DataFind( Data(),
false );
1343 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() time_key found, Data = " << it4->second << ::std::endl;
1345 return DataFind( it4->second,
true );
1349 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1350 bool CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::insert(
const Data& d,
const T& t,
double b,
double r,
const Time& time_key ) {
1351 DataFind data = find( t, b, r, time_key );
1352 if ( data.second ==
true )
return false;
1353 data_map[t][b][r][time_key] = d;
1358 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1359 void CustomDataTimeContainer< T, MidFunctor, InFunctor, Data, OutComp, MidComp, InComp >::replace(
const Data& d,
const T& t,
double b,
double r,
const Time& time_key ) {
1360 data_map[t][b][r][time_key] = d;
1364 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1366 data_map[t][b][r].erase(time_key);
1367 if ( data_map[t][b][r].empty() ) data_map[t][b].erase(r);
1368 if ( data_map[t][b].empty() ) data_map[t].erase(b);
1369 if ( data_map[t].empty() ) data_map.erase(t);
1373 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1378 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1380 if (debug) ::std::cout <<
"CustomDataTimeContainer::calculateData() time_key = " << time_key << ::std::endl;
1382 if ( time_data.empty() ) {
1383 if (debug) ::std::cout <<
"CustomDataTimeContainer::calculateData() time_data is empty." << ::std::endl;
1388 if ( time_data.size() == 1 ) {
1389 if (debug) ::std::cout <<
"CustomDataTimeContainer::calculateData() time_data has size 1. Data created "
1390 << time_data.begin()->second << ::std::endl;
1392 return time_data.begin()->second;
1395 time_t normalized_time = time_key;
1397 if ( normalized_time < time_data.begin()->first ) {
1398 if (debug) ::std::cout <<
"CustomDataTimeContainer::calculateData() time_key has time < first key. Data created "
1399 << time_data.begin()->second << ::std::endl;
1401 return time_data.begin()->second;
1404 normalized_time %= ( time_data.rbegin()->first - time_data.begin()->first );
1405 if ( normalized_time == 0 )
1406 return time_data.begin()->second;
1408 normalized_time += time_data.begin();
1409 CDTCTimeIt upper_it = time_data.upper_bound(normalized_time);
1410 CDTCTimeIt lower_it = upper_it;
1414 return ( lower_it->second * ( (normalized_time - lower_it->first) / ( upper_it->first - lower_it->first ) )
1415 + upper_it->second * ( (upper_it->first - normalized_time) / ( upper_it->first - lower_it->first ) ) );
1426 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1436 typedef typename TimeData::iterator CDTCTimeIt;
1437 typedef typename TimeData::reverse_iterator CDTCTimeRIt;
1438 typedef typename TimeData::const_iterator CDTCTimeCIt;
1439 typedef typename TimeData::const_reverse_iterator CDTCTimeCRIt;
1444 typedef typename ::std::map< double, TimeData, InComp >
InnerData;
1445 typedef typename InnerData::iterator CDCInnerIt;
1446 typedef typename InnerData::reverse_iterator CDCInnerRIt;
1447 typedef typename InnerData::const_iterator CDCInnerCIt;
1448 typedef typename InnerData::const_reverse_iterator CDCInnerCRIt;
1453 typedef typename ::std::map< double, InnerData, MidComp >
MediumData;
1454 typedef typename MediumData::iterator CDCMediumIt;
1455 typedef typename MediumData::const_iterator CDCMediumCIt;
1456 typedef typename MediumData::reverse_iterator CDCMediumRIt;
1457 typedef typename MediumData::const_reverse_iterator CDCMediumCRIt;
1463 typedef typename CustomContainer::iterator CDCIt;
1464 typedef typename CustomContainer::reverse_iterator CDCRIt;
1465 typedef typename CustomContainer::const_iterator CDCCIt;
1466 typedef typename CustomContainer::const_reverse_iterator CDCCRIt;
1472#if __cplusplus >= 201103L
1473 static constexpr double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
1475 static constexpr double DB_CDATA_ALL_INNER_KEYS = -10.0;
1477 static const double DB_CDATA_ALL_MEDIUM_KEYS = -190.0;
1479 static const double DB_CDATA_ALL_INNER_KEYS = -10.0;
1481 static const T DB_CDATA_ALL_OUTER_KEYS;
1483 static const Time DB_CDATA_ALL_TIME_KEYS;
1502 MediumData& operator[] (
const T& key ) {
return data_map[key]; }
1509 bool empty()
const {
return data_map.empty(); }
1516 int size()
const {
return data_map.size(); }
1531 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;
1541 Data* get(
const T& tx,
const T& rx,
const Time& time_key = DB_CDATA_ALL_TIME_KEYS )
const;
1557 bool insert( 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 );
1572 void replace( 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 );
1586 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);
1624 typedef typename ::std::pair< Data*, bool > DataFind;
1639 DataFind 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;
1653 Data* calculateData(
const TimeData& time_data ,
const Time& time_key = DB_CDATA_ALL_TIME_KEYS )
const;
1659 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1663 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1664 const Time CustomDataTimeContainer< T, MidFunctor, InFunctor, Data*, OutComp, MidComp, InComp >::DB_CDATA_ALL_TIME_KEYS =
Time(1, 1, 1901, 0, 0, 0);
1667 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1669 if ( data_map.empty() )
return new Data();
1671 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::get() t = " << t <<
"; b = " << b <<
"; r = " << r
1672 <<
"; time_key = " << time_key << ::std::endl;
1674 DataFind ret_val = find();
1675 if ( ret_val.second ==
true )
return ret_val.first->clone();
1677 CDCCIt it = data_map.find( t );
1678 if ( it == data_map.end() )
return new Data();
1680 CDCMediumCIt it2 = it->second.lower_bound( b );
1681 CDCMediumCRIt rit2 = it->second.rbegin();
1686 if ( it2 == it->second.end() ) {
1687 if ( rit2 == it->second.rend() )
return new Data();
1688 it3 = rit2->second.lower_bound( r );
1689 rit3 = rit2->second.rbegin();
1690 if ( it3 != rit2->second.end() )
return calculateData(it3->second, time_key);
1691 if ( rit3 != rit2->second.rend() )
return calculateData(rit3->second, time_key);
1695 it3 = it2->second.lower_bound( r );
1696 rit3 = it2->second.rbegin();
1697 if ( it3 != it2->second.end() )
return calculateData(it3->second, time_key);
1698 if ( rit3 != it2->second.rend() )
return calculateData(rit3->second, time_key);
1701 if ( it3 == it2->second.end() )
return new Data();
1702 return calculateData(it3->second, time_key);
1706 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1708 MidFunctor mid_funct;
1717 double min_dist = INFINITY;
1719 if ( data_map.empty() ==
true ) {
1720 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() data_map is empty " << ::std::endl;
1724 const TimeData* time_data_ptr = NULL;
1726 for ( CDCCIt it = data_map.begin(); it != data_map.end(); it++ ) {
1728 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() start T = " << it->first <<
"; end T = " << rx << ::std::endl;
1730 if ( it->first == DB_CDATA_ALL_OUTER_KEYS ) {
1731 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() overriding start T = " << tx <<
"; end T = " << rx << ::std::endl;
1733 curr_b = mid_funct(tx,rx);
1734 curr_r = in_funct(tx,rx);
1737 curr_b = mid_funct(it->first,rx);
1738 curr_r = in_funct(it->first,rx);
1741 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() curr bearing = " << curr_b * 180.0 / M_PI
1742 <<
"; curr range = " << curr_r << ::std::endl;
1744 CDCMediumCIt itb = it->second.begin();
1745 if ( itb->first == DB_CDATA_ALL_MEDIUM_KEYS ) delta_b = 0;
1747 itb = it->second.lower_bound( curr_b );
1748 if ( itb == it->second.end() ) itb = (++(it->second.rbegin())).base();
1750 delta_b = curr_b - itb->first;
1751 if (delta_b < 0.0) delta_b = -delta_b;
1752 if (delta_b > M_PI) delta_b = 2.0*M_PI - delta_b ;
1755 double ort_dist = curr_r * sin(delta_b);
1756 double ort_projection = ::std::sqrt( curr_r*curr_r - ort_dist*ort_dist );
1758 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() nearest bearing = " << itb->first * 180.0 / M_PI
1759 <<
"; diff bearing = " << delta_b * 180.0 / M_PI <<
"; orthog distance = " << ort_dist
1760 <<
"; orthog range projection = " << ort_projection << ::std::endl;
1762 CDCInnerCIt itr = itb->second.begin();
1763 if ( itr->first == DB_CDATA_ALL_INNER_KEYS ) curr_dist = ort_dist;
1765 itr = itb->second.lower_bound( ort_projection );
1766 if ( itr == itb->second.begin() || itr == itb->second.end() || itr->first == ort_projection ) {
1767 if ( itr == itb->second.end() ) itr = (++(itb->second.rbegin())).base();
1768 double adj_distance = ::std::abs( ort_projection - itr->first );
1769 curr_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1772 double adj_distance = ::std::abs( ort_projection - itr->first );
1773 double first_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1775 if (debug) ::std::cout <<
"CustomDataTimeContainer::get() first try, range = " << itr->first
1776 <<
"; dist = " << first_dist << ::std::endl;
1779 adj_distance = ::std::abs( ort_projection - itr->first );
1780 double before_dist = ::std::sqrt( ort_projection*ort_projection + adj_distance*adj_distance );
1782 if (debug) ::std::cout <<
"CustomDataTimeContainer::get() second try, range = " << itr->first
1783 <<
"; dist = " << before_dist << ::std::endl;
1785 curr_dist = ::std::min( first_dist, before_dist );
1786 if ( curr_dist == first_dist ) itr++;
1789 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::get() nearest range = " << itr->first <<
"; distance = " << curr_dist
1790 <<
"; min distance = " << min_dist << ::std::endl;
1792 if ( curr_dist < min_dist ) {
1793 min_dist = curr_dist;
1794 time_data_ptr = &(itr->second);
1795 if ( curr_dist == 0 )
break;
1800 if ( time_data_ptr != NULL )
return calculateData( *time_data_ptr, time_key);
1805 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1806 typename CustomDataTimeContainer< T, MidFunctor, InFunctor, Data*, OutComp, MidComp, InComp >::DataFind
CustomDataTimeContainer< T, MidFunctor, InFunctor, Data*, OutComp, MidComp, InComp >::find(
const T& t,
double b,
double r,
const Time& time_key )
const {
1808 if (debug) ::std::cout <<
"CustomDataTimeContainer*::find() << t = " << t <<
"; b = " << b <<
"; r = "
1809 << r <<
"; time_key = " << time_key << ::std::endl;
1811 CDCCIt it = data_map.find( t );
1812 if ( it == data_map.end() ) {
1814 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() t not found" << ::std::endl;
1816 return DataFind( NULL,
false );
1819 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() t found" << ::std::endl;
1821 CDCMediumCIt it2 = it->second.find( b );
1822 if ( it2 == it->second.end() ) {
1824 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() b not found" << ::std::endl;
1826 return DataFind( NULL,
false );
1829 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() b found" << ::std::endl;
1831 CDCInnerCIt it3 = it2->second.find( r );
1832 if ( it3 == it2->second.end() ) {
1834 if ( debug ) ::std::cout <<
"CustomDataTimeContainer::find() r not found" << ::std::endl;
1836 return DataFind( NULL,
false );
1838 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() r found" << ::std::endl;
1840 CDTCTimeCIt it4 = it3->second.find( time_key );
1841 if ( it4 == it3->second.end() ) {
1843 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() time_key not found" << ::std::endl;
1845 return DataFind( NULL,
false );
1848 if ( debug ) ::std::cout <<
"CustomDataTimeContainer*::find() time_key found, Data = " << it4->second << ::std::endl;
1850 return DataFind( it4->second,
true );
1854 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1855 bool CustomDataTimeContainer< T, MidFunctor, InFunctor, Data*, OutComp, MidComp, InComp >::insert( Data* d,
const T& t,
double b,
double r,
const Time& time_key ) {
1856 DataFind data = find( t, b, r, time_key );
1857 if ( data.second ==
true )
return false;
1858 data_map[t][b][r][time_key] = d;
1863 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1864 void CustomDataTimeContainer< T, MidFunctor, InFunctor, Data*, OutComp, MidComp, InComp >::replace( Data* d,
const T& t,
double b,
double r,
const Time& time_key ) {
1866 if (debug) ::std::cout <<
"CustomDataTimeContainer*::replace() d = " << *d <<
"; t = " << t <<
"; b = " << b <<
"; r = " << r <<
"; time_key " << time_key << ::std::endl;
1868 DataFind ptr = find( t, b, r, time_key );
1870 if ( ptr.first != NULL ) {
1875 data_map[t][b][r][time_key] = d;
1879 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1881 DataFind ptr = find( t, b, r, time_key );
1882 if ( ptr.first == NULL )
return;
1883 if ( ptr.first != NULL )
delete ptr.first;
1885 data_map[t][b][r].erase(time_key);
1886 if ( data_map[t][b][r].empty() ) data_map[t][b].erase(r);
1887 if ( data_map[t][b].empty() ) data_map[t].erase(b);
1888 if ( data_map[t].empty() ) data_map.erase(t);
1892 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1894 if ( data_map.empty() )
return;
1895 for ( CDCIt it = data_map.begin(); it != data_map.end(); it++ ) {
1896 for ( CDCMediumIt it2 = it->second.begin(); it2 != it->second.end(); it2++ ) {
1897 for ( CDCInnerIt it3 = it2->second.begin(); it3 != it2->second.end(); it3++ ) {
1898 for ( CDTCTimeCIt it4 = it3->second.begin(); it4 != it3->second.end(); it4++) {
1899 if ( it4->second != NULL )
delete it4->second;
1908 template <
class T,
class M
idFunctor,
class InFunctor,
class Data,
class OutComp,
class M
idComp,
class InComp >
1910 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() time_key = "
1911 << time_key <<
"; time_key in time_t = " << (time_t)time_key
1912 <<
"; time_data size = " << time_data.size()
1913 <<
"; time data min value = " << time_data.begin()->first
1914 <<
"; time_data max value = " << time_data.rbegin()->first << ::std::endl;
1916 if ( time_data.empty() ) {
1917 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() time_data is empty." << ::std::endl;
1922 if ( time_data.size() == 1 ) {
1923 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() time_data has size 1. Data cloned from "
1924 << time_data.begin()->second <<
"; ret value " << *(time_data.begin()->second) << ::std::endl;
1926 return (time_data.begin()->second)->clone();
1929 CDTCTimeCIt fit = time_data.find(time_key);
1930 if ( fit != time_data.end() ) {
1931 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() time key found, ret value "
1932 << *(fit->second) << ::std::endl;
1934 return fit->second->clone();
1937 time_t normalized_time = time_key;
1939 CDTCTimeCIt upper_it;
1940 CDTCTimeCIt lower_it;
1943 if ( (normalized_time > time_data.rbegin()->first) || (normalized_time < time_data.begin()->first) ) {
1944 normalized_time %= time_data.rbegin()->first - time_data.begin()->first;
1946 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() time out of bound, normalized on time = "
1947 << (time_data.rbegin()->first - time_data.begin()->first) <<
"; normalized_time = "
1948 << normalized_time <<
"; final time = " << (time_data.begin()->first + normalized_time )
1951 normalized_time += time_data.begin()->first;
1954 upper_it = time_data.upper_bound(normalized_time);
1956 if ( upper_it == time_data.begin() ) {
1957 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() normalized_time = " << normalized_time
1958 <<
"; upper_it time is first in time data = " << upper_it->first
1959 <<
"; ret value = " << *(upper_it->second) << ::std::endl;
1961 return (upper_it->second)->clone();
1963 lower_it = upper_it;
1966 alpha = ( ::std::abs((
double)(upper_it->first - normalized_time)) / ::std::abs((
double)( upper_it->first - lower_it->first )) );
1967 beta = ( ::std::abs((
double)(normalized_time - lower_it->first)) / ::std::abs((
double)( upper_it->first - lower_it->first )) );
1969 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() normalized_time = " << normalized_time
1970 <<
"; lower_it time = " << lower_it->first
1971 <<
"; upper_it time = " << upper_it->first
1972 <<
"; alpha = " << alpha <<
"; beta " << beta << ::std::endl;
1974 Data* ret_val = (lower_it->second)->clone();
1976 *ret_val = (*ret_val) * alpha + (*(upper_it->second)) * beta;
1978 if (debug) ::std::cout <<
"CustomDataTimeContainer*::calculateData() return value = "
1979 << *ret_val << ::std::endl;
Class for managing custom db data.
Definition woss-db-custom-data-container.h:60
MediumData & operator[](const T &key)
Definition woss-db-custom-data-container.h:125
const 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:400
int size() const
Definition woss-db-custom-data-container.h:139
CustomDataContainer()
Definition woss-db-custom-data-container.h:112
bool usingDebug()
Definition woss-db-custom-data-container.h:223
::std::map< double, InnerData, MidComp > MediumData
Definition woss-db-custom-data-container.h:78
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:437
const Data * get(const T &tx, const T &rx) const
Definition woss-db-custom-data-container.h:300
::std::map< double, Data, InComp > InnerData
Definition woss-db-custom-data-container.h:69
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:519
bool debug
Definition woss-db-custom-data-container.h:232
::std::map< T, MediumData, OutComp > CustomContainer
Definition woss-db-custom-data-container.h:87
bool empty() const
Definition woss-db-custom-data-container.h:132
~CustomDataContainer()
Definition woss-db-custom-data-container.h:117
void setDebug(bool flag)
Definition woss-db-custom-data-container.h:216
void clear()
Definition woss-db-custom-data-container.h:533
CustomContainer data_map
Definition woss-db-custom-data-container.h:238
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:525
const 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:262
::std::map< double, InnerData, MidComp > MediumData
Definition woss-db-custom-data-container.h:1453
bool empty() const
Definition woss-db-custom-data-container.h:1509
CustomDataTimeContainer()
Definition woss-db-custom-data-container.h:1489
void setDebug(bool flag)
Definition woss-db-custom-data-container.h:1599
bool debug
Definition woss-db-custom-data-container.h:1615
CustomContainer data_map
Definition woss-db-custom-data-container.h:1621
::std::map< double, TimeData, InComp > InnerData
Definition woss-db-custom-data-container.h:1444
bool usingDebug()
Definition woss-db-custom-data-container.h:1606
::std::map< time_t, Data * > TimeData
Definition woss-db-custom-data-container.h:1435
int size() const
Definition woss-db-custom-data-container.h:1516
::std::map< T, MediumData, OutComp > CustomContainer
Definition woss-db-custom-data-container.h:1462
~CustomDataTimeContainer()
Definition woss-db-custom-data-container.h:1494
Class for managing custom db data.
Definition woss-db-custom-data-container.h:922
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:1350
bool empty() const
Definition woss-db-custom-data-container.h:1004
DataFind 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:1301
::std::map< time_t, Data > TimeData
Definition woss-db-custom-data-container.h:930
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:1163
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:1365
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:1202
MediumData & operator[](const T &key)
Definition woss-db-custom-data-container.h:997
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:1359
::std::map< double, InnerData, MidComp > MediumData
Definition woss-db-custom-data-container.h:948
::std::map< T, MediumData, OutComp > CustomContainer
Definition woss-db-custom-data-container.h:957
bool usingDebug()
Definition woss-db-custom-data-container.h:1101
bool debug
Definition woss-db-custom-data-container.h:1110
CustomContainer data_map
Definition woss-db-custom-data-container.h:1116
int size() const
Definition woss-db-custom-data-container.h:1011
CustomDataTimeContainer()
Definition woss-db-custom-data-container.h:984
void clear()
Definition woss-db-custom-data-container.h:1374
~CustomDataTimeContainer()
Definition woss-db-custom-data-container.h:989
void setDebug(bool flag)
Definition woss-db-custom-data-container.h:1094
::std::map< double, TimeData, InComp > InnerData
Definition woss-db-custom-data-container.h:939
Data calculateData(const TimeData &time_data, const Time &time_key=DB_CDATA_ALL_TIME_KEYS) const
Definition woss-db-custom-data-container.h:1379
a class for time date manipulation
Definition time-definitions.h:95
Definitions and library for woss::Time, woss::SimTime, woss::TimeReference and woss::TimeReferenceTcl...