]> git.donarmstrong.com Git - mothur.git/blobdiff - globaldata.cpp
fixed bug in libshuff
[mothur.git] / globaldata.cpp
index fe3c11b87dba7519ebec6c1e39168b764563233e..c2871694e2feaa9219ed5d31575e57a84a3022dc 100644 (file)
@@ -1,6 +1,9 @@
 
 
 #include "globaldata.hpp"
+#include "sharedlistvector.h"
+#include "inputdata.h"
+#include "fullmatrix.h"
 
 /*******************************************************/
 
@@ -24,12 +27,10 @@ string GlobalData::getNameFile()            {       return namefile;                }
 string GlobalData::getGroupFile()              {       return groupfile;               }
 string GlobalData::getOrderFile()              {       return orderfile;               }
 string GlobalData::getTreeFile()               {       return treefile;                }
-string GlobalData::getSharedFile()             {       return sharedfile;              }
-//string GlobalData::getFastaFile()            {       return fastafile;               }       
+string GlobalData::getSharedFile()             {       return sharedfile;              }       
 string GlobalData::getFormat()                 {       return format;                  }
 
 void GlobalData::setListFile(string file)              {       listfile = file;        inputFileName = file;                                   }
-//void GlobalData::setFastaFile(string file)           {       fastafile = file;       inputFileName = file;                                   }
 void GlobalData::setTreeFile(string file)              {       treefile = file;        inputFileName = file;                                   }
 void GlobalData::setRabundFile(string file)            {       rabundfile = file;      inputFileName = file;                                   }
 void GlobalData::setSabundFile(string file)            {       sabundfile = file;      inputFileName = file;                                   }
@@ -50,6 +51,17 @@ GlobalData::GlobalData() {
        clear();
        gListVector = NULL;             
        gSparseMatrix = NULL;   
+       ginput = NULL;
+       gorder = NULL;
+       glist = NULL;
+       gSharedList = NULL;
+       sabund = NULL;
+       rabund = NULL;
+       gGroupmap = NULL;
+       gMatrix = NULL;
+       gTreemap = NULL;
+       gSequenceDB = NULL;
+       nameMap = NULL;
 }
 /*******************************************************/
 
@@ -74,23 +86,46 @@ void GlobalData::clear() {
 
 /******************************************************/
 void GlobalData::newRead() {
-       try{
+       try{    
+                       //remove old file names
                        clear();
-                       gGroupmap = NULL;
-                       gListVector = NULL;
-                       gSparseMatrix = NULL;
+                       
+                       //free memory
+                       if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
+
+                       if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
+
+                       if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
+
+                       if (ginput != NULL) { delete ginput; ginput = NULL;}
+
+                       if (gorder != NULL) { delete gorder; gorder = NULL; }
+
+                       if (glist != NULL) { delete glist; glist = NULL;}
+
+                       if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
+
+                       if (sabund != NULL) { delete sabund; sabund = NULL;}
+
+                       if (rabund != NULL) { delete rabund; rabund = NULL; }
+
+                       if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
+
+                       if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
+
+                       if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
+                       
+                       if (nameMap != NULL) { delete nameMap; nameMap = NULL; }
+
+
                        gTree.clear();
                        Treenames.clear();
-                       labels.clear(); lines.clear(); Groups.clear();
+                       labels.clear(); Groups.clear();
                        allLines = 1;
                        runParse = true;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function newRead. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the GlobalData class function newRead. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "GlobalData", "newRead");
                exit(1);
        }
 }
@@ -100,9 +135,25 @@ void GlobalData::newRead() {
 /******************************************************/
 GlobalData::~GlobalData() {
        _uniqueInstance = 0;
-       if(gListVector != NULL)         {       delete gListVector;             }
-       if(gSparseMatrix != NULL)       {       delete gSparseMatrix;   }
-       if(gorder != NULL)                      {       delete gorder;          }
+       try {
+               if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
+               if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
+               if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
+               if (ginput != NULL) { delete ginput; ginput = NULL;}
+               if (gorder != NULL) { delete gorder; gorder = NULL; }
+               if (glist != NULL) { delete glist; glist = NULL;}
+               if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
+               if (sabund != NULL) { delete sabund; sabund = NULL;}
+               if (rabund != NULL) { delete rabund; rabund = NULL; }
+               if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
+               if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
+               if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
+               if (nameMap != NULL) { delete nameMap; nameMap = NULL; }
+       }
+       catch(exception& e) {
+               errorOut(e, "GlobalData", "~GlobalData");
+               exit(1);
+       }
 }
 /*******************************************************/