Sounds like an excellent candidate for using a DATABASE. Like SQL Server. That's what these programs do for a living.... If you really need to do this yourself, you should probably create a series of memory structures to house the data and create indexes on the various fields. The MFC/OO approach would be to create objects similar to the following:
class CommandObj
{
public:
CString m_cCommandTime;
CString m_cCommandName;
WORD m_wParam1;
WORD m_wParam2;
WORD m_wParam3;
};
class CommandDB
{
BOOL CheckMatch(CommandObj *pCmdObj, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3);
public:
CObList m_oCommands; // list of Command objects
CMapStringToOb m_oCmdNameIndex; // index of cmd name to a CObList of Command objects that have this cmd name
CMapWordToOb m_oParam1Index; // index of param1 values to a CObList of Command objects that have this value
virtual ~CommandDB(); // clean up our lists
void AddCommandObj(CommandObj *pCmdObj);
BOOL SearchCommands(CObList *pOutputResults, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3);
};
void CommandDB::AddCommandObj(CommandObj *pCmdObj)
{
CObList *pIdxList = NULL;
// update our indexes...
if (!m_oCmdNameIndex.Lookup(pCmdObj->m_cCommandName,pIdxList))
{
pIdxList = new CObList;
m_oCmdNameIndex.SetAt(pCmdObj->m_cCommandName,pIdxList);
}
pIdxList->AddTail(pCmdObj);
if (!m_oParam1Index.Lookup(pCmdObj->m_wParam1,pIdxList))
{
pIdxList = new CObList;
m_oParam1Index.SetAt(pCmdObj->m_wParam1,pIdxList);
}
pIdxList->AddTail(pCmdObj);
// and add to "table"
m_oCommands.AddTail(pCmdObj);
}
BOOL CommandDB::SearchCommands(CObList *pOutputResults, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3)
{
BOOL bFound = TRUE;
CommandObj *pCmdObj;
CObList *pKeyList = NULL;
if (cpCommand != NULL && *cpCommand)
m_oCmdNameIndex.Lookup(cpCommand,pKeyList);
else if (wpParam1 != NULL)
m_oParam1Index.Lookup(*wpParam1,pKeyList);
else
pKeyList = &m_oCommands; // table scan time...
// scan keyset for matches
POSITION pPos = pKeyList->GetHeadPosition();
while (pPos)
{
pCmdObj = (CommandObj *)pKeyList->GetNext(pPos);
if (CheckMatch(pCmdObj,cpCommand,wpParam1,wpParam2,wpParam3))
{
bFound = TRUE;
pOutputResults->AddTail(pCmdObj);
}
}
return bFound;
}
BOOL CommandDB::Check