From e2f02a50f00fa8363a55e91f025bb4d20faa1aa0 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 15 Aug 2017 22:15:21 +0200 Subject: [PATCH] Use const container calls when result is immediately converted to a const iterator --- src/algorithms/PVT/libs/rinex_printer.cc | 12 +- .../sbas_l1_telemetry_decoder_cc.cc | 14 +- src/core/system_parameters/rtcm.cc | 122 +++++++++--------- .../adapter/adapter_test.cc | 12 +- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/algorithms/PVT/libs/rinex_printer.cc b/src/algorithms/PVT/libs/rinex_printer.cc index 0b6fb5030..f18196162 100644 --- a/src/algorithms/PVT/libs/rinex_printer.cc +++ b/src/algorithms/PVT/libs/rinex_printer.cc @@ -1526,8 +1526,8 @@ void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map::const_iterator gps_ephemeris_iter; - for(gps_ephemeris_iter = eph_map.begin(); - gps_ephemeris_iter != eph_map.end(); + for(gps_ephemeris_iter = eph_map.cbegin(); + gps_ephemeris_iter != eph_map.cend(); gps_ephemeris_iter++) { // -------- SV / EPOCH / SV CLK @@ -1857,8 +1857,8 @@ void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map::const_iterator gps_ephemeris_iter; - for(gps_ephemeris_iter = eph_map.begin(); - gps_ephemeris_iter != eph_map.end(); + for(gps_ephemeris_iter = eph_map.cbegin(); + gps_ephemeris_iter != eph_map.cend(); gps_ephemeris_iter++) { // -------- SV / EPOCH / SV CLK @@ -2020,8 +2020,8 @@ void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map::const_iterator galileo_ephemeris_iter; line.clear(); - for(galileo_ephemeris_iter = eph_map.begin(); - galileo_ephemeris_iter != eph_map.end(); + for(galileo_ephemeris_iter = eph_map.cbegin(); + galileo_ephemeris_iter != eph_map.cend(); galileo_ephemeris_iter++) { // -------- SV / EPOCH / SV CLK diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc index 2fb2fe5f8..238695e7c 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc @@ -136,8 +136,8 @@ int sbas_l1_telemetry_decoder_cc::general_work (int noutput_items __attribute__( // compute message sample stamp // and fill messages in SBAS raw message objects //std::vector sbas_raw_msgs; - for(std::vector::const_iterator it = valid_msgs.begin(); - it != valid_msgs.end(); ++it) + for(std::vector::const_iterator it = valid_msgs.cbegin(); + it != valid_msgs.cend(); ++it) { int message_sample_offset = (sample_alignment ? 0 : -1) @@ -314,7 +314,7 @@ bool sbas_l1_telemetry_decoder_cc::symbol_aligner_and_decoder::get_bits(const st std::vector symbols_vd1(symbols); // aligned symbol vector -> copy input symbol vector std::vector symbols_vd2; // shifted symbol vector -> add past sample in front of input vector symbols_vd2.push_back(d_past_symbol); - for (std::vector::const_iterator symbol_it = symbols.begin(); symbol_it != symbols.end() - 1; ++symbol_it) + for (std::vector::const_iterator symbol_it = symbols.cbegin(); symbol_it != symbols.cend() - 1; ++symbol_it) { symbols_vd2.push_back(*symbol_it); } @@ -361,7 +361,7 @@ void sbas_l1_telemetry_decoder_cc::frame_detector::get_frame_candidates(const st ss << "copy bits "; int count = 0; // copy new bits into the working buffer - for (std::vector::const_iterator bit_it = bits.begin(); bit_it < bits.end(); ++bit_it) + for (std::vector::const_iterator bit_it = bits.cbegin(); bit_it < bits.cend(); ++bit_it) { d_buffer.push_back(*bit_it); ss << *bit_it; @@ -421,7 +421,7 @@ void sbas_l1_telemetry_decoder_cc::crc_verifier::get_valid_frames(const std::vec std::stringstream ss; VLOG(FLOW) << "get_valid_frames(): " << "msg_candidates.size()=" << msg_candidates.size(); // for each candidate - for (std::vector::const_iterator candidate_it = msg_candidates.begin(); candidate_it < msg_candidates.end(); ++candidate_it) + for (std::vector::const_iterator candidate_it = msg_candidates.cbegin(); candidate_it < msg_candidates.cend(); ++candidate_it) { // convert to bytes std::vector candidate_bytes; @@ -462,7 +462,7 @@ void sbas_l1_telemetry_decoder_cc::crc_verifier::zerropad_back_and_convert_to_by const size_t bits_per_byte = 8; unsigned char byte = 0; VLOG(LMORE) << "zerropad_back_and_convert_to_bytes():" << byte; - for (std::vector::const_iterator candidate_bit_it = msg_candidate.begin(); candidate_bit_it < msg_candidate.end(); ++candidate_bit_it) + for (std::vector::const_iterator candidate_bit_it = msg_candidate.cbegin(); candidate_bit_it < msg_candidate.cend(); ++candidate_bit_it) { int idx_bit = candidate_bit_it - msg_candidate.begin(); int bit_pos_in_current_byte = (bits_per_byte - 1) - (idx_bit % bits_per_byte); @@ -490,7 +490,7 @@ void sbas_l1_telemetry_decoder_cc::crc_verifier::zerropad_front_and_convert_to_b unsigned char byte = 0; int idx_bit = 6; // insert 6 zeros at the front to fit the 250bits into a multiple of bytes VLOG(LMORE) << "zerropad_front_and_convert_to_bytes():" << byte; - for (std::vector::const_iterator candidate_bit_it = msg_candidate.begin(); candidate_bit_it < msg_candidate.end(); ++candidate_bit_it) + for (std::vector::const_iterator candidate_bit_it = msg_candidate.cbegin(); candidate_bit_it < msg_candidate.cend(); ++candidate_bit_it) { int bit_pos_in_current_byte = (bits_per_byte - 1) - (idx_bit % bits_per_byte); byte |= (unsigned char)(*candidate_bit_it) << bit_pos_in_current_byte; diff --git a/src/core/system_parameters/rtcm.cc b/src/core/system_parameters/rtcm.cc index 35e378520..9999b3671 100644 --- a/src/core/system_parameters/rtcm.cc +++ b/src/core/system_parameters/rtcm.cc @@ -462,8 +462,8 @@ std::string Rtcm::print_MT1001(const Gps_Ephemeris & gps_eph, double obs_time, c std::map observablesL1; std::map::const_iterator observables_iter; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { std::string system_(&observables_iter->second.System, 1); @@ -477,8 +477,8 @@ std::string Rtcm::print_MT1001(const Gps_Ephemeris & gps_eph, double obs_time, c std::bitset<64> header = Rtcm::get_MT1001_4_header(1001, obs_time, observablesL1, ref_id, smooth_int, sync_flag, divergence_free); std::string data = header.to_string(); - for(observables_iter = observablesL1.begin(); - observables_iter != observablesL1.end(); + for(observables_iter = observablesL1.cbegin(); + observables_iter != observablesL1.cend(); observables_iter++) { std::bitset<58> content = Rtcm::get_MT1001_sat_content(gps_eph, obs_time, observables_iter->second); @@ -512,8 +512,8 @@ std::string Rtcm::print_MT1002(const Gps_Ephemeris & gps_eph, double obs_time, c std::map observablesL1; std::map::const_iterator observables_iter; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { std::string system_(&observables_iter->second.System, 1); @@ -527,8 +527,8 @@ std::string Rtcm::print_MT1002(const Gps_Ephemeris & gps_eph, double obs_time, c std::bitset<64> header = Rtcm::get_MT1001_4_header(1002, obs_time, observablesL1, ref_id, smooth_int, sync_flag, divergence_free); std::string data = header.to_string(); - for(observables_iter = observablesL1.begin(); - observables_iter != observablesL1.end(); + for(observables_iter = observablesL1.cbegin(); + observables_iter != observablesL1.cend(); observables_iter++) { std::bitset<74> content = Rtcm::get_MT1002_sat_content(gps_eph, obs_time, observables_iter->second); @@ -586,8 +586,8 @@ std::string Rtcm::print_MT1003(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem std::map::const_iterator observables_iter; std::map::const_iterator observables_iter2; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { std::string system_(&observables_iter->second.System, 1); @@ -607,13 +607,13 @@ std::string Rtcm::print_MT1003(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem std::vector< std::pair< Gnss_Synchro, Gnss_Synchro > >::const_iterator common_observables_iter; std::map observablesL1_with_L2; - for(observables_iter = observablesL1.begin(); - observables_iter != observablesL1.end(); + for(observables_iter = observablesL1.cbegin(); + observables_iter != observablesL1.cend(); observables_iter++) { unsigned int prn_ = observables_iter->second.PRN; - for(observables_iter2 = observablesL2.begin(); - observables_iter2 != observablesL2.end(); + for(observables_iter2 = observablesL2.cbegin(); + observables_iter2 != observablesL2.cend(); observables_iter2++) { if(observables_iter2->second.PRN == prn_) @@ -631,8 +631,8 @@ std::string Rtcm::print_MT1003(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem std::bitset<64> header = Rtcm::get_MT1001_4_header(1003, obs_time, observablesL1_with_L2, ref_id, smooth_int, sync_flag, divergence_free); std::string data = header.to_string(); - for(common_observables_iter = common_observables.begin(); - common_observables_iter != common_observables.end(); + for(common_observables_iter = common_observables.cbegin(); + common_observables_iter != common_observables.cend(); common_observables_iter++) { std::bitset<101> content = Rtcm::get_MT1003_sat_content(ephL1, ephL2, obs_time, common_observables_iter->first, common_observables_iter->second); @@ -696,8 +696,8 @@ std::string Rtcm::print_MT1004(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem std::map::const_iterator observables_iter; std::map::const_iterator observables_iter2; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { std::string system_(&observables_iter->second.System, 1); @@ -717,13 +717,13 @@ std::string Rtcm::print_MT1004(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem std::vector< std::pair< Gnss_Synchro, Gnss_Synchro > >::const_iterator common_observables_iter; std::map observablesL1_with_L2; - for(observables_iter = observablesL1.begin(); - observables_iter != observablesL1.end(); + for(observables_iter = observablesL1.cbegin(); + observables_iter != observablesL1.cend(); observables_iter++) { unsigned int prn_ = observables_iter->second.PRN; - for(observables_iter2 = observablesL2.begin(); - observables_iter2 != observablesL2.end(); + for(observables_iter2 = observablesL2.cbegin(); + observables_iter2 != observablesL2.cend(); observables_iter2++) { if(observables_iter2->second.PRN == prn_) @@ -741,8 +741,8 @@ std::string Rtcm::print_MT1004(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem std::bitset<64> header = Rtcm::get_MT1001_4_header(1004, obs_time, observablesL1_with_L2, ref_id, smooth_int, sync_flag, divergence_free); std::string data = header.to_string(); - for(common_observables_iter = common_observables.begin(); - common_observables_iter != common_observables.end(); + for(common_observables_iter = common_observables.cbegin(); + common_observables_iter != common_observables.cend(); common_observables_iter++) { std::bitset<125> content = Rtcm::get_MT1004_sat_content(ephL1, ephL2, obs_time, common_observables_iter->first, common_observables_iter->second); @@ -1037,7 +1037,7 @@ std::string Rtcm::print_MT1008(unsigned int ref_id, const std::string & antenna_ DF029 = std::bitset<8>(len); std::string DF030_str_; - for(auto it = ant_descriptor.begin(); it != ant_descriptor.end(); it++) + for(auto it = ant_descriptor.cbegin(); it != ant_descriptor.cend(); it++) { char c = *it; std::bitset<8> character = std::bitset<8>(c); @@ -1056,7 +1056,7 @@ std::string Rtcm::print_MT1008(unsigned int ref_id, const std::string & antenna_ DF032 = std::bitset<8>(len2); std::string DF033_str_; - for(auto it = ant_sn.begin(); it != ant_sn.end(); it++) + for(auto it = ant_sn.cbegin(); it != ant_sn.cend(); it++) { char c = *it; std::bitset<8> character = std::bitset<8>(c); @@ -1317,7 +1317,7 @@ std::string Rtcm::print_MT1029(unsigned int ref_id, const Gps_Ephemeris & gps_ep unsigned int i = 0; bool first = true; std::string text_binary; - for(auto it = message.begin(); it != message.end(); it++) + for(auto it = message.cbegin(); it != message.cend(); it++) { char c = *it; if(isgraph(c)) @@ -1684,8 +1684,8 @@ std::string Rtcm::get_MSM_1_content_sat_data(const std::map & std::vector pos; std::vector::iterator it; - for(gnss_synchro_iter = observables.begin(); - gnss_synchro_iter != observables.end(); + for(gnss_synchro_iter = observables.cbegin(); + gnss_synchro_iter != observables.cend(); gnss_synchro_iter++) { it = std::find(pos.begin(), pos.end(), 65 - gnss_synchro_iter->second.PRN); @@ -1717,8 +1717,8 @@ std::string Rtcm::get_MSM_1_content_signal_data(const std::map > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -1806,8 +1806,8 @@ std::string Rtcm::get_MSM_2_content_signal_data(const Gps_Ephemeris & ephNAV, co std::vector > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -1902,8 +1902,8 @@ std::string Rtcm::get_MSM_3_content_signal_data(const Gps_Ephemeris & ephNAV, co std::vector > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -2000,8 +2000,8 @@ std::string Rtcm::get_MSM_4_content_sat_data(const std::map & std::vector pos; std::vector::iterator it; - for(gnss_synchro_iter = observables.begin(); - gnss_synchro_iter != observables.end(); + for(gnss_synchro_iter = observables.cbegin(); + gnss_synchro_iter != observables.cend(); gnss_synchro_iter++) { it = std::find(pos.begin(), pos.end(), 65 - gnss_synchro_iter->second.PRN); @@ -2040,8 +2040,8 @@ std::string Rtcm::get_MSM_4_content_signal_data(const Gps_Ephemeris & ephNAV, co std::vector > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -2142,8 +2142,8 @@ std::string Rtcm::get_MSM_5_content_sat_data(const std::map & std::vector pos; std::vector::iterator it; - for(gnss_synchro_iter = observables.begin(); - gnss_synchro_iter != observables.end(); + for(gnss_synchro_iter = observables.cbegin(); + gnss_synchro_iter != observables.cend(); gnss_synchro_iter++) { it = std::find(pos.begin(), pos.end(), 65 - gnss_synchro_iter->second.PRN); @@ -2187,8 +2187,8 @@ std::string Rtcm::get_MSM_5_content_signal_data(const Gps_Ephemeris & ephNAV, co std::vector > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -2290,8 +2290,8 @@ std::string Rtcm::get_MSM_6_content_signal_data(const Gps_Ephemeris & ephNAV, co std::vector > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -2392,8 +2392,8 @@ std::string Rtcm::get_MSM_7_content_signal_data(const Gps_Ephemeris & ephNAV, co std::vector > observables_vector; std::map::const_iterator map_iter; - for(map_iter = observables.begin(); - map_iter != observables.end(); + for(map_iter = observables.cbegin(); + map_iter != observables.cend(); map_iter++) { observables_vector.push_back(*map_iter); @@ -2442,8 +2442,8 @@ std::vector > Rtcm::sort_by_PRN_mask(const std::vec } } has_lower_pos; - for(synchro_map_iter = synchro_map.begin(); - synchro_map_iter != synchro_map.end(); + for(synchro_map_iter = synchro_map.cbegin(); + synchro_map_iter != synchro_map.cend(); synchro_map_iter++) { @@ -2499,8 +2499,8 @@ std::vector > Rtcm::sort_by_signal(const std::vecto } has_lower_signalID; - for(synchro_map_iter = synchro_map.begin(); - synchro_map_iter != synchro_map.end(); + for(synchro_map_iter = synchro_map.cbegin(); + synchro_map_iter != synchro_map.cend(); synchro_map_iter++) { @@ -2785,8 +2785,8 @@ int Rtcm::set_DF006(const std::map & observables) //Number of satellites observed in current epoch unsigned short int nsats = 0; std::map::const_iterator observables_iter; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { nsats++; @@ -3566,8 +3566,8 @@ int Rtcm::set_DF394(const std::map & gnss_synchro) DF394.reset(); std::map::const_iterator gnss_synchro_iter; unsigned int mask_position; - for(gnss_synchro_iter = gnss_synchro.begin(); - gnss_synchro_iter != gnss_synchro.end(); + for(gnss_synchro_iter = gnss_synchro.cbegin(); + gnss_synchro_iter != gnss_synchro.cend(); gnss_synchro_iter++) { mask_position = 64 - gnss_synchro_iter->second.PRN; @@ -3587,8 +3587,8 @@ int Rtcm::set_DF395(const std::map & gnss_synchro) std::map::const_iterator gnss_synchro_iter; std::string sig; unsigned int mask_position; - for(gnss_synchro_iter = gnss_synchro.begin(); - gnss_synchro_iter != gnss_synchro.end(); + for(gnss_synchro_iter = gnss_synchro.cbegin(); + gnss_synchro_iter != gnss_synchro.cend(); gnss_synchro_iter++) { std::string sig_(gnss_synchro_iter->second.Signal); @@ -3654,8 +3654,8 @@ std::string Rtcm::set_DF396(const std::map & observables) std::vector list_of_sats; std::vector list_of_signals; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { list_of_sats.push_back(observables_iter->second.PRN); @@ -3708,8 +3708,8 @@ std::string Rtcm::set_DF396(const std::map & observables) for(unsigned int sat = 0; sat < num_satellites; sat++) { value = false; - for(observables_iter = observables.begin(); - observables_iter != observables.end(); + for(observables_iter = observables.cbegin(); + observables_iter != observables.cend(); observables_iter++) { std::string sig_(observables_iter->second.Signal); diff --git a/src/tests/unit-tests/signal-processing-blocks/adapter/adapter_test.cc b/src/tests/unit-tests/signal-processing-blocks/adapter/adapter_test.cc index 82b309112..a24f1a7e8 100644 --- a/src/tests/unit-tests/signal-processing-blocks/adapter/adapter_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/adapter/adapter_test.cc @@ -93,7 +93,7 @@ int DataTypeAdapter::run_ishort_to_cshort_block() EXPECT_EQ(expected_implementation, ishort_to_cshort->implementation()); std::ofstream ofs(file_name_input.c_str(), std::ofstream::binary); - for(std::vector::const_iterator i = input_data_shorts.begin(); i != input_data_shorts.end(); ++i) + for(std::vector::const_iterator i = input_data_shorts.cbegin(); i != input_data_shorts.cend(); ++i) { short aux = *i; ofs.write(reinterpret_cast(&aux), sizeof(short)); @@ -122,7 +122,7 @@ int DataTypeAdapter::run_ishort_to_complex_block() EXPECT_EQ(expected_implementation, ishort_to_complex->implementation()); std::ofstream ofs(file_name_input.c_str(), std::ofstream::binary); - for(std::vector::const_iterator i = input_data_shorts.begin(); i != input_data_shorts.end(); ++i) + for(std::vector::const_iterator i = input_data_shorts.cbegin(); i != input_data_shorts.cend(); ++i) { short aux = *i; ofs.write(reinterpret_cast(&aux), sizeof(short)); @@ -151,7 +151,7 @@ int DataTypeAdapter::run_ibyte_to_cshort_block() EXPECT_EQ(expected_implementation, ibyte_to_cshort->implementation()); std::ofstream ofs(file_name_input.c_str()); - for(std::vector::const_iterator i = input_data_bytes.begin(); i != input_data_bytes.end(); ++i) + for(std::vector::const_iterator i = input_data_bytes.cbegin(); i != input_data_bytes.cend(); ++i) { ofs << *i; } @@ -179,7 +179,7 @@ int DataTypeAdapter::run_ibyte_to_complex_block() EXPECT_EQ(expected_implementation, ibyte_to_complex->implementation()); std::ofstream ofs(file_name_input.c_str() ); - for(std::vector::const_iterator i = input_data_bytes.begin(); i != input_data_bytes.end(); ++i) + for(std::vector::const_iterator i = input_data_bytes.cbegin(); i != input_data_bytes.cend(); ++i) { ofs << *i; } @@ -207,7 +207,7 @@ int DataTypeAdapter::run_ibyte_to_cbyte_block() EXPECT_EQ(expected_implementation, ibyte_to_cbyte->implementation()); std::ofstream ofs(file_name_input.c_str()); - for(std::vector::const_iterator i = input_data_bytes.begin(); i != input_data_bytes.end(); ++i) + for(std::vector::const_iterator i = input_data_bytes.cbegin(); i != input_data_bytes.cend(); ++i) { ofs << *i; } @@ -235,7 +235,7 @@ int DataTypeAdapter::run_byte_to_short_block() EXPECT_EQ(expected_implementation, byte_to_short->implementation()); std::ofstream ofs(file_name_input.c_str()); - for(std::vector::const_iterator i = input_data_bytes.begin(); i != input_data_bytes.end(); ++i) + for(std::vector::const_iterator i = input_data_bytes.cbegin(); i != input_data_bytes.cend(); ++i) { ofs << *i; }