Skip to content

Commit

Permalink
Changed plugins list from an MFC list to a STL list
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Sep 19, 2010
1 parent 5de14b9 commit 00fa603
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 128 deletions.
2 changes: 1 addition & 1 deletion OtherTypes.h
Expand Up @@ -936,7 +936,7 @@ class CMapDirection
}; // end of class CMapDirection

typedef map<string, CMapDirection> CMapDirectionsMap;
typedef map<string, CMapDirection>::const_iterator MapDirectionsIterator;
typedef CMapDirectionsMap::const_iterator MapDirectionsIterator;

extern CMapDirectionsMap MapDirectionsMap;

Expand Down
42 changes: 28 additions & 14 deletions ProcessPreviousLine.cpp
Expand Up @@ -582,23 +582,35 @@ assemble the full text of the original line.
m_CurrentPlugin = NULL;
// do main triggers
ProcessOneTriggerSequence (strCurrentLine,
StyledLine,
strResponse,
prevpos,
bNoLog, bNoOutput, bChangedColour,
triggerList, strExtraOutput, mapDeferredScripts, mapOneShotItems);
StyledLine,
strResponse,
prevpos,
bNoLog,
bNoOutput,
bChangedColour,
triggerList,
strExtraOutput,
mapDeferredScripts,
mapOneShotItems);

// do plugins
for (pos = m_PluginList.GetHeadPosition (); pos; )
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = m_PluginList.GetNext (pos);
m_CurrentPlugin = *pit;
if (m_CurrentPlugin->m_bEnabled)
ProcessOneTriggerSequence (strCurrentLine,
StyledLine,
strResponse,
prevpos,
bNoLog, bNoOutput, bChangedColour,
triggerList, strExtraOutput, mapDeferredScripts, mapOneShotItems);
StyledLine,
strResponse,
prevpos,
bNoLog,
bNoOutput,
bChangedColour,
triggerList,
strExtraOutput,
mapDeferredScripts,
mapOneShotItems);
} // end of doing each plugin

m_CurrentPlugin = NULL; // not in a plugin any more
Expand Down Expand Up @@ -846,9 +858,11 @@ assemble the full text of the original line.
}

