wxMaxima
Loading...
Searching...
No Matches
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 "cells/GroupCell.h"
37#include <wx/arrstr.h>
38#include <wx/stopwatch.h>
39#include <vector>
40#include <utility>
41
44{
45private:
46 class Command{
47 public:
48 Command(const wxString &strng, int index) : m_indexStart(index), m_command(strng) {}
49 Command(Command &&o) noexcept : m_indexStart(o.m_indexStart), m_command(std::move(o.m_command)) {}
50 Command(const Command &o) : m_indexStart(o.m_indexStart), m_command(o.m_command) {}
51 Command &operator=(Command &&o) noexcept
52 {
53 m_indexStart = o.m_indexStart;
54 m_command = std::move(o.m_command);
55 return *this;
56 }
57 Command &operator=(const Command &o)
58 {
59 m_indexStart = o.m_indexStart;
60 m_command = o.m_command;
61 return *this;
62 }
63
64 const wxString &GetString() const { return m_command; }
65 void AddEnding()
66 {
67 wxString trimmed = m_command;
68 trimmed.Trim(true);
69 if (!trimmed.EndsWith(wxS(";")) && !trimmed.EndsWith(wxS("$")))
70 m_command += ";";
71 }
72 int GetIndex() const { return m_indexStart; }
73 private:
74 long m_indexStart = -1;
75 wxString m_command;
76 };
77
88 std::vector<EvaluationQueue::Command> m_commands;
90 wxString m_pendingText;
92 Configuration *m_pendingConfig = nullptr;
95 long m_cellConsumedChars = 0;
96 std::size_t m_size;
98 wxString m_userLabel;
99
109 wxStopWatch m_commandStopwatch;
112 bool m_commandTimerRunning = false;
113
116 struct QueuedCell {
118 wxString textAtEnqueue;
119 };
121 std::vector<QueuedCell> m_queue;
122
132 bool m_integrityFailure = false;
133 wxString m_integrityFailureEnqueuedText;
134 wxString m_integrityFailureCurrentText;
135
138 void AddTokens();
142 void ProduceNextCommand();
143
144public:
151 wxString GetUserLabel() const
152 { return m_userLabel; }
153
154 int GetIndex() const
155 {
156 if (!m_commands.empty())
157 return m_commands.front().GetIndex();
158 else
159 return -1;
160 }
161
162 bool m_workingGroupChanged = false;
163
165
166 void AddEnding()
167 {
168 if (!m_commands.empty())
169 m_commands.back().AddEnding();
170 }
171
172 virtual ~EvaluationQueue()
173 {};
174
176 bool IsLastInQueue(GroupCell const *gr)
177 {
178 return !m_queue.empty() && (gr == m_queue.front().cell);
179 }
180
182 bool IsInQueue(GroupCell *gr) const;
183
185 void AddToQueue(GroupCell *gr);
186
188 void Remove(GroupCell *gr);
189
191 void AddHiddenTreeToQueue(const GroupCell *gr);
192
194 void RemoveFirst();
195
201
203 bool Empty() const;
204
206 void Clear();
207
209 wxString GetCommand();
210
215 bool HasIntegrityFailure() const { return m_integrityFailure; }
218 const wxString &GetIntegrityFailureEnqueuedText() const
219 { return m_integrityFailureEnqueuedText; }
222 const wxString &GetIntegrityFailureCurrentText() const
223 { return m_integrityFailureCurrentText; }
224
226 int Size() const { return m_size; }
227
232 int CommandsLeftInCell() const;
233
238 {
239 m_commandStopwatch.Start();
240 m_commandTimerRunning = true;
241 }
242
247 {
248 return m_commandTimerRunning ? m_commandStopwatch.Time() : -1;
249 }
250};
251
252
253#endif /* EVALUATIONQUEUE_H */
This file defines the class GroupCell that bundles input and output in the worksheet.
A weak non-owning pointer that becomes null whenever the observed object is destroyed.
Definition: CellPtr.h:539
The configuration storage for the current worksheet.
Definition: Configuration.h:98
A simple FIFO queue with manual removal of elements.
Definition: EvaluationQueue.h:44
void Remove(GroupCell *gr)
Remove a GroupCell from the evaluation queue.
Definition: EvaluationQueue.cpp:63
wxString GetUserLabel() const
Query for the label the user has assigned to the current command.
Definition: EvaluationQueue.h:151
bool IsLastInQueue(GroupCell const *gr)
Is GroupCell gr part of the evaluation queue?
Definition: EvaluationQueue.h:176
long GetCommandElapsedMilliseconds() const
Milliseconds since MarkCommandSent() was last called for the command currently in flight,...
Definition: EvaluationQueue.h:246
bool IsInQueue(GroupCell *gr) const
Is GroupCell gr part of the evaluation queue?
Definition: EvaluationQueue.cpp:57
void Clear()
Clear the queue.
Definition: EvaluationQueue.cpp:43
bool Empty() const
Is the queue empty?
Definition: EvaluationQueue.cpp:34
void AddHiddenTreeToQueue(const GroupCell *gr)
Adds all hidden cells attached to the GroupCell gr to the evaluation queue.
Definition: EvaluationQueue.cpp:104
void AddToQueue(GroupCell *gr)
Adds a GroupCell to the evaluation queue.
Definition: EvaluationQueue.cpp:80
wxString GetCommand()
Return the next command that needs to be evaluated.
Definition: EvaluationQueue.cpp:355
void RemoveFirst()
Removes the first command in the queue.
Definition: EvaluationQueue.cpp:114
GroupCell * GetCell()
Gets the cell the next command in the queue belongs to.
Definition: EvaluationQueue.cpp:348
bool HasIntegrityFailure() const
Did the cell that just became current (see GetCell()) have different text than what was captured when...
Definition: EvaluationQueue.h:215
int CommandsLeftInCell() const
Roughly how many commands are still to be run in the current cell. Because commands are tokenized laz...
Definition: EvaluationQueue.cpp:326
const wxString & GetIntegrityFailureCurrentText() const
The cell's text as AddTokens() actually read it, valid only while HasIntegrityFailure() is true for t...
Definition: EvaluationQueue.h:222
const wxString & GetIntegrityFailureEnqueuedText() const
The cell's text as it was when AddToQueue() was called, valid only while HasIntegrityFailure() is tru...
Definition: EvaluationQueue.h:218
int Size() const
Get the size of the queue [in cells].
Definition: EvaluationQueue.h:226
void MarkCommandSent()
Call exactly once, right after the current command's text is actually written to Maxima's socket – st...
Definition: EvaluationQueue.h:237
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88