From e7246d456599f0f8964d9dd0dd35d878e7081434 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 19 Aug 2017 11:27:22 +0200 Subject: [PATCH] Replace C-style casts by C++ casts --- src/algorithms/PVT/libs/rinex_printer.h | 6 +++--- .../gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc | 2 +- .../gnuradio_blocks/pcps_multithread_acquisition_cc.cc | 4 ++-- .../gnuradio_blocks/pcps_opencl_acquisition_cc.cc | 4 ++-- src/algorithms/input_filter/gnuradio_blocks/beamformer.cc | 4 ++-- src/algorithms/libs/complex_byte_to_float_x2.cc | 6 +++--- src/algorithms/libs/cshort_to_float_x2.cc | 6 +++--- .../gnuradio_blocks/signal_generator_c.cc | 2 +- .../gnuradio_blocks/galileo_e1b_telemetry_decoder_cc.cc | 4 ++-- .../gnuradio_blocks/galileo_e5a_telemetry_decoder_cc.cc | 8 ++++---- .../gnuradio_blocks/gps_l2c_telemetry_decoder_cc.cc | 2 +- .../gnuradio_blocks/sbas_l1_telemetry_decoder_cc.cc | 6 +++--- .../galileo_e1_tcp_connector_tracking_cc.cc | 4 ++-- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/algorithms/PVT/libs/rinex_printer.h b/src/algorithms/PVT/libs/rinex_printer.h index af168ab9b..d9aee967e 100644 --- a/src/algorithms/PVT/libs/rinex_printer.h +++ b/src/algorithms/PVT/libs/rinex_printer.h @@ -483,7 +483,7 @@ inline std::string & Rinex_Printer::rightJustify(std::string & s, } else { - s.insert((std::string::size_type)0, length-s.length(), pad); + s.insert(static_cast(0), length - s.length(), pad); } return s; } @@ -614,13 +614,13 @@ inline std::string & Rinex_Printer::sci2for(std::string & aStr, // (if it's negative, there's a leading '-' if (aStr[0] == '.') { - aStr.insert((std::string::size_type)0, 1, ' '); + aStr.insert(static_cast(0), 1, ' '); } //If checkSwitch is false, add on one leading zero to the string if (!checkSwitch) { - aStr.insert((std::string::size_type)1, 1, '0'); + aStr.insert(static_cast(1), 1, '0'); } return aStr; diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc index b9ab8f138..0aa8f1410 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc @@ -284,7 +284,7 @@ float pcps_acquisition_fine_doppler_cc::estimate_input_power(gr_vector_const_voi int pcps_acquisition_fine_doppler_cc::compute_and_accumulate_grid(gr_vector_const_void_star &input_items) { // initialize acquisition algorithm - const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer + const gr_complex *in = reinterpret_cast(input_items[0]); //Get the input samples pointer DLOG(INFO) << "Channel: " << d_channel << " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc index febc35679..0dcbbc070 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc @@ -387,7 +387,7 @@ int pcps_multithread_acquisition_cc::general_work(int noutput_items, unsigned int num_dwells = std::min(static_cast(d_max_dwells - d_in_dwell_count), ninput_items[0]); for (unsigned int i = 0; i < num_dwells; i++) { - memcpy(d_in_buffer[d_in_dwell_count++], (gr_complex*)input_items[i], + memcpy(d_in_buffer[d_in_dwell_count++], reinterpret_cast(input_items[i]), sizeof(gr_complex)*d_fft_size); d_sample_counter += d_fft_size; d_sample_counter_buffer.push_back(d_sample_counter); @@ -395,7 +395,7 @@ int pcps_multithread_acquisition_cc::general_work(int noutput_items, if (ninput_items[0] > static_cast(num_dwells)) { - d_sample_counter += d_fft_size * (ninput_items[0]-num_dwells); + d_sample_counter += d_fft_size * (ninput_items[0] - num_dwells); } } else diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc index baea80465..28823347e 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc @@ -730,10 +730,10 @@ int pcps_opencl_acquisition_cc::general_work(int noutput_items, // Fill internal buffer with d_max_dwells signal blocks. This step ensures that // consecutive signal blocks will be processed in multi-dwell operation. This is // essential when d_bit_transition_flag = true. - unsigned int num_dwells = std::min(static_cast(d_max_dwells-d_in_dwell_count), ninput_items[0]); + unsigned int num_dwells = std::min(static_cast(d_max_dwells - d_in_dwell_count), ninput_items[0]); for (unsigned int i = 0; i < num_dwells; i++) { - memcpy(d_in_buffer[d_in_dwell_count++], (gr_complex*)input_items[i], + memcpy(d_in_buffer[d_in_dwell_count++], static_cast(input_items[i]), sizeof(gr_complex)*d_fft_size); d_sample_counter += d_fft_size; d_sample_counter_buffer.push_back(d_sample_counter); diff --git a/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc b/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc index 47a61a877..697d33362 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc @@ -67,7 +67,7 @@ beamformer::~beamformer() int beamformer::work(int noutput_items,gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - gr_complex *out = (gr_complex *) output_items[0]; + gr_complex *out = reinterpret_cast(output_items[0]); // channel output buffers // gr_complex *ch1 = (gr_complex *) input_items[0]; // gr_complex *ch2 = (gr_complex *) input_items[1]; @@ -86,7 +86,7 @@ int beamformer::work(int noutput_items,gr_vector_const_void_star &input_items, sum = gr_complex(0,0); for (int i = 0; i < GNSS_SDR_BEAMFORMER_CHANNELS; i++) { - sum = sum + ((gr_complex*)input_items[i])[n] * weight_vector[i]; + sum = sum + (reinterpret_cast(input_items[i]))[n] * weight_vector[i]; } out[n] = sum; } diff --git a/src/algorithms/libs/complex_byte_to_float_x2.cc b/src/algorithms/libs/complex_byte_to_float_x2.cc index 0bcdcc909..014b330f3 100644 --- a/src/algorithms/libs/complex_byte_to_float_x2.cc +++ b/src/algorithms/libs/complex_byte_to_float_x2.cc @@ -54,9 +54,9 @@ int complex_byte_to_float_x2::work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const lv_8sc_t *in = (const lv_8sc_t *) input_items[0]; - float *out0 = (float*) output_items[0]; - float *out1 = (float*) output_items[1]; + const lv_8sc_t *in = reinterpret_cast(input_items[0]); + float *out0 = reinterpret_cast(output_items[0]); + float *out1 = reinterpret_cast(output_items[1]); const float scalar = 1; volk_8ic_s32f_deinterleave_32f_x2(out0, out1, in, scalar, noutput_items); return noutput_items; diff --git a/src/algorithms/libs/cshort_to_float_x2.cc b/src/algorithms/libs/cshort_to_float_x2.cc index 861f1c010..50b2f3d4b 100644 --- a/src/algorithms/libs/cshort_to_float_x2.cc +++ b/src/algorithms/libs/cshort_to_float_x2.cc @@ -54,9 +54,9 @@ int cshort_to_float_x2::work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const lv_16sc_t *in = (const lv_16sc_t *) input_items[0]; - float *out0 = (float*) output_items[0]; - float *out1 = (float*) output_items[1]; + const lv_16sc_t *in = reinterpret_cast(input_items[0]); + float *out0 = reinterpret_cast(output_items[0]); + float *out1 = reinterpret_cast(output_items[1]); const float scalar = 1; volk_16ic_s32f_deinterleave_32f_x2(out0, out1, in, scalar, noutput_items); return noutput_items; diff --git a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc index 31c7730e4..86f488588 100644 --- a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc +++ b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc @@ -254,7 +254,7 @@ int signal_generator_c::general_work (int noutput_items __attribute__((unused)), gr_vector_const_void_star &input_items __attribute__((unused)), gr_vector_void_star &output_items) { - gr_complex *out = (gr_complex *) output_items[0]; + gr_complex *out = reinterpret_cast(output_items[0]); work_counter_++; diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e1b_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e1b_telemetry_decoder_cc.cc index 85e058b95..8e70d49e7 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e1b_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e1b_telemetry_decoder_cc.cc @@ -122,10 +122,10 @@ galileo_e1b_telemetry_decoder_cc::galileo_e1b_telemetry_decoder_cc( d_symbols_per_preamble = GALILEO_INAV_PREAMBLE_LENGTH_BITS * d_samples_per_symbol; - memcpy((unsigned short int*)this->d_preambles_bits, (unsigned short int*)preambles_bits, GALILEO_INAV_PREAMBLE_LENGTH_BITS*sizeof(unsigned short int)); + memcpy(static_cast(this->d_preambles_bits), static_cast(preambles_bits), GALILEO_INAV_PREAMBLE_LENGTH_BITS * sizeof(unsigned short int)); // preamble bits to sampled symbols - d_preambles_symbols = (signed int*)malloc(sizeof(signed int) * d_symbols_per_preamble); + d_preambles_symbols = static_cast(malloc(sizeof(signed int) * d_symbols_per_preamble)); int n = 0; for (int i = 0; i < GALILEO_INAV_PREAMBLE_LENGTH_BITS; i++) { diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e5a_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e5a_telemetry_decoder_cc.cc index 2dfebc79f..031c18983 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e5a_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_e5a_telemetry_decoder_cc.cc @@ -78,10 +78,10 @@ void galileo_e5a_telemetry_decoder_cc::viterbi_decoder(double *page_part_symbols //create appropriate transition matrices int *out0, *out1, *state0, *state1; - out0 = (int*)calloc( max_states, sizeof(int) ); - out1 = (int*)calloc( max_states, sizeof(int) ); - state0 = (int*)calloc( max_states, sizeof(int) ); - state1 = (int*)calloc( max_states, sizeof(int) ); + out0 = static_cast(calloc( max_states, sizeof(int) )); + out1 = static_cast(calloc( max_states, sizeof(int) )); + state0 = static_cast(calloc( max_states, sizeof(int) )); + state1 = static_cast(calloc( max_states, sizeof(int) )); nsc_transit( out0, state0, 0, g_encoder, KK, nn ); nsc_transit( out1, state1, 1, g_encoder, KK, nn ); diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l2c_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l2c_telemetry_decoder_cc.cc index a565630ac..53178e4f9 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l2c_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l2c_telemetry_decoder_cc.cc @@ -101,7 +101,7 @@ int gps_l2c_telemetry_decoder_cc::general_work (int noutput_items __attribute__( u32 delay = 0; //add the symbol to the decoder - u8 symbol_clip = (u8)(in[0].Prompt_I > 0) * 255; + u8 symbol_clip = static_cast(in[0].Prompt_I > 0) * 255; flag_new_cnav_frame = cnav_msg_decoder_add_symbol(&d_cnav_decoder, symbol_clip, &msg, &delay); consume_each(1); //one by one 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 9785f6f02..96f1dd1b1 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 @@ -234,7 +234,7 @@ bool sbas_l1_telemetry_decoder_cc::sample_aligner::get_symbols(const std::vector // get the next samples for (int i = 0; i < d_n_smpls_in_history; i++) { - smpls[i] = ((int)i_sym)*sbas_l1_telemetry_decoder_cc::d_samples_per_symbol + i - 1 == -1 ? d_past_sample : samples[i_sym*sbas_l1_telemetry_decoder_cc::d_samples_per_symbol + i - 1]; + smpls[i] = static_cast(i_sym) * sbas_l1_telemetry_decoder_cc::d_samples_per_symbol + i - 1 == -1 ? d_past_sample : samples[i_sym*sbas_l1_telemetry_decoder_cc::d_samples_per_symbol + i - 1]; } // update the pseudo correlations (IIR method) of the two possible alignments @@ -466,7 +466,7 @@ void sbas_l1_telemetry_decoder_cc::crc_verifier::zerropad_back_and_convert_to_by { int idx_bit = candidate_bit_it - msg_candidate.begin(); 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; + byte |= static_cast(*candidate_bit_it) << bit_pos_in_current_byte; ss << *candidate_bit_it; if (idx_bit % bits_per_byte == bits_per_byte - 1) { @@ -493,7 +493,7 @@ void sbas_l1_telemetry_decoder_cc::crc_verifier::zerropad_front_and_convert_to_b 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; + byte |= static_cast(*candidate_bit_it) << bit_pos_in_current_byte; ss << *candidate_bit_it; if (idx_bit % bits_per_byte == bits_per_byte - 1) { diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc index f83a38370..9e17260fd 100644 --- a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc @@ -87,7 +87,7 @@ void Galileo_E1_Tcp_Connector_Tracking_cc::forecast (int noutput_items, { if (noutput_items != 0) { - ninput_items_required[0] = (int)d_vector_length*2; // set the required available samples in each call + ninput_items_required[0] = static_cast(d_vector_length) * 2; // set the required available samples in each call } } @@ -173,7 +173,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( d_enable_tracking = false; d_pull_in = false; - d_current_prn_length_samples = (int)d_vector_length; + d_current_prn_length_samples = static_cast(d_vector_length); // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0;