1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 11435 $
6  * $Id: compiler_defs.cpp 11435 2018-08-07 07:13:14Z fuscated $
7  * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/compilergcc/compiler_defs.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "compiler_defs.h"
12 #include <cbproject.h>
13 #include <projectbuildtarget.h>
14 
15 #include <wx/listimpl.cpp>
16 WX_DEFINE_LIST(CompilerCommands);
17 
CompilerQueue()18 CompilerQueue::CompilerQueue()
19     : m_LastWasRun(false)
20 {
21 }
22 
~CompilerQueue()23 CompilerQueue::~CompilerQueue()
24 {
25     Clear();
26 }
27 
Clear()28 void CompilerQueue::Clear()
29 {
30     m_Commands.DeleteContents(true);
31     m_Commands.Clear();
32     m_Commands.DeleteContents(false);
33 }
34 
GetCount() const35 size_t CompilerQueue::GetCount() const
36 {
37     return m_Commands.GetCount();
38 }
39 
LastCommandWasRun() const40 bool CompilerQueue::LastCommandWasRun() const
41 {
42     return m_LastWasRun;
43 }
44 
Add(CompilerCommand * cmd)45 void CompilerQueue::Add(CompilerCommand* cmd)
46 {
47     if (cmd)
48     {
49         if (cmd->dir.IsEmpty() && cmd->project)
50             cmd->dir = cmd->project->GetExecutionDir();
51         m_Commands.Append(cmd);
52     }
53 }
54 
Add(CompilerQueue * queue)55 void CompilerQueue::Add(CompilerQueue* queue)
56 {
57     for (CompilerCommands::iterator it = queue->m_Commands.begin(); it != queue->m_Commands.end(); ++it)
58     {
59         if (*it)
60             Add(new CompilerCommand(**it));
61     }
62 }
63 
Peek()64 CompilerCommand* CompilerQueue::Peek()
65 {
66     if (m_Commands.empty())
67         return nullptr;
68     else
69         return m_Commands.front();
70 }
71 
Next()72 CompilerCommand* CompilerQueue::Next()
73 {
74     if (m_Commands.empty())
75         return nullptr;
76     CompilerCommand* cmd = m_Commands.front();
77     m_Commands.pop_front();
78     m_LastWasRun = cmd ? cmd->isRun : false;
79     return cmd;
80 }
81