X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=nameassignment.cpp;h=641be4e626fb9c52b9035a979acd95dbe654e35a;hb=3102812d94898439646131cecdb64fc542913c87;hp=42d374d0b9e74842e4d3f289c75ae61645556ebd;hpb=74844a60d80c6dd06e3fb02ee9b928424f9019b0;p=mothur.git diff --git a/nameassignment.cpp b/nameassignment.cpp index 42d374d..641be4e 100644 --- a/nameassignment.cpp +++ b/nameassignment.cpp @@ -17,19 +17,23 @@ void NameAssignment::readMap(){ string firstCol, secondCol, skip; // int index = 0; - -// map data; + + map::iterator itData; int rowIndex = 0; - + while(fileHandle){ fileHandle >> firstCol; //read from first column fileHandle >> secondCol; //read from second column + + itData = (*this).find(firstCol); + if (itData == (*this).end()) { + + (*this)[firstCol] = rowIndex++; + list.push_back(secondCol); //adds data's value to list + reverse[rowIndex] = firstCol; + + }else{ m->mothurOut(firstCol + " is already in namesfile. I will use first definition."); m->mothurOutEndLine(); } -// 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(); @@ -83,16 +87,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); + } } //**********************************************************************************************************************