X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=nameassignment.cpp;h=126c4e0c594b6745ec6a7c4fcd5228c717d67677;hb=ccae9eef0b44f2d63fdf4a707d0d40243aa1b990;hp=0c30898dd4085f5000a68c005ccbeee1bcd3650c;hpb=e189982e0a9b7352ad57cc38ccee675f128be22e;p=mothur.git diff --git a/nameassignment.cpp b/nameassignment.cpp index 0c30898..126c4e0 100644 --- a/nameassignment.cpp +++ b/nameassignment.cpp @@ -6,7 +6,7 @@ NameAssignment::NameAssignment(string nameMapFile){ m = MothurOut::getInstance(); - openInputFile(nameMapFile, fileHandle); + m->openInputFile(nameMapFile, fileHandle); } @@ -22,7 +22,7 @@ void NameAssignment::readMap(){ int rowIndex = 0; while(fileHandle){ - fileHandle >> firstCol; //read from first column + fileHandle >> firstCol; m->gobble(fileHandle); //read from first column fileHandle >> secondCol; //read from second column itData = (*this).find(firstCol); @@ -34,7 +34,7 @@ void NameAssignment::readMap(){ }else{ m->mothurOut(firstCol + " is already in namesfile. I will use first definition."); m->mothurOutEndLine(); } - gobble(fileHandle); + m->gobble(fileHandle); } fileHandle.close(); @@ -76,6 +76,7 @@ void NameAssignment::print(ostream& out){ //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. + //out << it->first << '\t' << it->first << endl; } } catch(exception& e) { @@ -87,16 +88,35 @@ void NameAssignment::print(ostream& out){ //********************************************************************************************************************** int NameAssignment::get(string key){ - - return (*this)[key]; - + try { + map::iterator itGet = (*this).find(key); + + //if you can't find it + if (itGet == (*this).end()) { return -1; } + + return (*this)[key]; + } + catch(exception& e) { + m->errorOut(e, "NameAssignment", "get"); + exit(1); + } } //********************************************************************************************************************** string NameAssignment::get(int key){ + try { - return reverse[key]; - + map::iterator itGet = reverse.find(key); + + if (itGet == reverse.end()) { return "not found"; } + + return reverse[key]; + + } + catch(exception& e) { + m->errorOut(e, "NameAssignment", "get"); + exit(1); + } } //**********************************************************************************************************************