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 <vector>
39#include <utility>
40
43{
44private:
45 class Command{
46 public:
47 Command(const wxString &strng, int index) : m_indexStart(index), m_command(strng) {}
48 Command(Command &&o) noexcept : 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) noexcept
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()
65 {
66 wxString trimmed = m_command;
67 trimmed.Trim(true);
68 if (!trimmed.EndsWith(wxS(";")) && !trimmed.EndsWith(wxS("$")))
69 m_command += ";";
70 }
71 int GetIndex() const { return m_indexStart; }
72 private:
73 long m_indexStart = -1;
74 wxString m_command;
75 };
76
84 std::vector<EvaluationQueue::Command> m_commands;
85 std::size_t m_size;
87 wxString m_userLabel;
89 std::vector<CellPtr<GroupCell>> m_queue;
90
92 void AddTokens(const GroupCell *cell);
93
94public:
101 wxString GetUserLabel() const
102 { return m_userLabel; }
103
104 int GetIndex() const
105 {
106 if (!m_commands.empty())
107 return m_commands.front().GetIndex();
108 else
109 return -1;
110 }
111
112 bool m_workingGroupChanged = false;
113
115
116 void AddEnding()
117 {
118 if (!m_commands.empty())
119 m_commands.back().AddEnding();
120 }
121
122 virtual ~EvaluationQueue()
123 {};
124
126 bool IsLastInQueue(GroupCell const *gr)
127 {
128 return !m_queue.empty() && (gr == m_queue.front());
129 }
130
132 bool IsInQueue(GroupCell *gr) const;
133
135 void AddToQueue(GroupCell *gr);
136
138 void Remove(GroupCell *gr);
139
141 void AddHiddenTreeToQueue(const GroupCell *gr);
142
144 void RemoveFirst();
145
151
153 bool Empty() const;
154
156 void Clear();
157
159 wxString GetCommand();
160
162 int Size() const { return m_size; }
163
165 int CommandsLeftInCell() const { return m_commands.size(); }
166};
167
168
169#endif /* EVALUATIONQUEUE_H */
This file defines the class GroupCell that bundles input and output in the worksheet.
A simple FIFO queue with manual removal of elements.
Definition: EvaluationQueue.h:43
void Remove(GroupCell *gr)
Remove a GroupCell from the evaluation queue.
Definition: EvaluationQueue.cpp:54
wxString GetUserLabel() const
Query for the label the user has assigned to the current command.
Definition: EvaluationQueue.h:101
bool IsLastInQueue(GroupCell const *gr)
Is GroupCell gr part of the evaluation queue?
Definition: EvaluationQueue.h:126
bool IsInQueue(GroupCell *gr) const
Is GroupCell gr part of the evaluation queue?
Definition: EvaluationQueue.cpp:50
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:87
void AddToQueue(GroupCell *gr)
Adds a GroupCell to the evaluation queue.
Definition: EvaluationQueue.cpp:67
wxString GetCommand()
Return the next command that needs to be evaluated.
Definition: EvaluationQueue.cpp:168
void RemoveFirst()
Removes the first command in the queue.
Definition: EvaluationQueue.cpp:97
GroupCell * GetCell()
Gets the cell the next command in the queue belongs to.
Definition: EvaluationQueue.cpp:161
int CommandsLeftInCell() const
Get the size of the queue.
Definition: EvaluationQueue.h:165
int Size() const
Get the size of the queue [in cells].
Definition: EvaluationQueue.h:162
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87