// do plugins
for (POSITION plugin_pos = m_PluginList.GetHeadPosition (); !bFoundIt && plugin_pos; )
for (PluginListIterator pit = m_PluginList.begin ();
!bFoundIt && pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = m_PluginList.GetNext (plugin_pos);
m_CurrentPlugin = *pit;

if (m_CurrentPlugin->m_bEnabled)
for (iItem = 0; !bFoundIt && iItem < GetTriggerArray ().GetSize (); iItem++)
Expand Down
52 changes: 33 additions & 19 deletions dialogs/plugins/PluginsDlg.cpp
Expand Up @@ -184,14 +184,15 @@ void CPluginsDlg::LoadList (void)

int nItem = 0;

m_ctlPluginList.DeleteAllItems ();
m_ctlPluginList.DeleteAllItems ();

for (POSITION pos = m_pDoc->m_PluginList.GetHeadPosition(); pos; nItem++)
for (PluginListIterator pit = m_pDoc->m_PluginList.begin ();
pit != m_pDoc->m_PluginList.end ();
++pit, nItem++)
{
CPlugin * p = m_pDoc->m_PluginList.GetNext (pos);
CPlugin * p = *pit;

m_ctlPluginList.InsertItem (nItem, p->m_strName); // eColumnName

m_ctlPluginList.SetItemText (nItem, eColumnPurpose, p->m_strPurpose);
m_ctlPluginList.SetItemText (nItem, eColumnAuthor, p->m_strAuthor);
m_ctlPluginList.SetItemText (nItem, eColumnLanguage, p->m_strLanguage);
Expand Down Expand Up @@ -401,11 +402,13 @@ int nItem,

CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);

POSITION pos = m_pDoc->m_PluginList.Find (p);
PluginListIterator pit = find (m_pDoc->m_PluginList.begin (),
m_pDoc->m_PluginList.end (),
p);

if (pos)
if (pit != m_pDoc->m_PluginList.end ())
{
m_pDoc->m_PluginList.RemoveAt (pos); // remove from list
m_pDoc->m_PluginList.erase (pit); // remove from list
delete p; // delete the plugin
bChanged = true;
}
Expand Down Expand Up @@ -475,12 +478,15 @@ for (int nItem = -1;

CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);

POSITION pos = m_pDoc->m_PluginList.Find (p);

if (pos)
PluginListIterator pit = find (m_pDoc->m_PluginList.begin (),
m_pDoc->m_PluginList.end (),
p);

if (pit != m_pDoc->m_PluginList.end ())
{
CString strName = p->m_strSource;
m_pDoc->m_PluginList.RemoveAt (pos); // remove from list
m_pDoc->m_PluginList.erase (pit); // remove from list
delete p; // delete the plugin

try
Expand Down Expand Up @@ -567,9 +573,11 @@ for (int nItem = -1;

CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);

POSITION pos = m_pDoc->m_PluginList.Find (p);
PluginListIterator pit = find (m_pDoc->m_PluginList.begin (),
m_pDoc->m_PluginList.end (),
p);

if (!pos)
if (pit == m_pDoc->m_PluginList.end ())
continue;

EditPlugin (p->m_strSource);
Expand Down Expand Up @@ -681,9 +689,11 @@ void CPluginsDlg::OnRdblclkPluginsList(NMHDR* pNMHDR, LRESULT* pResult)

CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);

POSITION pos = m_pDoc->m_PluginList.Find (p);
PluginListIterator pit = find (m_pDoc->m_PluginList.begin (),
m_pDoc->m_PluginList.end (),
p);

if (!pos)
if (pit == m_pDoc->m_PluginList.end ())
continue;

// need a directory
Expand Down Expand Up @@ -731,9 +741,11 @@ for (int nItem = -1;

CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);

POSITION pos = m_pDoc->m_PluginList.Find (p);
PluginListIterator pit = find (m_pDoc->m_PluginList.begin (),
m_pDoc->m_PluginList.end (),
p);

if (!pos)
if (pit == m_pDoc->m_PluginList.end ())
continue;

m_pDoc->EnablePlugin (p->m_strID, TRUE);
Expand All @@ -758,10 +770,12 @@ for (int nItem = -1;

CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);

POSITION pos = m_pDoc->m_PluginList.Find (p);
PluginListIterator pit = find (m_pDoc->m_PluginList.begin (),
m_pDoc->m_PluginList.end (),
p);

if (!pos)
continue;
if (pit == m_pDoc->m_PluginList.end ())
continue;

m_pDoc->EnablePlugin (p->m_strID, FALSE);
bChanged = true;
Expand Down
26 changes: 17 additions & 9 deletions doc.cpp
Expand Up @@ -820,7 +820,7 @@ void CMUSHclientDoc::SetUpOutputWindow (void)
{

vector<string> v;
POSITION pos;
PluginListIterator pit;

StringToVector ((LPCTSTR) App.m_strPluginList, v, "*");

Expand All @@ -830,9 +830,11 @@ void CMUSHclientDoc::SetUpOutputWindow (void)
bool bAlreadyLoaded = false;

// see if we already have this one
for (pos = m_PluginList.GetHeadPosition(); pos; )
for (pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
{
CPlugin * p = m_PluginList.GetNext (pos);
CPlugin * p = *pit;

if (p->m_strSource == strPath)
{
Expand All @@ -846,9 +848,11 @@ void CMUSHclientDoc::SetUpOutputWindow (void)
{
InternalLoadPlugin (strPath);
// mark it as loaded globally
for (pos = m_PluginList.GetHeadPosition(); pos; )
for (pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
{
CPlugin * p = m_PluginList.GetNext (pos);
CPlugin * p = *pit;

if (p->m_strSource == strPath)
{
Expand Down Expand Up @@ -4707,9 +4711,11 @@ void CMUSHclientDoc::CheckTimers ()

CheckTimerList (GetTimerMap ());
// do plugins
for (POSITION pos = m_PluginList.GetHeadPosition (); pos; )
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = m_PluginList.GetNext (pos);
m_CurrentPlugin = *pit;
if (m_CurrentPlugin->m_bEnabled)
CheckTimerList (GetTimerMap ());
} // end of doing each plugin
Expand Down Expand Up @@ -5158,9 +5164,11 @@ void CMUSHclientDoc::OnGameResetalltimers()
{
ResetAllTimers (GetTimerMap ());
// do plugins
for (POSITION pos = m_PluginList.GetHeadPosition (); pos; )
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = m_PluginList.GetNext (pos);
m_CurrentPlugin = *pit;
if (m_CurrentPlugin->m_bEnabled)
ResetAllTimers (GetTimerMap ());
} // end of doing each plugin
Expand Down
2 changes: 1 addition & 1 deletion doc.h
Expand Up @@ -542,7 +542,7 @@ typedef CTypedPtrArray <CPtrArray, CAlphaConfiguration*> CAlphaConfigurationArra
#ifdef PANE
class CPaneView;
typedef map<string, CPaneView *> CPaneMap;
typedef map<string, CPaneView *>::iterator PaneMapIterator;
typedef CPaneMap::iterator PaneMapIterator;
#endif // PANE

class CMUSHclientDoc : public CDocument
Expand Down
7 changes: 6 additions & 1 deletion doc_construct.cpp
Expand Up @@ -524,7 +524,12 @@ int i;

// delete plugins

DELETE_LIST (m_PluginList);
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
delete *pit;

m_PluginList.clear ();

CloseLog (); // this writes out the log file postamble as well

Expand Down
32 changes: 18 additions & 14 deletions evaluate.cpp
Expand Up @@ -68,23 +68,25 @@ CAliasList AliasList;
{
m_CurrentPlugin = NULL;
if (ProcessOneAliasSequence (input,
bCountThem,
bOmitFromLog,
bEchoAlias,
AliasList,
mapOneShotItems))
return true;
// do plugins
for (pos = m_PluginList.GetHeadPosition (); pos; )
{
m_CurrentPlugin = m_PluginList.GetNext (pos);
if (m_CurrentPlugin->m_bEnabled)
if (ProcessOneAliasSequence (input,
bCountThem,
bOmitFromLog,
bEchoAlias,
AliasList,
mapOneShotItems))
return true;
// do plugins
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = *pit;
if (m_CurrentPlugin->m_bEnabled)
if (ProcessOneAliasSequence (input,
bCountThem,
bOmitFromLog,
bEchoAlias,
AliasList,
mapOneShotItems))
{
m_CurrentPlugin = NULL;
return true;
Expand Down Expand Up @@ -144,9 +146,11 @@ CAliasList AliasList;
} // end of scanning main aliases

// do plugins
for (POSITION plugin_pos = m_PluginList.GetHeadPosition (); !bFoundIt && plugin_pos; )
for (PluginListIterator pit = m_PluginList.begin ();
!bFoundIt && pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = m_PluginList.GetNext (plugin_pos);
m_CurrentPlugin = *pit;

if (m_CurrentPlugin->m_bEnabled)
for (POSITION pos = GetAliasMap ().GetStartPosition (); !bFoundIt && pos; )
Expand Down
9 changes: 5 additions & 4 deletions mushview.cpp
Expand Up @@ -1788,11 +1788,12 @@ CPoint menupoint = point;
} // end of all aliases

// do plugins
for (POSITION plugin_pos = pDoc->m_PluginList.GetHeadPosition ();
plugin_pos && i < MXP_MENU_COUNT; )
for (PluginListIterator pit = pDoc->m_PluginList.begin ();
pit != pDoc->m_PluginList.end () && i < MXP_MENU_COUNT;
++pit)
{
pDoc->m_CurrentPlugin = pDoc->m_PluginList.GetNext (plugin_pos);

pDoc->m_CurrentPlugin = *pit;
if (pDoc->m_CurrentPlugin->m_bEnabled)
for (POSITION pos = pDoc->GetAliasMap ().GetStartPosition ();
pos && i < MXP_MENU_COUNT; )
Expand Down

0 comments on commit 00fa603

Please sign in to comment.