M
Mike Copeland
I am converting an application element which currently is a fixed
array, sorted for searching by a binary search. Because I don't want to
maintain this process with a fixed array size limitation, I decided to
change it to use of an STL vector.
However, the binary search function is in a subprocess, and I'm
calling it with a parameter that returns the index of the matched
element. The function is a boolean function. Now that I've changed the
processing, I find that I don't know how to access the matched element
(if a match is made), because I'm using an iterator to search the
vector.
Is there a way I can return to the calling code an offset or index to
the matched vector element? TIA
Here's the search code:
bool findTeamId(int *pp) // Find Team Id
{
bool bFound = false;
string strTId = sTId;
strcpy(TeamId, copy(B40, 1, 26)), *pp = -1; // defaults
for(tIter = teamVector.begin(), bFound = false; tIter !=
teamVector.end(); tIter++)
{
if(strTId == tIter->teamCode)
{
// How can I assign pp - or is there another way to access the matched
// element?
return true;
}
}
return bFound;
}
And here is the global data definition:
struct TeamData
{
string teamCode; // Team Code (TId4)
string teamName; // Team's Name
bool isAdded; // Added to working stack of
teams
char teamTypeCode; // Team type Code
int teamMembers1; // Count of Team Members-1
int teamMembers2; // Count of Team Members-2
} ;
typedef vector<TeamData> TeamVector;
typedef TeamVector::iterator TeamIter;
extern TeamVector teamVector;
extern TeamIter tIter;
array, sorted for searching by a binary search. Because I don't want to
maintain this process with a fixed array size limitation, I decided to
change it to use of an STL vector.
However, the binary search function is in a subprocess, and I'm
calling it with a parameter that returns the index of the matched
element. The function is a boolean function. Now that I've changed the
processing, I find that I don't know how to access the matched element
(if a match is made), because I'm using an iterator to search the
vector.
Is there a way I can return to the calling code an offset or index to
the matched vector element? TIA
Here's the search code:
bool findTeamId(int *pp) // Find Team Id
{
bool bFound = false;
string strTId = sTId;
strcpy(TeamId, copy(B40, 1, 26)), *pp = -1; // defaults
for(tIter = teamVector.begin(), bFound = false; tIter !=
teamVector.end(); tIter++)
{
if(strTId == tIter->teamCode)
{
// How can I assign pp - or is there another way to access the matched
// element?
return true;
}
}
return bFound;
}
And here is the global data definition:
struct TeamData
{
string teamCode; // Team Code (TId4)
string teamName; // Team's Name
bool isAdded; // Added to working stack of
teams
char teamTypeCode; // Team type Code
int teamMembers1; // Count of Team Members-1
int teamMembers2; // Count of Team Members-2
} ;
typedef vector<TeamData> TeamVector;
typedef TeamVector::iterator TeamIter;
extern TeamVector teamVector;
extern TeamIter tIter;