X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=nameassignment.cpp;h=bc088f45924f4af9db951e81882376cd64fbc8f0;hb=5f44783e6d74a9c207492ac244210c915cadc272;hp=cd9ef4e0381a0a8ec384482b26d1966bb3388763;hpb=bfbc55964f1977da72c2cea984288a427d370a59;p=mothur.git diff --git a/nameassignment.cpp b/nameassignment.cpp index cd9ef4e..bc088f4 100644 --- a/nameassignment.cpp +++ b/nameassignment.cpp @@ -1,4 +1,4 @@ -using namespace std; + #include "nameassignment.hpp" @@ -12,44 +12,46 @@ NameAssignment::NameAssignment(string nameMapFile){ //********************************************************************************************************************** -void NameAssignment::readMap(int colA, int colB){ +void NameAssignment::readMap(){ try{ string firstCol, secondCol, skip; // int index = 0; - int skipNCols = colB-colA-1; - - map data; +// map data; + int rowIndex = 0; + while(fileHandle){ fileHandle >> firstCol; //read from first column - - for(int i=0;i> skip; - } - fileHandle >> secondCol; //read from second column - - data[firstCol] = secondCol; //store data in map - + +// data[firstCol] = secondCol; //store data in map + + list.push_back(secondCol); //adds data's value to list + reverse[rowIndex] = firstCol; + (*this)[firstCol] = rowIndex++; gobble(fileHandle); } fileHandle.close(); - int rowIndex = 0; - map::iterator it = data.begin(); - for(it;it!=data.end();it++){ - list.push_back(it->second); //adds data's value to list - (*this)[it->first] = rowIndex; - rowIndex++; - } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "NameAssignment", "readMap"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the NameAssignment class function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +//********************************************************************************************************************** +void NameAssignment::push_back(string name) { + try{ + + int num = (*this).size(); + (*this)[name] = num; + reverse[num] = name; + + list.push_back(name); + } + catch(exception& e) { + errorOut(e, "NameAssignment", "push_back"); exit(1); } } @@ -64,19 +66,16 @@ ListVector NameAssignment::getListVector(void){ //********************************************************************************************************************** -void NameAssignment::print(void){ +void NameAssignment::print(ostream& out){ try { - map::iterator it = (*this).begin(); - for(it;it!=(*this).end();it++){ - cout << it->first << '\t' << it->second << endl; //prints out keys and values of the map this. + map::iterator it; +//cout << (*this).size() << endl; + for(it = (*this).begin(); it!=(*this).end(); it++){ + out << it->first << '\t' << it->second << endl; //prints out keys and values of the map this. } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the NameAssignment class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "NameAssignment", "print"); exit(1); } } @@ -88,6 +87,12 @@ int NameAssignment::get(string key){ return (*this)[key]; } +//********************************************************************************************************************** +string NameAssignment::get(int key){ + + return reverse[key]; + +} //**********************************************************************************************************************