From cc7ad593973bcff9562c53ae42601d3f548d5ed3 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 3 Oct 2006 00:11:04 +0000 Subject: [PATCH] Death to stupid mussa pointers Long live smart pointers like boost::shared_ptr Go through mussa and replace references to Mussa * or Mussa & with a typedef MussaRef which is defined as boost::shared_ptr --- alg/mussa.hpp | 2 ++ alg/parse_options.cpp | 8 +++--- alg/parse_options.hpp | 5 ++-- qui/MussaAlignedWindow.cpp | 24 ++++++++--------- qui/MussaAlignedWindow.hpp | 12 ++++++--- qui/MussaWindow.cpp | 30 ++++++++++----------- qui/MussaWindow.hpp | 8 +++--- qui/SubanalysisWindow.cpp | 6 ++--- qui/motif_editor/MotifEditor.cpp | 2 +- qui/motif_editor/MotifEditor.hpp | 4 +-- qui/mussa_setup_dialog/MussaSetupDialog.cpp | 2 +- qui/mussa_setup_dialog/MussaSetupDialog.hpp | 6 +++-- qui/mussa_setup_dialog/MussaSetupWidget.cpp | 4 +-- qui/mussa_setup_dialog/MussaSetupWidget.hpp | 4 +-- 14 files changed, 63 insertions(+), 54 deletions(-) diff --git a/alg/mussa.hpp b/alg/mussa.hpp index 28c75ca..84fcd92 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -221,4 +221,6 @@ public: void seqcomp(); }; +//! provide a simple name to point to our Mussa shared_ptr +typedef boost::shared_ptr MussaRef; #endif diff --git a/alg/parse_options.cpp b/alg/parse_options.cpp index cc7ec63..489fbfe 100644 --- a/alg/parse_options.cpp +++ b/alg/parse_options.cpp @@ -8,8 +8,7 @@ namespace po = boost::program_options; #include "alg/parse_options.hpp" MussaOptions::MussaOptions() - : analysis(0), - useGUI(true), + : useGUI(true), runAsPythonInterpeter(false) { } @@ -38,8 +37,9 @@ void initialize_mussa(MussaOptions& opts, int argc, char **argv) std::cout << options << std::endl; return; } - - opts.analysis = new Mussa(); + + MussaRef new_mussa(new Mussa); + opts.analysis = new_mussa; // currently we can only have one analysis loaded, so // running trumps viewing. diff --git a/alg/parse_options.hpp b/alg/parse_options.hpp index 52445d0..25405a6 100644 --- a/alg/parse_options.hpp +++ b/alg/parse_options.hpp @@ -2,8 +2,7 @@ #define _PARSE_OPTIONS_H_ #include - -class Mussa; +#include //! collect information about runtime options struct MussaOptions @@ -12,7 +11,7 @@ struct MussaOptions MussaOptions(); //! pointer to our analysis, if its null, feel free to die - Mussa *analysis; + MussaRef analysis; //! Location of documentation std::string doc_dir; //! should we use the gui? diff --git a/qui/MussaAlignedWindow.cpp b/qui/MussaAlignedWindow.cpp index f418b02..65e3d7b 100644 --- a/qui/MussaAlignedWindow.cpp +++ b/qui/MussaAlignedWindow.cpp @@ -12,8 +12,8 @@ #include using namespace std; -MussaAlignedWindow::MussaAlignedWindow(Mussa& m, - const set& sel_paths, +MussaAlignedWindow::MussaAlignedWindow(MussaRef m, + const set& sel_paths, QWidget *parent) : QMainWindow(parent), analysis(m), @@ -23,8 +23,8 @@ MussaAlignedWindow::MussaAlignedWindow(Mussa& m, alignTB(0) { setupActions(); - browser.setSequences(analysis.sequences(), analysis.colorMapper()); - setSelectedPaths(m, sel_paths); + browser.setSequences(analysis->sequences(), analysis->colorMapper()); + setSelectedPaths(analysis, sel_paths); setAlignment(0); double zoom_level = browser.zoomToSequence(); @@ -107,13 +107,13 @@ void MussaAlignedWindow::setupAlignmentMenus() } -void MussaAlignedWindow::setSelectedPaths(Mussa &m, const set& sel_paths) +void MussaAlignedWindow::setSelectedPaths(MussaRef m, const set& sel_paths) { // sets are sorted set::iterator sel_i = sel_paths.begin(); - list::const_iterator path_i = m.paths().refined_pathz.begin(); - list::const_iterator path_end = m.paths().refined_pathz.end(); - size_t path_size = m.paths().refined_pathz.size(); + list::const_iterator path_i = m->paths().refined_pathz.begin(); + list::const_iterator path_end = m->paths().refined_pathz.end(); + size_t path_size = m->paths().refined_pathz.size(); size_t pathid=0; selected_paths.reserve(sel_paths.size()); @@ -175,10 +175,10 @@ void MussaAlignedWindow::computeMatchLines() if (view_paths[count]) filtered_paths.push_back(*path_i); } - analysis.createLocalAlignment(filtered_paths.begin(), - filtered_paths.end(), - result, - reversed); + analysis->createLocalAlignment(filtered_paths.begin(), + filtered_paths.end(), + result, + reversed); list::const_iterator result_i = result.begin(); list >::const_iterator reversed_i = reversed.begin(); diff --git a/qui/MussaAlignedWindow.hpp b/qui/MussaAlignedWindow.hpp index 1e71390..c4715f9 100644 --- a/qui/MussaAlignedWindow.hpp +++ b/qui/MussaAlignedWindow.hpp @@ -3,6 +3,8 @@ #include +#include + #include #include #include @@ -18,7 +20,11 @@ class MussaAlignedWindow : public QMainWindow public: //! construct an aligned window for an analysis and selected paths - MussaAlignedWindow(Mussa&, const std::set&, QWidget *parent=0); + /*! \param analysis is a shared_ptr to a mussa analysis + * \param paths is a set of "paths" AKA integer offsets into the sequences stored in mussa + * \param parent is the typical Qt pointer to a parent widget + */ + MussaAlignedWindow(MussaRef analysis, const std::set& paths, QWidget *parent=0); public slots: //! use selected_paths[pathid] to set the starting position of our sequence @@ -31,7 +37,7 @@ public slots: protected: // figure out what Alignments we have (needed for setupAlignmentMenus) - void setSelectedPaths(Mussa &m, const std::set& sel_paths); + void setSelectedPaths(MussaRef m, const std::set& sel_paths); // create our cations void setupActions(); // create our menus @@ -40,7 +46,7 @@ protected: void setupAlignmentMenus(); void computeMatchLines(); - Mussa& analysis; + MussaRef analysis; //std::vector sequences; //const std::set& selected_paths; std::vector selected_paths; diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 8fa878e..cb3c2ce 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -29,7 +29,7 @@ namespace fs = boost::filesystem; using namespace std; -MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : +MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) : QMainWindow(parent), analysis(analysis_), default_dir(QDir::home().absolutePath().toStdString(), fs::native), @@ -91,19 +91,21 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : addToolBar(mussaViewTB); statusBar()->showMessage("Welcome to mussa", 2000); - connect(analysis, SIGNAL(progress(const std::string&, int, int)), - this, SLOT(updateProgress(const std::string&, int, int))); + // FIXME: we should start refactoring the connect call to updateAnalysis or something + if (analysis) { + connect(analysis.get(), SIGNAL(progress(const std::string&, int, int)), + this, SLOT(updateProgress(const std::string&, int, int))); + } updateTitle(); updateAnalysis(); } -void MussaWindow::setAnalysis(Mussa *new_analysis) +void MussaWindow::setAnalysis(MussaRef new_analysis) { if (new_analysis != 0) { // only switch mussas if we loaded without error clear(); - delete analysis; - analysis = new_analysis; + analysis.swap(new_analysis); updateTitle(); updateAnalysis(); } @@ -304,9 +306,7 @@ void MussaWindow::createNewAnalysis() if (not isClearingAnalysisSafe()) return; if (setup_analysis_dialog->exec()) { - Mussa *m = 0; - m = setup_analysis_dialog->getMussa(); - setAnalysis(m); + setAnalysis(setup_analysis_dialog->getMussa()); } } catch(mussa_error e) { QString msg(e.what()); @@ -476,9 +476,9 @@ void MussaWindow::loadMupa() // but this should work for the moment. if (not isClearingAnalysisSafe()) return; - Mussa *m = new Mussa; + MussaRef m(new Mussa); fs::path converted_path(mupa_path.toStdString(), fs::native); - connect(m, SIGNAL(progress(const std::string&, int, int)), + connect(m.get(), SIGNAL(progress(const std::string&, int, int)), this, SLOT(updateProgress(const std::string&, int, int))); m->load_mupa_file(converted_path); m->analyze(); @@ -514,9 +514,9 @@ void MussaWindow::loadSavedAnalysis() // but this should work for the moment. if (not isClearingAnalysisSafe()) return; - Mussa *m = new Mussa; + MussaRef m(new Mussa); fs::path converted_path(muway_dir.toStdString(), fs::native); - connect(m, SIGNAL(progress(const std::string&, int, int)), + connect(m.get(), SIGNAL(progress(const std::string&, int, int)), this, SLOT(updateProgress(const std::string&, int, int))); m->load(converted_path); // only switch mussas if we loaded without error @@ -543,7 +543,7 @@ void MussaWindow::loadSavedAnalysis() void MussaWindow::newMussaWindow() { - Mussa *a = new Mussa(); + MussaRef a(new Mussa); MussaWindow *win = new MussaWindow(a); win->default_dir = default_dir; win->show(); @@ -609,7 +609,7 @@ void MussaWindow::viewMussaAlignment() "first")); } else { boost::shared_ptr ma_win( - new MussaAlignedWindow(*analysis, selected_paths) + new MussaAlignedWindow(analysis, selected_paths) ); aligned_windows.push_back(ma_win); diff --git a/qui/MussaWindow.hpp b/qui/MussaWindow.hpp index 5adabde..ed34adb 100644 --- a/qui/MussaWindow.hpp +++ b/qui/MussaWindow.hpp @@ -30,13 +30,13 @@ class MussaWindow : public QMainWindow Q_OBJECT public: - MussaWindow(Mussa* analysis=0, QWidget *parent=0); + MussaWindow(MussaRef analysis=0, QWidget *parent=0); //! reset any attached window void clear(); //! switch to a new analysis - void setAnalysis(Mussa *new_analysis); + void setAnalysis(MussaRef new_analysis); //! ask the user what to do if we're going to lose data //! returns true if getting rid of this analysis is safe @@ -95,8 +95,8 @@ signals: void changedAnnotations(); protected: - //! reference to our analysis - Mussa *analysis; + //! shared_ptr to our analysis + MussaRef analysis; //! the default directory we should loand and save from boost::filesystem::path default_dir; std::list > aligned_windows; diff --git a/qui/SubanalysisWindow.cpp b/qui/SubanalysisWindow.cpp index 5fdafcd..34ef9aa 100644 --- a/qui/SubanalysisWindow.cpp +++ b/qui/SubanalysisWindow.cpp @@ -80,8 +80,8 @@ void SubanalysisWindow::run() "empty model now."); } - std::auto_ptr m(new Mussa); - + MussaRef m(new Mussa); + for(SequenceLocationModel::iterator itor = model.begin(); itor != model.end(); ++itor) @@ -94,7 +94,7 @@ void SubanalysisWindow::run() m->set_window(window->value()); m->set_threshold(threshold->value()); m->analyze(); - MussaWindow *mw = new MussaWindow(m.get()); + MussaWindow *mw = new MussaWindow(m); mw->show(); model.clear(); hide(); diff --git a/qui/motif_editor/MotifEditor.cpp b/qui/motif_editor/MotifEditor.cpp index 8871358..e5e559e 100644 --- a/qui/motif_editor/MotifEditor.cpp +++ b/qui/motif_editor/MotifEditor.cpp @@ -6,7 +6,7 @@ using namespace std; -MotifEditor::MotifEditor(Mussa *m, QWidget *parent) +MotifEditor::MotifEditor(MussaRef m, QWidget *parent) : QWidget(parent), analysis(m), editor_layout(new QVBoxLayout(parent)), diff --git a/qui/motif_editor/MotifEditor.hpp b/qui/motif_editor/MotifEditor.hpp index b404dce..e8055bb 100644 --- a/qui/motif_editor/MotifEditor.hpp +++ b/qui/motif_editor/MotifEditor.hpp @@ -17,7 +17,7 @@ class MotifEditor : public QWidget Q_OBJECT public: - MotifEditor(Mussa* m, QWidget *parent=0); + MotifEditor(MussaRef m, QWidget *parent=0); //! update our window title void updateTitle(); @@ -35,7 +35,7 @@ signals: void changedMotifs(); private: - Mussa* analysis; + MussaRef analysis; QPushButton *applyButton; QVBoxLayout *editor_layout; diff --git a/qui/mussa_setup_dialog/MussaSetupDialog.cpp b/qui/mussa_setup_dialog/MussaSetupDialog.cpp index 80b3301..dcbd179 100644 --- a/qui/mussa_setup_dialog/MussaSetupDialog.cpp +++ b/qui/mussa_setup_dialog/MussaSetupDialog.cpp @@ -35,7 +35,7 @@ void MussaSetupDialog::reject() done(0); } -Mussa* MussaSetupDialog::getMussa() +MussaRef MussaSetupDialog::getMussa() { return setupWidget->getMussaObject(); } diff --git a/qui/mussa_setup_dialog/MussaSetupDialog.hpp b/qui/mussa_setup_dialog/MussaSetupDialog.hpp index 2acc971..48f365e 100644 --- a/qui/mussa_setup_dialog/MussaSetupDialog.hpp +++ b/qui/mussa_setup_dialog/MussaSetupDialog.hpp @@ -4,8 +4,10 @@ #include #include +#include "alg/mussa.hpp" + class MussaSetupWidget; -class Mussa; + class MussaSetupDialog : public QDialog { @@ -14,7 +16,7 @@ class MussaSetupDialog : public QDialog public: MussaSetupDialog(QWidget *parent = 0, Qt::WFlags f = 0); - Mussa* getMussa(); + MussaRef getMussa(); public slots: void accept(); diff --git a/qui/mussa_setup_dialog/MussaSetupWidget.cpp b/qui/mussa_setup_dialog/MussaSetupWidget.cpp index e029b11..55d6199 100644 --- a/qui/mussa_setup_dialog/MussaSetupWidget.cpp +++ b/qui/mussa_setup_dialog/MussaSetupWidget.cpp @@ -97,9 +97,9 @@ void MussaSetupWidget::mussaCancelPushed() emit cancelButtonPushed(); } -Mussa* MussaSetupWidget::getMussaObject() +MussaRef MussaSetupWidget::getMussaObject() { - Mussa *mussa = new Mussa; + MussaRef mussa(new Mussa); int fastaIndex; int start; diff --git a/qui/mussa_setup_dialog/MussaSetupWidget.hpp b/qui/mussa_setup_dialog/MussaSetupWidget.hpp index 6244b20..f228f9a 100644 --- a/qui/mussa_setup_dialog/MussaSetupWidget.hpp +++ b/qui/mussa_setup_dialog/MussaSetupWidget.hpp @@ -8,7 +8,7 @@ class SequenceSetupFrame; -class Mussa; +#include "alg/mussa.hpp" class MussaSetupWidget : public QWidget { @@ -18,7 +18,7 @@ public: MussaSetupWidget(QWidget *parent = 0); // MussaSetupWidget(const MussaSetupWidget&); - Mussa* getMussaObject(); + MussaRef getMussaObject(); signals: void createButtonPushed(); -- 2.30.2