wxMaxima
EvaluationQueue.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2009 Ziga Lenarcic <zigalenarcic@users.sourceforge.net>
4 // (C) 2012 Doug Ilijev <doug.ilijev@gmail.com>
5 // (C) 2015-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // SPDX-License-Identifier: GPL-2.0+
23 
32 #ifndef EVALUATIONQUEUE_H
33 #define EVALUATIONQUEUE_H
34 
35 #include "precomp.h"
36 #include "GroupCell.h"
37 #include <wx/arrstr.h>
38 #include <vector>
39 
42 {
43 private:
44 
45  class Command{
46  public:
47  Command(const wxString &string, int index) : m_indexStart(index), m_command(string) {}
48  Command(Command &&o) : m_indexStart(o.m_indexStart), m_command(std::move(o.m_command)) {}
49  Command(const Command &o) : m_indexStart(o.m_indexStart), m_command(o.m_command) {}
50  Command &operator=(Command &&o)
51  {
52  m_indexStart = o.m_indexStart;
53  m_command = std::move(o.m_command);
54  return *this;
55  }
56  Command &operator=(const Command &o)
57  {
58  m_indexStart = o.m_indexStart;
59  m_command = o.m_command;
60  return *this;
61  }
62 
63  const wxString &GetString() const { return m_command; }
64  void AddEnding() { m_command += ";"; }
65  int GetIndex() const { return m_indexStart; }
66  private:
67  int m_indexStart;
68  wxString m_command;
69  };
70 
78  std::vector<EvaluationQueue::Command> m_commands;
79  int m_size;
81  wxString m_userLabel;
83  std::vector<GroupCell *> m_queue;
84 
86  void AddTokens(GroupCell *cell);
87 
89  wxArrayString m_knownAnswers;
90  wxArrayString m_knownQuestions;
91 
92 public:
99  wxString GetUserLabel() const
100  { return m_userLabel; }
101 
102  int GetIndex() const
103  {
104  if (!m_commands.empty())
105  return m_commands.front().GetIndex();
106  else
107  return -1;
108  }
109 
110  bool m_workingGroupChanged;
111 
112  EvaluationQueue();
113 
114  void AddEnding()
115  {
116  if (!m_commands.empty())
117  m_commands.back().AddEnding();
118  }
119 
120  ~EvaluationQueue()
121  {};
122 
124  bool IsLastInQueue(GroupCell const *gr)
125  {
126  return !m_queue.empty() && (gr == m_queue.front());
127  }
128 
130  bool IsInQueue(GroupCell *gr) const;
131 
133  void AddToQueue(GroupCell *gr);
134 
136  void Remove(GroupCell *gr);
137 
140 
142  void RemoveFirst();
143 
148  GroupCell *GetCell();
149 
151  bool Empty() const;
152 
154  void Clear();
155 
157  wxString GetCommand();
158 
160  int Size() const { return m_size; }
161 
163  int CommandsLeftInCell() const { return m_commands.size(); }
164 };
165 
166 
167 #endif /* EVALUATIONQUEUE_H */
EvaluationQueue::Empty
bool Empty() const
Is the queue empty?
Definition: EvaluationQueue.cpp:33
EvaluationQueue::RemoveFirst
void RemoveFirst()
Removes the first command in the queue.
Definition: EvaluationQueue.cpp:104
GroupCell.h
EvaluationQueue::AddToQueue
void AddToQueue(GroupCell *gr)
Adds a GroupCell to the evaluation queue.
Definition: EvaluationQueue.cpp:71
EvaluationQueue
A simple FIFO queue with manual removal of elements.
Definition: EvaluationQueue.h:41
EvaluationQueue::GetCommand
wxString GetCommand()
Return the next command that needs to be evaluated.
Definition: EvaluationQueue.cpp:175
EvaluationQueue::Size
int Size() const
Get the size of the queue [in cells].
Definition: EvaluationQueue.h:160
EvaluationQueue::Clear
void Clear()
Clear the queue.
Definition: EvaluationQueue.cpp:44
EvaluationQueue::GetUserLabel
wxString GetUserLabel() const
Definition: EvaluationQueue.h:99
EvaluationQueue::CommandsLeftInCell
int CommandsLeftInCell() const
Get the size of the queue.
Definition: EvaluationQueue.h:163
EvaluationQueue::GetCell
GroupCell * GetCell()
Definition: EvaluationQueue.cpp:167
EvaluationQueue::IsLastInQueue
bool IsLastInQueue(GroupCell const *gr)
Is GroupCell gr part of the evaluation queue?
Definition: EvaluationQueue.h:124
EvaluationQueue::AddHiddenTreeToQueue
void AddHiddenTreeToQueue(GroupCell *gr)
Adds all hidden cells attached to the GroupCell gr to the evaluation queue.
Definition: EvaluationQueue.cpp:92
EvaluationQueue::Remove
void Remove(GroupCell *gr)
Remove a GroupCell from the evaluation queue.
Definition: EvaluationQueue.cpp:57
GroupCell
Definition: GroupCell.h:68
EvaluationQueue::IsInQueue
bool IsInQueue(GroupCell *gr) const
Is GroupCell gr part of the evaluation queue?
Definition: EvaluationQueue.cpp:52