From 2614509b29c9257b876e7d97a70b97f5c3f3c239 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 2 Dec 2018 15:52:32 +0100 Subject: [PATCH] Fix string comparisons, improve const correctness --- src/algorithms/PVT/adapters/rtklib_pvt.cc | 56 +++++++++--------- .../PVT/gnuradio_blocks/rtklib_pvt_cc.cc | 58 ++++++++++--------- src/core/libs/string_converter.cc | 10 ++-- 3 files changed, 66 insertions(+), 58 deletions(-) diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc index e6b2d09cb..5bc2b473f 100644 --- a/src/algorithms/PVT/adapters/rtklib_pvt.cc +++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc @@ -80,27 +80,27 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, // RINEX version pvt_output_parameters.rinex_version = configuration->property(role + ".rinex_version", 3); - if (FLAGS_RINEX_version.compare("3.01") == 0) + if (FLAGS_RINEX_version == "3.01") { pvt_output_parameters.rinex_version = 3; } - else if (FLAGS_RINEX_version.compare("3.02") == 0) + else if (FLAGS_RINEX_version == "3.02") { pvt_output_parameters.rinex_version = 3; } - else if (FLAGS_RINEX_version.compare("3") == 0) + else if (FLAGS_RINEX_version == "3") { pvt_output_parameters.rinex_version = 3; } - else if (FLAGS_RINEX_version.compare("2.11") == 0) + else if (FLAGS_RINEX_version == "2.11") { pvt_output_parameters.rinex_version = 2; } - else if (FLAGS_RINEX_version.compare("2.10") == 0) + else if (FLAGS_RINEX_version == "2.10") { pvt_output_parameters.rinex_version = 2; } - else if (FLAGS_RINEX_version.compare("2") == 0) + else if (FLAGS_RINEX_version == "2") { pvt_output_parameters.rinex_version = 2; } @@ -220,11 +220,11 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, int positioning_mode = -1; std::string default_pos_mode("Single"); std::string positioning_mode_str = configuration->property(role + ".positioning_mode", default_pos_mode); // (PMODE_XXX) see src/algorithms/libs/rtklib/rtklib.h - if (positioning_mode_str.compare("Single") == 0) positioning_mode = PMODE_SINGLE; - if (positioning_mode_str.compare("Static") == 0) positioning_mode = PMODE_STATIC; - if (positioning_mode_str.compare("Kinematic") == 0) positioning_mode = PMODE_KINEMA; - if (positioning_mode_str.compare("PPP_Static") == 0) positioning_mode = PMODE_PPP_STATIC; - if (positioning_mode_str.compare("PPP_Kinematic") == 0) positioning_mode = PMODE_PPP_KINEMA; + if (positioning_mode_str == "Single") positioning_mode = PMODE_SINGLE; + if (positioning_mode_str == "Static") positioning_mode = PMODE_STATIC; + if (positioning_mode_str == "Kinematic") positioning_mode = PMODE_KINEMA; + if (positioning_mode_str == "PPP_Static") positioning_mode = PMODE_PPP_STATIC; + if (positioning_mode_str == "PPP_Kinematic") positioning_mode = PMODE_PPP_KINEMA; if (positioning_mode == -1) { @@ -269,12 +269,12 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, std::string default_iono_model("OFF"); std::string iono_model_str = configuration->property(role + ".iono_model", default_iono_model); /* (IONOOPT_XXX) see src/algorithms/libs/rtklib/rtklib.h */ int iono_model = -1; - if (iono_model_str.compare("OFF") == 0) iono_model = IONOOPT_OFF; - if (iono_model_str.compare("Broadcast") == 0) iono_model = IONOOPT_BRDC; - if (iono_model_str.compare("SBAS") == 0) iono_model = IONOOPT_SBAS; - if (iono_model_str.compare("Iono-Free-LC") == 0) iono_model = IONOOPT_IFLC; - if (iono_model_str.compare("Estimate_STEC") == 0) iono_model = IONOOPT_EST; - if (iono_model_str.compare("IONEX") == 0) iono_model = IONOOPT_TEC; + if (iono_model_str == "OFF") iono_model = IONOOPT_OFF; + if (iono_model_str == "Broadcast") iono_model = IONOOPT_BRDC; + if (iono_model_str == "SBAS") iono_model = IONOOPT_SBAS; + if (iono_model_str == "Iono-Free-LC") iono_model = IONOOPT_IFLC; + if (iono_model_str == "Estimate_STEC") iono_model = IONOOPT_EST; + if (iono_model_str == "IONEX") iono_model = IONOOPT_TEC; if (iono_model == -1) { //warn user and set the default @@ -288,11 +288,11 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, std::string default_trop_model("OFF"); int trop_model = -1; std::string trop_model_str = configuration->property(role + ".trop_model", default_trop_model); /* (TROPOPT_XXX) see src/algorithms/libs/rtklib/rtklib.h */ - if (trop_model_str.compare("OFF") == 0) trop_model = TROPOPT_OFF; - if (trop_model_str.compare("Saastamoinen") == 0) trop_model = TROPOPT_SAAS; - if (trop_model_str.compare("SBAS") == 0) trop_model = TROPOPT_SBAS; - if (trop_model_str.compare("Estimate_ZTD") == 0) trop_model = TROPOPT_EST; - if (trop_model_str.compare("Estimate_ZTD_Grad") == 0) trop_model = TROPOPT_ESTG; + if (trop_model_str == "OFF") trop_model = TROPOPT_OFF; + if (trop_model_str == "Saastamoinen") trop_model = TROPOPT_SAAS; + if (trop_model_str == "SBAS") trop_model = TROPOPT_SBAS; + if (trop_model_str == "Estimate_ZTD") trop_model = TROPOPT_EST; + if (trop_model_str == "Estimate_ZTD_Grad") trop_model = TROPOPT_ESTG; if (trop_model == -1) { //warn user and set the default @@ -337,11 +337,11 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, std::string default_gps_ar("Continuous"); std::string integer_ambiguity_resolution_gps_str = configuration->property(role + ".AR_GPS", default_gps_ar); /* Integer Ambiguity Resolution mode for GPS (0:off,1:continuous,2:instantaneous,3:fix and hold,4:ppp-ar) */ int integer_ambiguity_resolution_gps = -1; - if (integer_ambiguity_resolution_gps_str.compare("OFF") == 0) integer_ambiguity_resolution_gps = ARMODE_OFF; - if (integer_ambiguity_resolution_gps_str.compare("Continuous") == 0) integer_ambiguity_resolution_gps = ARMODE_CONT; - if (integer_ambiguity_resolution_gps_str.compare("Instantaneous") == 0) integer_ambiguity_resolution_gps = ARMODE_INST; - if (integer_ambiguity_resolution_gps_str.compare("Fix-and-Hold") == 0) integer_ambiguity_resolution_gps = ARMODE_FIXHOLD; - if (integer_ambiguity_resolution_gps_str.compare("PPP-AR") == 0) integer_ambiguity_resolution_gps = ARMODE_PPPAR; + if (integer_ambiguity_resolution_gps_str == "OFF") integer_ambiguity_resolution_gps = ARMODE_OFF; + if (integer_ambiguity_resolution_gps_str == "Continuous") integer_ambiguity_resolution_gps = ARMODE_CONT; + if (integer_ambiguity_resolution_gps_str == "Instantaneous") integer_ambiguity_resolution_gps = ARMODE_INST; + if (integer_ambiguity_resolution_gps_str == "Fix-and-Hold") integer_ambiguity_resolution_gps = ARMODE_FIXHOLD; + if (integer_ambiguity_resolution_gps_str == "PPP-AR") integer_ambiguity_resolution_gps = ARMODE_PPPAR; if (integer_ambiguity_resolution_gps == -1) { //warn user and set the default @@ -371,7 +371,7 @@ RtklibPvt::RtklibPvt(ConfigurationInterface* configuration, double min_ratio_to_fix_ambiguity = configuration->property(role + ".min_ratio_to_fix_ambiguity", 3.0); /* Set the integer ambiguity validation threshold for ratio‐test, which uses the ratio of squared residuals of the best integer vector to the second‐best vector. */ - int min_lock_to_fix_ambiguity = configuration->property(role + ".min_lock_to_fix_ambiguity", 0); /* Set the minimum lock count to fix integer ambiguity. + int min_lock_to_fix_ambiguity = configuration->property(role + ".min_lock_to_fix_ambiguity", 0); /* Set the minimum lock count to fix integer ambiguity.FLAGS_RINEX_version. If the lock count is less than the value, the ambiguity is excluded from the fixed integer vector. */ double min_elevation_to_fix_ambiguity = configuration->property(role + ".min_elevation_to_fix_ambiguity", 0.0); /* Set the minimum elevation (deg) to fix integer ambiguity. diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc index 96ed65700..b3e3b2b51 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc @@ -492,7 +492,7 @@ rtklib_pvt_cc::rtklib_pvt_cc(uint32_t nchannels, { xml_base_path = p.string(); } - if (xml_base_path.compare(".") != 0) + if (xml_base_path != ".") { std::cout << "XML files will be stored at " << xml_base_path << std::endl; } @@ -959,7 +959,13 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::map::const_iterator tmp_eph_iter_gal = d_pvt_solver->galileo_ephemeris_map.find(in[i][epoch].PRN); std::map::const_iterator tmp_eph_iter_cnav = d_pvt_solver->gps_cnav_ephemeris_map.find(in[i][epoch].PRN); std::map::const_iterator tmp_eph_iter_glo_gnav = d_pvt_solver->glonass_gnav_ephemeris_map.find(in[i][epoch].PRN); - if (((tmp_eph_iter_gps->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("1C") == 0)) or ((tmp_eph_iter_cnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("2S") == 0)) or ((tmp_eph_iter_gal->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("1B") == 0)) or ((tmp_eph_iter_gal->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("5X") == 0)) or ((tmp_eph_iter_glo_gnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("1G") == 0)) or ((tmp_eph_iter_glo_gnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("2G") == 0)) or ((tmp_eph_iter_cnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal).compare("L5") == 0))) + if (((tmp_eph_iter_gps->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "1C")) or + ((tmp_eph_iter_cnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "2S")) or + ((tmp_eph_iter_gal->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "1B")) or + ((tmp_eph_iter_gal->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "5X")) or + ((tmp_eph_iter_glo_gnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "1G")) or + ((tmp_eph_iter_glo_gnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "2G")) or + ((tmp_eph_iter_cnav->second.i_satellite_PRN == in[i][epoch].PRN) and (std::string(in[i][epoch].Signal) == "L5"))) { // store valid observables in a map. gnss_observables_map.insert(std::pair(i, in[i][epoch])); @@ -1893,7 +1899,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -1905,7 +1911,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); if (gal_eph_iter != d_pvt_solver->galileo_ephemeris_map.cend()) @@ -2013,7 +2019,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2025,7 +2031,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2073,7 +2079,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { // This is a channel with valid GPS signal gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2085,7 +2091,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2132,7 +2138,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2144,7 +2150,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2191,7 +2197,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { // This is a channel with valid GPS signal gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2203,7 +2209,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2250,7 +2256,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { // This is a channel with valid GPS signal gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2262,7 +2268,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); if (gps_eph_iter != d_pvt_solver->gps_ephemeris_map.cend()) @@ -2395,7 +2401,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2407,7 +2413,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); if (gal_eph_iter != d_pvt_solver->galileo_ephemeris_map.cend()) @@ -2513,7 +2519,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2525,7 +2531,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2573,7 +2579,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { // This is a channel with valid GPS signal gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2585,7 +2591,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2633,7 +2639,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2645,7 +2651,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2694,7 +2700,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { // This is a channel with valid GPS signal gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2706,7 +2712,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (glo_channel == 0) { - if (system.compare("R") == 0) + if (system == "R") { glonass_gnav_eph_iter = d_pvt_solver->glonass_gnav_ephemeris_map.find(gnss_observables_iter->second.PRN); if (glonass_gnav_eph_iter != d_pvt_solver->glonass_gnav_ephemeris_map.cend()) @@ -2754,7 +2760,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item std::string system(&gnss_observables_iter->second.System, 1); if (gps_channel == 0) { - if (system.compare("G") == 0) + if (system == "G") { // This is a channel with valid GPS signal gps_eph_iter = d_pvt_solver->gps_ephemeris_map.find(gnss_observables_iter->second.PRN); @@ -2766,7 +2772,7 @@ int rtklib_pvt_cc::work(int noutput_items, gr_vector_const_void_star& input_item } if (gal_channel == 0) { - if (system.compare("E") == 0) + if (system == "E") { gal_eph_iter = d_pvt_solver->galileo_ephemeris_map.find(gnss_observables_iter->second.PRN); if (gal_eph_iter != d_pvt_solver->galileo_ephemeris_map.cend()) diff --git a/src/core/libs/string_converter.cc b/src/core/libs/string_converter.cc index 8675c586c..7420aad64 100644 --- a/src/core/libs/string_converter.cc +++ b/src/core/libs/string_converter.cc @@ -34,17 +34,19 @@ #include -StringConverter::StringConverter() {} +StringConverter::StringConverter() = default; + + +StringConverter::~StringConverter() = default; -StringConverter::~StringConverter() {} bool StringConverter::convert(const std::string& value, bool default_value) { - if (value.compare("true") == 0) + if (value == "true") { return true; } - else if (value.compare("false") == 0) + else if (value == "false") { return false; }