I'm having trouble workin with a simple CList:
the function always adds the first element twice and I don't know how.
also, the later added elements do not appear immediately in the list,
but only on the next function call...
here is the code:
----------------
CList<CASystem, CASystem> AllCAS;
CASystem *GetCreateCASystem(int ID)
{
bool bFound = false;
CASystem *pCAS = NULL;
// check if AS list exists
if(AllAS.IsEmpty())
{
// create new AS
pCAS = new CASystem;
pCAS->ID = ID;
AllCAS.AddHead(pCAS);
return pCAS;
}
else
{
// search for CAS
int i = 0;
POSITION pos = AllCAS.GetHeadPosition();
pCAS = AllCAS.GetHead();
while(i<AllCAS.GetCount())
{
if(pCAS->ID == ID)
{
// CAS already saved
bFound = true;
break;
}
else
{
i++;
pCAS = AllCAS.GetNext(pos);
}
}
// if no CAS yet, create CAS
if(!bFound)
{
// set new CAS and return it
pCAS = new CASystem;
pCAS->ID = ID;
AllCAS.AddTail(pCAS);
}
return pCAS;
}
}