File indexing completed on 2024-05-12 04:39:43

0001 /*
0002     SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef MICOMMANDQUEUE_H
0008 #define MICOMMANDQUEUE_H
0009 
0010 #include "dbgglobal.h"
0011 
0012 #include <memory>
0013 #include <deque>
0014 
0015 namespace KDevMI { namespace MI {
0016 
0017 class MICommand;
0018 
0019 class CommandQueue
0020 {
0021 public:
0022     CommandQueue();
0023     ~CommandQueue();
0024 
0025     void enqueue(std::unique_ptr<MICommand> command);
0026 
0027     bool isEmpty() const;
0028     int count() const;
0029     void clear();
0030 
0031     /// Whether the queue contains a command with CmdImmediately or CmdInterrupt flags.
0032     bool haveImmediateCommand() const;
0033 
0034     /**
0035      * Retrieve and remove the next command from the list.
0036      * Returns @c nullptr if the list is empty.
0037      */
0038     std::unique_ptr<MICommand> nextCommand();
0039 
0040 private:
0041     void rationalizeQueue(MICommand* command);
0042     void dumpQueue() const;
0043 
0044 private:
0045     Q_DISABLE_COPY(CommandQueue)
0046 
0047     std::deque<std::unique_ptr<MICommand>> m_commandList;
0048     int m_immediatelyCounter = 0;
0049     uint32_t m_tokenCounter = 0;
0050 };
0051 
0052 } // end of namespace MI
0053 } // end of namespace KDevMI
0054 
0055 #endif // MICOMMANDQUEUE_H