World Ocean Simulation System (WOSS) library
woss-creator-container.h
Go to the documentation of this file.
1/* WOSS - World Ocean Simulation System -
2 *
3 * Copyright (C) 2009 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - federico@guerra-tlc.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/*
23 * This software has been developed by Federico Guerra and SIGNET lab,
24 * University of Padova, in collaboration with the NATO Centre for
25 * Maritime Research and Experimentation (http://www.cmre.nato.int ;
26 * E-mail: pao@cmre.nato.int), whose support is gratefully acknowledged.
27 */
28
29
40#ifndef WOSS_CREATOR_CONTAINER_DEFINITIONS_H
41#define WOSS_CREATOR_CONTAINER_DEFINITIONS_H
42
43
44#include <map>
46#include <iostream>
47
48
49namespace woss {
50
58
59
67 CustomTransducer( const ::std::string& name = "", double bearing = 0.0, double vert_rot = 0.0, double horiz_rot = 0.0, double mult = 1.0, double add = 0.0 )
68 : type(name), initial_bearing(bearing), initial_vert_rotation(vert_rot), initial_horiz_rotation(horiz_rot), multiply_costant(mult), add_costant(add) { }
69
70
71 friend std::ostream& operator<<( std::ostream& os, const CustomTransducer& instance ) {
72 os << "type name = " << instance.type <<"; initial bearing = " << instance.initial_bearing
73 << "; initial vertical rotation = " << instance.initial_vert_rotation
74 << "; initial horizontal rotation = " << instance.initial_horiz_rotation
75 << "; mult costant = " << instance.multiply_costant << "; add costant = "
76 << instance.add_costant;
77 return os;
78 }
79
80
84 ::std::string type;
85
86
91
96
101
106
111
112
113 };
114
115
116
123 template< typename Data >
125
126
127 public:
128
129
133 static Location* const ALL_LOCATIONS;
134
138 static const CoordZ ALL_COORDZ;
139
140
145
150
151
156 bool isEmpty() const;
157
162 int size() const;
163
164
172 bool insert( const Data& data, Location* const tx, Location* const rx );
173
181 bool insert( const Data& data, const CoordZ& tx, const CoordZ& rx );
182
183
190 Data get( Location* const tx, Location* const rx ) const;
191
198 Data get( const CoordZ& tx, const CoordZ& rx ) const;
199
206
207
213 void erase( Location* const tx, Location* const rx );
214
220 void erase( const CoordZ& tx, const CoordZ& rx );
221
222
230 void replace( const Data& data, Location* const tx, Location* const rx );
231
239 void replace( const Data& data, const CoordZ& tx, const CoordZ& rx );
240
241
245 void clear();
246
247
252 void setDebug( bool flag ) { debug = flag; }
253
258 bool isUsingDebug() const { return debug; }
259
260
261 protected:
262
263
267 typedef ::std::map< Location*, Data > InnerContainer;
268 typedef typename InnerContainer::iterator ICIter;
269 typedef typename InnerContainer::reverse_iterator ICRIter;
270 typedef typename InnerContainer::const_iterator ICCIter;
271 typedef typename InnerContainer::const_reverse_iterator ICCRIter;
272
273
277 typedef ::std::map< Location*, InnerContainer > DataContainer;
278 typedef typename DataContainer::iterator DCIter;
279 typedef typename DataContainer::const_iterator DCCIter;
280 typedef typename DataContainer::reverse_iterator DCRIter;
281 typedef typename DataContainer::const_reverse_iterator DCRCIter;
282
283
290 DCIter find( const CoordZ& coordinates );
291
299 ICIter find( const CoordZ& coordinates, const DCIter& iter );
300
301
307 Location* createLocation( const CoordZ& coordinates );
308
309
314
315
319 bool debug;
320
321
322 };
323
324
325 template< typename Data >
327
328 template< typename Data >
330
331
332 template< typename Data >
334 : data_container(),
335 debug(false)
336 {
337 }
338
339
340 template< typename Data >
342 clear();
343 }
344
345
346 template< typename Data >
348 return data_container.empty();
349 }
350
351
352 template< typename Data >
354 return data_container.size();
355 }
356
357
358 template< typename Data >
360 if ( coordinates == ALL_COORDZ ) return NULL;
361 return new Location( coordinates );
362 }
363
364
365 template< typename Data >
366 typename WossCreatorContainer< Data >::DCIter WossCreatorContainer< Data >::find( const CoordZ& coordinates ) {
367 DCIter it_all_loc = data_container.end();
368
369 for ( DCIter it = data_container.begin(); it != data_container.end(); it++ ) {
370 if ( it->first == ALL_LOCATIONS ) {
371 it_all_loc = it;
372 if ( coordinates == ALL_COORDZ ) break;
373 else continue;
374 }
375 if ( it->first->isEquivalentTo( coordinates ) ) {
376 if (debug) ::std::cout << "WossCreatorContainer::find() tx coordinates found = "
377 << coordinates << ::std::endl;
378 return it;
379 }
380 }
381
382 if ( coordinates == ALL_COORDZ && it_all_loc != data_container.end() ) {
383 if (debug) ::std::cout << "WossCreatorContainer::find() tx ALL_COORDZ found" << ::std::endl;
384 return it_all_loc;
385 }
386
387 if (debug && coordinates != ALL_COORDZ ) ::std::cout << "WossCreatorContainer::find() tx coordinates not found = "
388 << coordinates << ::std::endl;
389
390 if (debug && coordinates == ALL_COORDZ ) ::std::cout << "WossCreatorContainer::find() tx ALL_COORDZ not found" << ::std::endl;
391 return data_container.end();
392 }
393
394
395 template< typename Data >
396 typename WossCreatorContainer< Data >::ICIter WossCreatorContainer< Data >::find( const CoordZ& coordinates, const DCIter& iter ) {
397 ICIter it_all_loc = iter->second.end();
398
399 for ( ICIter it = iter->second.begin(); it != iter->second.end(); it++ ) {
400 if ( it->first == ALL_LOCATIONS ) {
401 it_all_loc = it;
402 if ( coordinates == ALL_COORDZ ) break;
403 else continue;
404 }
405 if ( it->first->isEquivalentTo( coordinates ) ) {
406 if (debug) ::std::cout << "WossCreatorContainer::find() rx coordinates found = "
407 << coordinates << ::std::endl;
408 return it;
409 }
410 }
411
412 if ( coordinates == ALL_COORDZ && it_all_loc != iter->second.end() ) {
413 if (debug) ::std::cout << "WossCreatorContainer::find() rx ALL_COORDZ found" << ::std::endl;
414 return it_all_loc;
415 }
416
417 if (debug && coordinates != ALL_COORDZ ) ::std::cout << "WossCreatorContainer::find() rx coordinates not found = "
418 << coordinates << ::std::endl;
419
420 if (debug && coordinates == ALL_COORDZ ) ::std::cout << "WossCreatorContainer::find() rx ALL_COORDZ not found" << ::std::endl;
421 return iter->second.end();
422 }
423
424
425 template< typename Data >
426 inline bool WossCreatorContainer< Data >::insert( const Data& data, Location* const tx, Location* const rx ) {
427 DCIter it = data_container.find(tx);
428 if ( it == data_container.end() ) {
429 data_container[tx][rx] = data;
430 return true;
431 }
432 ICIter it2 = it->second.find(rx);
433 if ( it2 == it->second.end() ) {
434 (it->second)[rx] = data;
435 return true;
436 }
437 return false;
438 }
439
440
441 template< typename Data >
442 inline bool WossCreatorContainer< Data >::insert( const Data& data, const CoordZ& tx, const CoordZ& rx ) {
443 DCIter it = find( tx );
444 if ( it == data_container.end() ) {
445 data_container[ createLocation(tx) ][ createLocation(rx) ] = data;
446 return true;
447 }
448 ICIter it2 = find( rx, it );
449 if ( it2 == it->second.end() ) {
450 (it->second)[ createLocation(rx) ] = data;
451 return true;
452 }
453 return false;
454 }
455
456
457 template< typename Data >
458 inline Data WossCreatorContainer< Data >::get( Location* const tx, Location* const rx ) const {
459 DCIter it = const_cast< typename WossCreatorContainer< Data >::DataContainer& >(data_container).find( tx );
460
461 if ( tx != ALL_LOCATIONS ) {
462 if ( it == data_container.end() ) {
463 if ( debug ) ::std::cout << "WossCreatorContainer::get() no tx location found = " << *tx
464 << "; trying ALL_LOCATIONS"<< ::std::endl;
465
466 it = const_cast< typename WossCreatorContainer< Data >::DataContainer& >(data_container).find( ALL_LOCATIONS );
467 }
468
469 if ( debug ) ::std::cout << "WossCreatorContainer::get() tx location found = " << *tx << ::std::endl;
470
471 }
472
473 if ( it != data_container.end() ) {
474 ICIter it2 = it->second.find( rx );
475
476 if ( rx != ALL_LOCATIONS ) {
477
478 if ( it2 == it->second.end() ) {
479 if ( debug ) ::std::cout << "WossCreatorContainer::get() no rx location found = " << *rx
480 << "; trying ALL_LOCATIONS"<< ::std::endl;
481
482 it2 = it->second.find( ALL_LOCATIONS );
483 }
484
485 if ( debug ) ::std::cout << "WossCreatorContainer::get() rx location found = " << *rx << ::std::endl;
486
487 }
488
489 if ( it2 != it->second.end() ) return it2->second;
490 }
491
492 ::std::cerr << "WARNING: WossCreatorContainer::get() no tx nor rx location found, returning default constructor!!" << ::std::endl;
493
494 return Data();
495 }
496
497
498 template< typename Data >
500 return data_container[ALL_LOCATIONS][ALL_LOCATIONS];
501 }
502
503
504 template< typename Data >
505 inline Data WossCreatorContainer< Data >::get( const CoordZ& tx, const CoordZ& rx ) const {
506 DCIter it = const_cast< WossCreatorContainer< Data >& >(*this).find( tx );
507
508 if ( tx != ALL_COORDZ ) {
509 if ( it == data_container.end() ) it = const_cast< WossCreatorContainer< Data >& >(*this).find( ALL_COORDZ );
510 }
511
512 if ( it != data_container.end() ) {
513 ICIter it2 = const_cast< WossCreatorContainer< Data >& >(*this).find( rx, it );
514
515 if ( rx != ALL_COORDZ ) {
516 if ( it2 == it->second.end() ) it2 = const_cast< WossCreatorContainer< Data >& >(*this).find( ALL_COORDZ, it );
517 }
518
519 if ( it2 != it->second.end() ) {
520 if ( debug ) ::std::cout << "WossCreatorContainer::get() value found = " << it2->second << ::std::endl;
521
522 return it2->second;
523 }
524 }
525 ::std::cerr << "WARNING: WossCreatorContainer::get() no tx nor rx coordinates found, returning default constructor!!" << ::std::endl;
526
527 return Data();
528 }
529
530
531 template< typename Data >
532 inline void WossCreatorContainer< Data >::erase( Location* const tx, Location* const rx ) {
533 DCIter it = data_container.find(tx);
534 if ( it != data_container.end() ) it->second.erase( rx );
535 if ( it->second.empty() ) data_container.erase(it);
536 }
537
538
539 template< typename Data >
540 inline void WossCreatorContainer< Data >::erase( const CoordZ& tx, const CoordZ& rx ) {
541 for ( DCIter it = data_container.begin(); it != data_container.end(); ) {
542
543 if ( it->first->isEquivalentTo( tx ) ) {
544
545 for ( ICIter it2 = it->second.begin(); it2 != it->second.end(); ) {
546 if ( it2->first->isEquivalentTo( rx ) ) it->second.erase(it2++);
547 else ++it2;
548 }
549
550 }
551
552 if ( it->second.empty() ) data_container.erase(it++);
553 else ++it;
554 }
555 }
556
557
558 template< typename Data >
559 inline void WossCreatorContainer< Data >::replace( const Data& data, Location* const tx, Location* const rx ) {
560 data_container[tx][rx] = data;
561 }
562
563
564 template< typename Data >
565 inline void WossCreatorContainer< Data >::replace( const Data& data, const CoordZ& tx, const CoordZ& rx ) {
566 data_container[ createLocation(tx) ][ createLocation(rx) ] = data;
567 }
568
569
570 template< typename Data >
572// for( DCIter it = data_container.begin(); it != data_container.end(); it++ ) {
573
574// for( ICIter it2 = it->second.begin(); it2 != it->second.end(); it2++ ) {
575//
576// }
577
578// it->second.clear();
579// }
580 data_container.clear();
581 }
582
583
585
592 template< typename Data >
593 class WossCreatorContainer< Data* > {
594
595
596 public:
597
598
599 static Location* const ALL_LOCATIONS;
600
601 static const CoordZ ALL_COORDZ;
602
603
605
607
608
609 bool isEmpty() const;
610
611 int size() const;
612
613
622 bool insert( Data* data, Location* const tx, Location* const rx );
623
632 bool insert( Data* data, const CoordZ& tx, const CoordZ& rx );
633
634
641 Data* get( Location* const tx, Location* const rx ) const;
642
649 Data* get( const CoordZ& tx, const CoordZ& rx ) const;
650
651
658 Data*& accessAllLocations();
659
660
661 void erase( Location* const tx, Location* const rx );
662
663 void erase( const CoordZ& tx, const CoordZ& rx );
664
665
673 void replace( Data* const data, Location* const tx, Location* const rx );
674
682 void replace( Data* const data, const CoordZ& tx, const CoordZ& rx );
683
684
685 void clear();
686
687
688 void setDebug( bool flag ) { debug = flag; }
689
690 bool isUsingDebug() const { return debug; }
691
692
693 protected:
694
695
696 typedef ::std::map< Location*, Data* > InnerContainer;
697 typedef typename InnerContainer::iterator ICIter;
698 typedef typename InnerContainer::reverse_iterator ICRIter;
699 typedef typename InnerContainer::const_iterator ICCIter;
700 typedef typename InnerContainer::const_reverse_iterator ICCRIter;
701
702
703 typedef ::std::map< Location*, InnerContainer > DataContainer;
704
705 typedef typename DataContainer::iterator DCIter;
706 typedef typename DataContainer::const_iterator DCCIter;
707 typedef typename DataContainer::reverse_iterator DCRIter;
708 typedef typename DataContainer::const_reverse_iterator DCRCIter;
709
710
711 DCIter find( const CoordZ& coordinates );
712
713 ICIter find( const CoordZ& coordinates, const DCIter& iter );
714
715
716 Location* createLocation( const CoordZ& coordinates );
717
718
719 DataContainer data_container;
720
721
722 bool debug;
723
724
725 };
726
727
728 template< typename Data >
730
731 template< typename Data >
733
734
735 template< typename Data >
737 : data_container(),
738 debug(false)
739 {
740 }
741
742
743 template< typename Data >
745 clear();
746 }
747
748
749 template< typename Data >
750 inline bool WossCreatorContainer< Data* >::isEmpty() const {
751 return data_container.empty();
752 }
753
754
755 template< typename Data >
756 inline int WossCreatorContainer< Data* >::size() const {
757 return data_container.size();
758 }
759
760
761 template< typename Data >
762 inline Location* WossCreatorContainer< Data* >::createLocation( const CoordZ& coordinates ) {
763 if ( coordinates == ALL_COORDZ ) return NULL;
764 return new Location( coordinates );
765 }
766
767
768 template< typename Data >
769 typename WossCreatorContainer< Data* >::DCIter WossCreatorContainer< Data* >::find( const CoordZ& coordinates ) {
770 DCIter it_all_loc = data_container.end();
771
772 for ( DCIter it = data_container.begin(); it != data_container.end(); it++ ) {
773 if ( it->first == ALL_LOCATIONS ) {
774 it_all_loc = it;
775 if ( coordinates == ALL_COORDZ ) break;
776 else continue;
777 }
778 if ( it->first->isEquivalentTo( coordinates ) ) {
779 if (debug) ::std::cout << "WossCreatorContainer*::find() tx coordinates found = "
780 << coordinates << ::std::endl;
781 return it;
782 }
783 }
784
785 if ( coordinates == ALL_COORDZ && it_all_loc != data_container.end() ) {
786 if (debug) ::std::cout << "WossCreatorContainer*::find() tx ALL_COORDZ found" << ::std::endl;
787 return it_all_loc;
788 }
789
790 if (debug && coordinates != ALL_COORDZ ) ::std::cout << "WossCreatorContainer*::find() tx coordinates not found = "
791 << coordinates << ::std::endl;
792
793 if (debug && coordinates == ALL_COORDZ ) ::std::cout << "WossCreatorContainer*::find() tx ALL_COORDZ not found" << ::std::endl;
794 return data_container.end();
795 }
796
797
798 template< typename Data >
799 typename WossCreatorContainer< Data* >::ICIter WossCreatorContainer< Data* >::find( const CoordZ& coordinates, const DCIter& iter ) {
800 ICIter it_all_loc = iter->second.end();
801
802 for ( ICIter it = iter->second.begin(); it != iter->second.end(); it++ ) {
803 if ( it->first == ALL_LOCATIONS ) {
804 it_all_loc = it;
805 if ( coordinates == ALL_COORDZ ) break;
806 else continue;
807 }
808 if ( it->first->isEquivalentTo( coordinates ) ) {
809 if (debug) ::std::cout << "WossCreatorContainer*::find() rx coordinates found = "
810 << coordinates << ::std::endl;
811 return it;
812 }
813 }
814
815 if ( coordinates == ALL_COORDZ && it_all_loc != iter->second.end() ) {
816 if (debug) ::std::cout << "WossCreatorContainer*::find() rx ALL_COORDZ found" << ::std::endl;
817 return it_all_loc;
818 }
819
820 if (debug && coordinates != ALL_COORDZ ) ::std::cout << "WossCreatorContainer*::find() rx coordinates not found = "
821 << coordinates << ::std::endl;
822
823 if (debug && coordinates == ALL_COORDZ ) ::std::cout << "WossCreatorContainer*::find() rx ALL_COORDZ not found" << ::std::endl;
824 return iter->second.end();
825 }
826
827
828 template< typename Data >
829 inline bool WossCreatorContainer< Data* >::insert( Data* data, Location* const tx, Location* const rx ) {
830 DCIter it = data_container.find(tx);
831 if ( it == data_container.end() ) {
832 data_container[tx][rx] = data;
833 return true;
834 }
835 ICIter it2 = it->second.find(rx);
836 if ( it2 == it->second.end() ) {
837 (it->second)[rx] = data;
838 return true;
839 }
840
841 delete data;
842 data = NULL;
843 return false;
844 }
845
846
847 template< typename Data >
848 inline bool WossCreatorContainer< Data* >::insert( Data* data, const CoordZ& tx, const CoordZ& rx ) {
849 DCIter it = find( tx );
850 if ( it == data_container.end() ) {
851 data_container[ createLocation(tx) ][ createLocation(rx) ] = data;
852 return true;
853 }
854 ICIter it2 = find( rx, it );
855 if ( it2 == it->second.end() ) {
856 (it->second)[ createLocation(rx) ] = data;
857 return true;
858 }
859
860 delete data;
861 data = NULL;
862 return false;
863 }
864
865
866 template< typename Data >
867 inline Data* WossCreatorContainer< Data* >::get( Location* const tx, Location* const rx ) const {
868 DCIter it = const_cast< typename WossCreatorContainer< Data* >::DataContainer& >(data_container).find( tx );
869
870 if ( tx != ALL_LOCATIONS ) {
871 if ( it == data_container.end() ) {
872 if ( debug ) ::std::cout << "WossCreatorContainer*::get() no tx location found = " << *tx
873 << "; trying ALL_LOCATIONS"<< ::std::endl;
874
875 it = const_cast< typename WossCreatorContainer< Data* >::DataContainer& >(data_container).find( ALL_LOCATIONS );
876 }
877
878 if ( debug ) ::std::cout << "WossCreatorContainer*::get() tx location found = " << *tx << ::std::endl;
879
880 }
881
882 if ( it != data_container.end() ) {
883 ICIter it2 = it->second.find( rx );
884
885 if ( rx != ALL_LOCATIONS ) {
886
887 if ( it2 == it->second.end() ) {
888 if ( debug ) ::std::cout << "WossCreatorContainer*::get() no rx location found = " << *rx
889 << "; trying ALL_LOCATIONS"<< ::std::endl;
890
891 it2 = it->second.find( ALL_LOCATIONS );
892 }
893
894 if ( debug ) ::std::cout << "WossCreatorContainer*::get() rx location found = " << *rx << ::std::endl;
895 }
896
897 if ( it2 != it->second.end() ) return it2->second->clone();
898 }
899
900 if ( debug ) ::std::cerr << "WARNING: WossCreatorContainer*::get() no tx nor rx location found, returning default constructor!!" << ::std::endl;
901
902 return new Data();
903 }
904
905
906 template< typename Data >
908 return data_container[ALL_LOCATIONS][ALL_LOCATIONS];
909 }
910
911
912 template< typename Data >
913 inline Data* WossCreatorContainer< Data* >::get( const CoordZ& tx, const CoordZ& rx ) const {
914 DCIter it = const_cast< WossCreatorContainer< Data* >& >(*this).find( tx );
915
916 if ( tx != ALL_COORDZ ) {
917 if ( it == data_container.end() ) it = const_cast< WossCreatorContainer< Data* >& >(*this).find( ALL_COORDZ );
918 }
919
920 if ( it != data_container.end() ) {
921 ICIter it2 = const_cast< WossCreatorContainer< Data* >& >(*this).find( rx, it );
922
923 if ( rx != ALL_COORDZ ) {
924 if ( it2 == it->second.end() ) it2 = const_cast< WossCreatorContainer< Data* >& >(*this).find( ALL_COORDZ, it );
925 }
926
927 if ( it2 != it->second.end() ) return it2->second->clone();
928 }
929 if ( debug ) ::std::cerr << "WARNING: WossCreatorContainer*::get() no tx nor rx coordinates found, returning default constructor!!" << ::std::endl;
930
931 return new Data();
932 }
933
934
935 template< typename Data >
936 inline void WossCreatorContainer< Data* >::erase( Location* const tx, Location* const rx ) {
937 DCIter it = data_container.find(tx);
938 if ( it != data_container.end() ) {
939
940 ICIter it2 = it->second.find( rx );
941
942 if ( it2 != it->second.end() ) {
943 delete it2->second;
944// delete it2->first;
945 it->second.erase( it2 );
946 }
947
948 }
949 if ( it->second.empty() ) {
950// delete it->first;
951 data_container.erase(it);
952 }
953 }
954
955
956 template< typename Data >
957 inline void WossCreatorContainer< Data* >::erase( const CoordZ& tx, const CoordZ& rx ) {
958 for ( DCIter it = data_container.begin(); it != data_container.end(); ) {
959
960 if ( it->first->isEquivalentTo( tx ) ) {
961
962 for ( ICIter it2 = it->second.begin(); it2 != it->second.end(); ) {
963 if ( it2->first->isEquivalentTo( rx ) ) {
964 delete it2->second;
965// delete it2->first;
966 it->second.erase(it2++);
967 }
968 else ++it2;
969 }
970
971 }
972
973 if ( it->second.empty() ) {
974// delete it->first;
975 data_container.erase(it++);
976 }
977 else ++it;
978 }
979 }
980
981
982 template< typename Data >
983 inline void WossCreatorContainer< Data* >::replace( Data* const data, Location* const tx, Location* const rx ) {
984 if ( data_container[tx][rx] != NULL ) delete data_container[tx][rx];
985 data_container[tx][rx] = data;
986 }
987
988
989 template< typename Data >
990 inline void WossCreatorContainer< Data* >::replace( Data* const data, const CoordZ& tx, const CoordZ& rx ) {
991 Location* tx_loc = createLocation(tx);
992 Location* rx_loc = createLocation(rx);
993
994 if ( data_container[tx_loc][rx_loc] != NULL ) delete data_container[tx_loc][rx_loc];
995 data_container[tx_loc][rx_loc] = data;
996 }
997
998
999 template< typename Data >
1001 for( DCIter it = data_container.begin(); it != data_container.end(); it++ ) {
1002
1003 for( ICIter it2 = it->second.begin(); it2 != it->second.end(); it2++ ) {
1004 delete it2->second;
1005 }
1006
1007 it->second.clear();
1008// delete it->first;
1009 }
1010 data_container.clear();
1011 }
1012
1013
1015
1016
1022 template<>
1024
1025
1026 public:
1027
1028
1029 static Location* const ALL_LOCATIONS;
1030
1031 static const CoordZ ALL_COORDZ;
1032
1033
1035
1037
1038
1039 bool isEmpty() const;
1040
1041 int size() const;
1042
1043
1052 bool insert( const CustomTransducer& data, Location* const tx, Location* const rx );
1053
1062 bool insert( const CustomTransducer& data, const CoordZ& tx, const CoordZ& rx );
1063
1064
1071 CustomTransducer get( Location* const tx, Location* const rx ) const;
1072
1079 CustomTransducer get( const CoordZ& tx, const CoordZ& rx ) const;
1080
1081
1089
1090
1091 void erase( Location* const tx, Location* const rx );
1092
1093 void erase( const CoordZ& tx, const CoordZ& rx );
1094
1095
1103 void replace( const CustomTransducer& data, Location* const tx, Location* const rx );
1104
1112 void replace( const CustomTransducer& data, const CoordZ& tx, const CoordZ& rx );
1113
1114
1115 void clear();
1116
1117
1118 void setDebug( bool flag ) { debug = flag; }
1119
1120 bool isUsingDebug() const { return debug; }
1121
1122
1123 protected:
1124
1125
1126 typedef ::std::map< Location*, CustomTransducer > InnerContainer;
1127 typedef InnerContainer::iterator ICIter;
1128 typedef InnerContainer::reverse_iterator ICRIter;
1129 typedef InnerContainer::const_iterator ICCIter;
1130 typedef InnerContainer::const_reverse_iterator ICCRIter;
1131
1132
1133 typedef ::std::map< Location*, InnerContainer > DataContainer;
1134
1135 typedef DataContainer::iterator DCIter;
1136 typedef DataContainer::const_iterator DCCIter;
1137 typedef DataContainer::reverse_iterator DCRIter;
1138 typedef DataContainer::const_reverse_iterator DCRCIter;
1139
1140
1141 DCIter find( const CoordZ& coordinates );
1142
1143 ICIter find( const CoordZ& coordinates, const DCIter& iter );
1144
1145
1146 Location* createLocation( const CoordZ& coordinates );
1147
1148
1150
1151
1152 bool debug;
1153
1154
1155 };
1156
1157
1159 return data_container.empty();
1160 }
1161
1162
1164 return data_container.size();
1165 }
1166
1167
1168 inline Location* WossCreatorContainer< CustomTransducer >::createLocation( const CoordZ& coordinates ) {
1169 if ( coordinates == ALL_COORDZ ) return NULL;
1170 return new Location( coordinates );
1171 }
1172
1173
1175 DCIter it = data_container.find(tx);
1176 if ( it == data_container.end() ) {
1177 data_container[tx][rx] = data;
1178 return true;
1179 }
1180 ICIter it2 = it->second.find(rx);
1181 if ( it2 == it->second.end() ) {
1182 (it->second)[rx] = data;
1183 return true;
1184 }
1185 return false;
1186 }
1187
1188
1189 inline bool WossCreatorContainer< CustomTransducer >::insert( const CustomTransducer& data, const CoordZ& tx, const CoordZ& rx ) {
1190 DCIter it = find( tx );
1191 if ( it == data_container.end() ) {
1192 data_container[ createLocation(tx) ][ createLocation(rx) ] = data;
1193 return true;
1194 }
1195 ICIter it2 = find( rx, it );
1196 if ( it2 == it->second.end() ) {
1197 (it->second)[ createLocation(rx) ] = data;
1198 return true;
1199 }
1200 return false;
1201 }
1202
1203
1207
1208
1209 inline void WossCreatorContainer< CustomTransducer >::erase( Location* const tx, Location* const rx ) {
1210 DCIter it = data_container.find(tx);
1211 if ( it != data_container.end() ) {
1212
1213 ICIter it2 = it->second.find( rx );
1214
1215 if ( it2 != it->second.end() ) {
1216 it->second.erase( it2 );
1217 }
1218
1219 }
1220 if ( it->second.empty() ) {
1221 data_container.erase(it);
1222 }
1223 }
1224
1225
1226 inline void WossCreatorContainer< CustomTransducer >::erase( const CoordZ& tx, const CoordZ& rx ) {
1227 for ( DCIter it = data_container.begin(); it != data_container.end(); ) {
1228
1229 if ( it->first->isEquivalentTo( tx ) ) {
1230
1231 for ( ICIter it2 = it->second.begin(); it2 != it->second.end(); ) {
1232 if ( it2->first->isEquivalentTo( rx ) ) {
1233 it->second.erase(it2++);
1234 }
1235 else ++it2;
1236 }
1237
1238 }
1239
1240 if ( it->second.empty() ) {
1241 data_container.erase(it++);
1242 }
1243 else ++it;
1244 }
1245 }
1246
1247
1249 data_container[tx][rx] = data;
1250 }
1251
1252
1253 inline void WossCreatorContainer< CustomTransducer >::replace( const CustomTransducer& data, const CoordZ& tx, const CoordZ& rx ) {
1254 Location* tx_loc = createLocation(tx);
1255 Location* rx_loc = createLocation(rx);
1256
1257 data_container[tx_loc][rx_loc] = data;
1258 }
1259
1260
1262// for( DCIter it = data_container.begin(); it != data_container.end(); it++ ) {
1263// for( ICIter it2 = it->second.begin(); it2 != it->second.end(); it2++ ) {
1264//
1265// }
1266// }
1267 data_container.clear();
1268 }
1269
1270}
1271
1272
1273#endif // WOSS_CREATOR_CONTAINER_DEFINITIONS_H
3D-Coordinates (lat, long, depth) class definitions and functions library
Definition coordinates-definitions.h:403
Class that stores the coordinates of moving entity.
Definition location-definitions.h:60
virtual Location * clone() const
Definition location-definitions.h:111
CustomTransducer get(Location *const tx, Location *const rx) const
CustomTransducer get(const CoordZ &tx, const CoordZ &rx) const
Class that stores WossCreator parameters.
Definition woss-creator-container.h:124
Data get(Location *const tx, Location *const rx) const
Definition woss-creator-container.cpp:157
static const CoordZ ALL_COORDZ
Definition woss-creator-container.h:138
bool insert(const Data &data, Location *const tx, Location *const rx)
Definition woss-creator-container.h:426
bool insert(const Data &data, const CoordZ &tx, const CoordZ &rx)
Definition woss-creator-container.h:442
DCIter find(const CoordZ &coordinates)
Definition woss-creator-container.cpp:64
Data & accessAllLocations()
Definition woss-creator-container.h:499
void replace(const Data &data, Location *const tx, Location *const rx)
Definition woss-creator-container.h:559
bool debug
Definition woss-creator-container.h:319
void erase(Location *const tx, Location *const rx)
Definition woss-creator-container.h:532
DataContainer data_container
Definition woss-creator-container.h:313
void clear()
Definition woss-creator-container.h:571
~WossCreatorContainer()
Definition woss-creator-container.cpp:59
WossCreatorContainer()
Definition woss-creator-container.cpp:52
Location * createLocation(const CoordZ &coordinates)
Definition woss-creator-container.h:359
void setDebug(bool flag)
Definition woss-creator-container.h:252
::std::map< Location *, Data > InnerContainer
Definition woss-creator-container.h:267
int size() const
Definition woss-creator-container.h:353
void replace(const Data &data, const CoordZ &tx, const CoordZ &rx)
Definition woss-creator-container.h:565
void erase(const CoordZ &tx, const CoordZ &rx)
Definition woss-creator-container.h:540
bool isUsingDebug() const
Definition woss-creator-container.h:258
static Location *const ALL_LOCATIONS
Definition woss-creator-container.h:133
bool isEmpty() const
Definition woss-creator-container.h:347
::std::map< Location *, InnerContainer > DataContainer
Definition woss-creator-container.h:277
Implementation of woss::Location class.
Initial set up of a transducer.
Definition woss-creator-container.h:57
double initial_vert_rotation
Definition woss-creator-container.h:95
double initial_bearing
Definition woss-creator-container.h:90
double add_costant
Definition woss-creator-container.h:110
::std::string type
Definition woss-creator-container.h:84
CustomTransducer(const ::std::string &name="", double bearing=0.0, double vert_rot=0.0, double horiz_rot=0.0, double mult=1.0, double add=0.0)
Definition woss-creator-container.h:67
double initial_horiz_rotation
Definition woss-creator-container.h:100
double multiply_costant
Definition woss-creator-container.h:105