From 14970bf2c356286907d50d622aafc1edc1635473 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 31 Aug 2014 11:42:00 +0200 Subject: [PATCH] Changing raw pointers by smart pointers --- .../PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc | 41 ++++++++----------- .../PVT/gnuradio_blocks/galileo_e1_pvt_cc.h | 8 ++-- .../PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc | 18 ++++---- .../PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h | 8 ++-- src/algorithms/PVT/libs/kml_printer.cc | 37 ++++++++++------- src/algorithms/PVT/libs/kml_printer.h | 4 +- src/algorithms/PVT/libs/nmea_printer.cc | 2 +- src/algorithms/PVT/libs/nmea_printer.h | 8 ++-- 8 files changed, 62 insertions(+), 64 deletions(-) diff --git a/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc index eeb4e9217..163bc0a0d 100644 --- a/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc @@ -73,17 +73,17 @@ galileo_e1_pvt_cc::galileo_e1_pvt_cc(unsigned int nchannels, boost::shared_ptr(); + d_kml_dump->set_headers(kml_dump_filename); //initialize nmea_printer - d_nmea_printer = new Nmea_Printer(nmea_dump_filename, flag_nmea_tty_port, nmea_dump_devname); - + d_nmea_printer = std::make_shared(nmea_dump_filename, flag_nmea_tty_port, nmea_dump_devname); d_dump_filename.append("_raw.dat"); dump_ls_pvt_filename.append("_ls_pvt.dat"); d_averaging_depth = averaging_depth; d_flag_averaging = flag_averaging; - d_ls_pvt = new galileo_e1_ls_pvt(nchannels, dump_ls_pvt_filename, d_dump); + d_ls_pvt = std::make_shared(nchannels, dump_ls_pvt_filename, d_dump); d_ls_pvt->set_averaging_depth(d_averaging_depth); d_sample_counter = 0; @@ -91,7 +91,7 @@ galileo_e1_pvt_cc::galileo_e1_pvt_cc(unsigned int nchannels, boost::shared_ptr(); // ############# ENABLE DATA FILE LOG ################# if (d_dump == true) @@ -115,12 +115,7 @@ galileo_e1_pvt_cc::galileo_e1_pvt_cc(unsigned int nchannels, boost::shared_ptrprint_position_galileo(d_ls_pvt, d_flag_averaging); //ToDo: Implement Galileo RINEX and Galileo NMEA outputs // d_nmea_printer->Print_Nmea_Line(d_ls_pvt, d_flag_averaging); // - // if (!b_rinex_header_writen) // & we have utc data in nav message! - // { - // std::map::iterator gps_ephemeris_iter; - // gps_ephemeris_iter = d_ls_pvt->gps_ephemeris_map.begin(); - // if (gps_ephemeris_iter != d_ls_pvt->gps_ephemeris_map.end()) - // { - // rp->rinex_obs_header(rp->obsFile, gps_ephemeris_iter->second,d_rx_time); - // rp->rinex_nav_header(rp->navFile,d_ls_pvt->gps_iono, d_ls_pvt->gps_utc_model); - // b_rinex_header_writen = true; // do not write header anymore - // } - // } + // if (!b_rinex_header_writen) // & we have utc data in nav message! + // { + // std::map::iterator galileo_ephemeris_iter; + // galileo_ephemeris_iter = d_ls_pvt->galileo_ephemeris_map.begin(); + // if (galileo_ephemeris_iter != d_ls_pvt->galileo_ephemeris_map.end()) + // { + // rp->rinex_obs_header(rp->obsFile, galileo_ephemeris_iter->second, d_rx_time); + // rp->rinex_nav_header(rp->navFile, d_ls_pvt->galielo_iono, d_ls_pvt->galileo_utc_model); + // b_rinex_header_writen = true; // do not write header anymore + // } + // } // if(b_rinex_header_writen) // Put here another condition to separate annotations (e.g 30 s) // { // // Limit the RINEX navigation output rate to 1/6 seg diff --git a/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.h b/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.h index 9878de826..e99e4bf34 100644 --- a/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.h +++ b/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.h @@ -96,7 +96,7 @@ private: boost::shared_ptr d_queue; bool d_dump; bool b_rinex_header_writen; - Rinex_Printer *rp; + std::shared_ptr rp; unsigned int d_nchannels; std::string d_dump_filename; std::ofstream d_dump_file; @@ -106,10 +106,10 @@ private: int d_display_rate_ms; long unsigned int d_sample_counter; long unsigned int d_last_sample_nav_output; - Kml_Printer d_kml_dump; - Nmea_Printer *d_nmea_printer; + std::shared_ptr d_kml_dump; + std::shared_ptr d_nmea_printer; double d_rx_time; - galileo_e1_ls_pvt *d_ls_pvt; + std::shared_ptr d_ls_pvt; bool pseudoranges_pairCompare_min(std::pair a, std::pair b); public: diff --git a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc index 78deb9863..cfad74712 100644 --- a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc @@ -87,17 +87,18 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, std::string kml_dump_filename; kml_dump_filename = d_dump_filename; kml_dump_filename.append(".kml"); - d_kml_dump.set_headers(kml_dump_filename); + d_kml_dump = std::make_shared(); + d_kml_dump->set_headers(kml_dump_filename); //initialize nmea_printer - d_nmea_printer = new Nmea_Printer(nmea_dump_filename, flag_nmea_tty_port, nmea_dump_devname); + d_nmea_printer = std::make_shared(nmea_dump_filename, flag_nmea_tty_port, nmea_dump_devname); d_dump_filename.append("_raw.dat"); dump_ls_pvt_filename.append("_ls_pvt.dat"); d_averaging_depth = averaging_depth; d_flag_averaging = flag_averaging; - d_ls_pvt = new gps_l1_ca_ls_pvt(nchannels,dump_ls_pvt_filename,d_dump); + d_ls_pvt = std::make_shared((int)nchannels, dump_ls_pvt_filename, d_dump); d_ls_pvt->set_averaging_depth(d_averaging_depth); d_sample_counter = 0; @@ -106,7 +107,7 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, b_rinex_header_writen = false; b_rinex_sbs_header_writen = false; - rp = new Rinex_Printer(); + rp = std::make_shared(); // ############# ENABLE DATA FILE LOG ################# if (d_dump == true) @@ -130,12 +131,7 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, gps_l1_ca_pvt_cc::~gps_l1_ca_pvt_cc() -{ - d_kml_dump.close_file(); - delete d_ls_pvt; - delete rp; - delete d_nmea_printer; -} +{} @@ -237,7 +233,7 @@ int gps_l1_ca_pvt_cc::general_work (int noutput_items, gr_vector_int &ninput_ite pvt_result = d_ls_pvt->get_PVT(gnss_pseudoranges_map, d_rx_time, d_flag_averaging); if (pvt_result == true) { - d_kml_dump.print_position(d_ls_pvt, d_flag_averaging); + d_kml_dump->print_position(d_ls_pvt, d_flag_averaging); d_nmea_printer->Print_Nmea_Line(d_ls_pvt, d_flag_averaging); if (!b_rinex_header_writen) // & we have utc data in nav message! diff --git a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h index 441133992..a0f21308b 100644 --- a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h +++ b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h @@ -96,7 +96,7 @@ private: bool d_dump; bool b_rinex_header_writen; bool b_rinex_sbs_header_writen; - Rinex_Printer *rp; + std::shared_ptr rp; unsigned int d_nchannels; std::string d_dump_filename; std::ofstream d_dump_file; @@ -106,10 +106,10 @@ private: int d_display_rate_ms; long unsigned int d_sample_counter; long unsigned int d_last_sample_nav_output; - Kml_Printer d_kml_dump; - Nmea_Printer *d_nmea_printer; + std::shared_ptr d_kml_dump; + std::shared_ptr d_nmea_printer; double d_rx_time; - gps_l1_ca_ls_pvt *d_ls_pvt; + std::shared_ptr d_ls_pvt; public: ~gps_l1_ca_pvt_cc (); //!< Default destructor diff --git a/src/algorithms/PVT/libs/kml_printer.cc b/src/algorithms/PVT/libs/kml_printer.cc index eb9644ba5..8531ef8c7 100644 --- a/src/algorithms/PVT/libs/kml_printer.cc +++ b/src/algorithms/PVT/libs/kml_printer.cc @@ -82,22 +82,25 @@ bool Kml_Printer::set_headers(std::string filename) -bool Kml_Printer::print_position(gps_l1_ca_ls_pvt* position,bool print_average_values) +bool Kml_Printer::print_position(const std::shared_ptr& position, bool print_average_values) { double latitude; double longitude; double height; + + std::shared_ptr position_ = position; + if (print_average_values == false) { - latitude = position->d_latitude_d; - longitude = position->d_longitude_d; - height = position->d_height_m; + latitude = position_->d_latitude_d; + longitude = position_->d_longitude_d; + height = position_->d_height_m; } else { - latitude = position->d_avg_latitude_d; - longitude = position->d_avg_longitude_d; - height = position->d_avg_height_m; + latitude = position_->d_avg_latitude_d; + longitude = position_->d_avg_longitude_d; + height = position_->d_avg_height_m; } if (kml_file.is_open()) @@ -113,22 +116,23 @@ bool Kml_Printer::print_position(gps_l1_ca_ls_pvt* position,bool print_average_v //ToDo: make the class ls_pvt generic and heritate the particular gps/gal/glo ls_pvt in order to // reuse kml_printer functions -bool Kml_Printer::print_position_galileo(galileo_e1_ls_pvt* position,bool print_average_values) +bool Kml_Printer::print_position_galileo(const std::shared_ptr& position, bool print_average_values) { double latitude; double longitude; double height; + std::shared_ptr position_ = position; if (print_average_values == false) { - latitude = position->d_latitude_d; - longitude = position->d_longitude_d; - height = position->d_height_m; + latitude = position_->d_latitude_d; + longitude = position_->d_longitude_d; + height = position_->d_height_m; } else { - latitude = position->d_avg_latitude_d; - longitude = position->d_avg_longitude_d; - height = position->d_avg_height_m; + latitude = position_->d_avg_latitude_d; + longitude = position_->d_avg_longitude_d; + height = position_->d_avg_height_m; } if (kml_file.is_open()) @@ -167,5 +171,8 @@ Kml_Printer::Kml_Printer () {} -Kml_Printer::~Kml_Printer () {} +Kml_Printer::~Kml_Printer () +{ + close_file(); +} diff --git a/src/algorithms/PVT/libs/kml_printer.h b/src/algorithms/PVT/libs/kml_printer.h index 4638c09aa..6b6592081 100644 --- a/src/algorithms/PVT/libs/kml_printer.h +++ b/src/algorithms/PVT/libs/kml_printer.h @@ -51,8 +51,8 @@ private: std::ofstream kml_file; public: bool set_headers(std::string filename); - bool print_position(gps_l1_ca_ls_pvt* position, bool print_average_values); - bool print_position_galileo(galileo_e1_ls_pvt* position, bool print_average_values); + bool print_position(const std::shared_ptr& position, bool print_average_values); + bool print_position_galileo(const std::shared_ptr& position, bool print_average_values); bool close_file(); Kml_Printer(); ~Kml_Printer(); diff --git a/src/algorithms/PVT/libs/nmea_printer.cc b/src/algorithms/PVT/libs/nmea_printer.cc index 42f220ac3..8ea9f8174 100644 --- a/src/algorithms/PVT/libs/nmea_printer.cc +++ b/src/algorithms/PVT/libs/nmea_printer.cc @@ -132,7 +132,7 @@ void Nmea_Printer::close_serial () } -bool Nmea_Printer::Print_Nmea_Line(gps_l1_ca_ls_pvt* pvt_data, bool print_average_values) +bool Nmea_Printer::Print_Nmea_Line(const std::shared_ptr& pvt_data, bool print_average_values) { std::string GPRMC; std::string GPGGA; diff --git a/src/algorithms/PVT/libs/nmea_printer.h b/src/algorithms/PVT/libs/nmea_printer.h index 0a2c5e114..5d826c164 100644 --- a/src/algorithms/PVT/libs/nmea_printer.h +++ b/src/algorithms/PVT/libs/nmea_printer.h @@ -60,7 +60,7 @@ public: /*! * \brief Print NMEA PVT and satellite info to the initialized device */ - bool Print_Nmea_Line(gps_l1_ca_ls_pvt* position, bool print_average_values); + bool Print_Nmea_Line(const std::shared_ptr& position, bool print_average_values); /*! * \brief Default destructor. @@ -72,9 +72,9 @@ private: std::ofstream nmea_file_descriptor; // Output file stream for NMEA log file std::string nmea_devname; int nmea_dev_descriptor; // NMEA serial device descriptor (i.e. COM port) - gps_l1_ca_ls_pvt* d_PVT_data; - int init_serial (std::string serial_device); //serial port control - void close_serial (); + std::shared_ptr d_PVT_data; + int init_serial(std::string serial_device); //serial port control + void close_serial(); std::string get_GPGGA(); // fix data std::string get_GPGSV(); // satellite data std::string get_GPGSA(); // overall satellite reception data