CMapStringToOb Mapping doesn't allow us to retrieve the objects in the order we added to the map...that is the sequence is not stored and it retrieves them randomly. True or false?
If true, any better suggestion as to what map can do it sequentially?
The [tt]CMapStringTo...[/tt] classes don't guarantee any order for the items, they are just "bags" (as the term used to be) into which you can dump stuff with a name and get them out with a name. Inside the bag, they're all jumbled up.
If you want a sequential list... ...not sure if there's a FIFO/LIFO map class in MFC, never had necessity to use one...
[tt]_______________________________________ Roger The Eileens are out there[/tt]
A solution is to put the sequence ( the order in which you add the objects to the map) in the key and the name of the key in the object associated with that key.
Something like :
CMyObjClass : public Cobject
{
public:
CMyObjClass( CString & s)
{
ObjName = s;
}
CString ObjName;
// other data
}
CMapStringToOb map;
CString key="1";
CMyObjClass o1 = new CMyObjClass("george"
map.Add(key,o1);
key = "2";
CMyObjClass o2 = new CMyObjClass("john"
map.Add(key,o2);
Lookup the map in the order of the sequence:
CMyObjClass *rObj=NULL;
CString sKey;
for (int i=0;i<map.GetCount();i++)
{
sKey.Format("%d",i);
Lookup(sKey, ( CObject*& ) &rObj);
if (rObj != NULL)
{
// process rObj->ObjName object with the "i" sequence
}
}
-obislavu-
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.