Death to stupid mussa pointers
authorDiane Trout <diane@caltech.edu>
Tue, 3 Oct 2006 00:11:04 +0000 (00:11 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 3 Oct 2006 00:11:04 +0000 (00:11 +0000)
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<Mussa>

14 files changed:
alg/mussa.hpp
alg/parse_options.cpp
alg/parse_options.hpp
qui/MussaAlignedWindow.cpp
qui/MussaAlignedWindow.hpp
qui/MussaWindow.cpp
qui/MussaWindow.hpp
qui/SubanalysisWindow.cpp
qui/motif_editor/MotifEditor.cpp
qui/motif_editor/MotifEditor.hpp
qui/mussa_setup_dialog/MussaSetupDialog.cpp
qui/mussa_setup_dialog/MussaSetupDialog.hpp
qui/mussa_setup_dialog/MussaSetupWidget.cpp
qui/mussa_setup_dialog/MussaSetupWidget.hpp

index 28c75ca28614ea6db87e4e70d8db8b154299c680..84fcd92ab9a0670416048a14b323c104202811c6 100644 (file)
@@ -221,4 +221,6 @@ public:
     void seqcomp();
 
 };
+//! provide a simple name to point to our Mussa shared_ptr
+typedef boost::shared_ptr<Mussa> MussaRef;
 #endif
index cc7ec632a48a884edbeca26350971b8a11aa162d..489fbfe32fd7ba24730a9189166e1f095ada4741 100644 (file)
@@ -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.
index 52445d06a8b40b5456a6160ae87f95ff3db6b442..25405a66c86978a76721aaf93c3ce14f3bbf92eb 100644 (file)
@@ -2,8 +2,7 @@
 #define _PARSE_OPTIONS_H_
 
 #include <string>
-
-class Mussa;
+#include <alg/mussa.hpp>
 
 //! 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?
index f418b02e8e7626e088030e4ff513153a90a0b8f4..65e3d7bf27df26328a92692ab7efbb2ecc1055e8 100644 (file)
@@ -12,8 +12,8 @@
 #include <iostream>
 using namespace std;
 
-MussaAlignedWindow::MussaAlignedWindow(Mussa& m, 
-                                       const set<int>& sel_paths, 
+MussaAlignedWindow::MussaAlignedWindow(MussaRef m, 
+                                       const set<int>& 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<int>& sel_paths)
+void MussaAlignedWindow::setSelectedPaths(MussaRef m, const set<int>& sel_paths)
 {
   // sets are sorted
   set<int>::iterator sel_i = sel_paths.begin();
-  list<ConservedPath>::const_iterator path_i = m.paths().refined_pathz.begin();
-  list<ConservedPath>::const_iterator path_end = m.paths().refined_pathz.end();
-  size_t path_size = m.paths().refined_pathz.size();
+  list<ConservedPath>::const_iterator path_i = m->paths().refined_pathz.begin();
+  list<ConservedPath>::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<ConservedPath::path_type>::const_iterator result_i = result.begin();
   list<vector<bool> >::const_iterator reversed_i = reversed.begin();
index 1e7139053776deeb493c6483a3037426c6d6f623..c4715f9106732cd9afc17d46a50e6532d9142ef0 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <set>
 
+#include <boost/shared_ptr.hpp>
+
 #include <QMainWindow>
 #include <QMenu>
 #include <QToolBar>
@@ -18,7 +20,11 @@ class MussaAlignedWindow : public QMainWindow
 
 public:
   //! construct an aligned window for an analysis and selected paths
-  MussaAlignedWindow(Mussa&, const std::set<int>&, 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<int>& 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<int>& sel_paths);
+  void setSelectedPaths(MussaRef m, const std::set<int>& 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<Sequence> sequences;
   //const std::set<int>& selected_paths;
   std::vector<ConservedPath> selected_paths;
index 8fa878e549bdcdd3a290861fa9393c1f6dbb6c91..cb3c2ce9295bc09daec97e4878e8d4f41c377420 100644 (file)
@@ -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<MussaAlignedWindow> ma_win( 
-      new MussaAlignedWindow(*analysis, selected_paths)
+      new MussaAlignedWindow(analysis, selected_paths)
     );
 
     aligned_windows.push_back(ma_win);
index 5adabde7a81553e7c808e7bebd1a42cb1b52c057..ed34adb5fe7647d5a219e6b688f9792bc2887b08 100644 (file)
@@ -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<boost::shared_ptr<MussaAlignedWindow> > aligned_windows;
index 5fdafcdb80a73824dd51693ed0429cea5c833d4e..34ef9aa9b0b2dbe8b778d69bdd22b46d4a28abfe 100644 (file)
@@ -80,8 +80,8 @@ void SubanalysisWindow::run()
                              "empty model now.");
   }
 
-  std::auto_ptr<Mussa> 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();
index 88713588e295d45c5b0cbb2229b6b92cb00c0d1a..e5e559eeb04bcbea5b5abe51be3ac5491993d5c6 100644 (file)
@@ -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)),
index b404dce967a8567de1c5f03b4d9d14036c3395bf..e8055bb264b09ccccdac50e81666a1bdd07c6297 100644 (file)
@@ -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;
index 80b33014c58c9628c62e1ac4d43c00b580dfa358..dcbd17957267e9906a7348659dc3fe7452642bb7 100644 (file)
@@ -35,7 +35,7 @@ void MussaSetupDialog::reject()
   done(0);
 }
 
-Mussa* MussaSetupDialog::getMussa()
+MussaRef MussaSetupDialog::getMussa()
 {
   return setupWidget->getMussaObject();
 }
index 2acc9714573f0fde75c5365ef863153869afca9b..48f365e7714578254939c009d0e49cda6e01d953 100644 (file)
@@ -4,8 +4,10 @@
 #include <QDialog>
 #include <QWidget>
 
+#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();
index e029b119284c42f0ef0c20e0a5877cbd104ccdb7..55d619921ce10735ae1111823c0d690457fe024e 100644 (file)
@@ -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;
index 6244b20cf49a015fd4508848724e14d8649480fc..f228f9ab7a3736a123d85a4b19754020c9631035 100644 (file)
@@ -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();