Hello all, again.
I have the following code that searches a vector for a particular item. If it exists already in the vector, it doesn't add the current entry. Otherwise, it adds it:
Code:
if(mMapLinks.size() == 0)
mMapLinks.push_back(new mapLink(mFilesystem, target, type, x, y, width, height, dstx, dsty));
else
{
vector<mapLink*>::iterator i = mMapLinks.begin();
bool exists = false;
for(; i != mMapLinks.end(); i++)
{
if((*i)->getTargetMap() == target)
{
exists = true;
break;
}
}
if(!exists)
mMapLinks.push_back(new mapLink(mFilesystem, target, type, x, y, width, height, dstx, dsty));
}
where mMapLinks is defined as 'vector<mapLink*> mMapLinks' and target is defined as 'string'.
This code does the job but feels clunky and potentially inefficient. I'd like to stick with a vector as I need very fast linear iteration although I'm not opposed to other suggestions.