Click here to Skip to main content
15,919,245 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to free library by dll self Pin
gucy24-Jun-03 17:52
gucy24-Jun-03 17:52 
AnswerRe: how to free library by dll self Pin
David Crow25-Jun-03 3:09
David Crow25-Jun-03 3:09 
QuestionApplication that handles 200 000+ Lines? Pin
Steve The Plant24-Jun-03 16:01
Steve The Plant24-Jun-03 16:01 
AnswerRe: Application that handles 200 000+ Lines? Pin
J. Dunlap24-Jun-03 16:14
J. Dunlap24-Jun-03 16:14 
GeneralRe: Application that handles 200 000+ Lines? Pin
Steve The Plant24-Jun-03 16:21
Steve The Plant24-Jun-03 16:21 
GeneralRe: Application that handles 200 000+ Lines? Pin
David Crow25-Jun-03 3:14
David Crow25-Jun-03 3:14 
AnswerRe: Application that handles 200 000+ Lines? Pin
Steve The Plant24-Jun-03 17:17
Steve The Plant24-Jun-03 17:17 
GeneralRe: Application that handles 200 000+ Lines? Pin
basementman25-Jun-03 5:11
basementman25-Jun-03 5:11 
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::CheckMatch(CommandObj *pCmdObj, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3)
{
  // you can extend this to do "like" clauses/pattern matching, etc...

  if (cpCommand && *cpCommand)
    {
      if (pCmdObj->Compare(cpCommand))
        return FALSE;
    }

  if (wpParam1)
    {
      if (*wpParam1 != pCmdObj->m_wParam1)
        return FALSE;
    }

  if (wpParam2)
    {
      if (*wpParam2 != pCmdObj->m_wParam2)
        return FALSE;
    }

  if (wpParam3)
    {
      if (*wpParam3 != pCmdObj->m_wParam3)
        return FALSE;
    }

  return TRUE;
}


This is like a little "hardcoded" isam file...only in memory.

 onwards and upwards... 
QuestionDrawing without flicker? Pin
Aidman24-Jun-03 15:25
Aidman24-Jun-03 15:25 
AnswerRe: Drawing without flicker? Pin
John M. Drescher24-Jun-03 15:45
John M. Drescher24-Jun-03 15:45 
AnswerRe: Drawing without flicker? Pin
Dave Bryant24-Jun-03 15:46
Dave Bryant24-Jun-03 15:46 
GeneralRe: Drawing without flicker? Pin
Aidman24-Jun-03 15:51
Aidman24-Jun-03 15:51 
GeneralRe: Drawing without flicker? Pin
John M. Drescher24-Jun-03 15:54
John M. Drescher24-Jun-03 15:54 
GeneralRe: Drawing without flicker? Pin
Aidman24-Jun-03 15:59
Aidman24-Jun-03 15:59 
GeneralRe: Drawing without flicker? Pin
J. Dunlap24-Jun-03 16:12
J. Dunlap24-Jun-03 16:12 
GeneralRe: Drawing without flicker? Pin
Ryan Binns24-Jun-03 16:13
Ryan Binns24-Jun-03 16:13 
GeneralRe: Drawing without flicker? Pin
John M. Drescher24-Jun-03 16:19
John M. Drescher24-Jun-03 16:19 
GeneralRe: Drawing without flicker? Pin
Ryan Binns24-Jun-03 16:21
Ryan Binns24-Jun-03 16:21 
Generalplay avi file and install codec for it Pin
Mohsen Saad24-Jun-03 15:17
Mohsen Saad24-Jun-03 15:17 
GeneralHelp!! CHTMLView inside CDialog Pin
crewchill24-Jun-03 14:09
crewchill24-Jun-03 14:09 
GeneralRe: Help!! CHTMLView inside CDialog Pin
Joan M24-Jun-03 20:34
professionalJoan M24-Jun-03 20:34 
GeneralRe: Help!! CHTMLView inside CDialog Pin
crewchill24-Jun-03 21:21
crewchill24-Jun-03 21:21 
GeneralLots'o'data... Pin
el davo24-Jun-03 13:25
el davo24-Jun-03 13:25 
GeneralRe: Lots'o'data... Pin
Dave Bryant24-Jun-03 14:34
Dave Bryant24-Jun-03 14:34 
QuestionWhat's wrong with this code? Pin
Jonathan Gilligan24-Jun-03 12:38
Jonathan Gilligan24-Jun-03 12:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.