GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-cmd.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2014-2018 Torsten
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 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 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Author: Torsten <ttl@justmail.de>
24 
25 #if ! defined (octave_octave_cmd_h)
26 #define octave_octave_cmd_h 1
27 
28 #include <QSemaphore>
29 #include <QMutex>
30 #include <QString>
31 #include <QFileInfo>
32 
33 #include "octave-qt-link.h"
34 
35 namespace octave
36 {
37  class octave_cmd
38  {
39  public:
40 
41  octave_cmd (void) = default;
42 
43  virtual ~octave_cmd (void) = default;
44 
45  virtual void execute (void) { }
46  };
47 
48  class octave_cmd_exec : public octave_cmd
49  {
50  public:
51 
52  octave_cmd_exec (const QString& cmd) : octave_cmd () { m_cmd = cmd; }
53 
54  void execute (void);
55 
56  protected:
57 
58  QString m_cmd;
59  };
60 
61  class octave_cmd_eval : public octave_cmd
62  {
63  public:
64 
65  octave_cmd_eval (const QFileInfo& info) : octave_cmd () { m_info = info; }
66 
67  void execute (void);
68 
69  protected:
70 
71  QFileInfo m_info;
72  };
73 
75  {
76  public:
77 
78  octave_cmd_debug (const QString& cmd, bool suppress_location)
79  : octave_cmd_exec (cmd), m_suppress_dbg_location (suppress_location) { }
80 
81  void execute (void);
82 
83  protected:
84 
86  };
87 
88  //! Queuing octave commands from the GUI for the worker thread.
89 
91  {
92  Q_OBJECT;
93 
94  public:
95 
97  : QObject (), m_queue (QList<octave_cmd *> ()), m_processing (1),
98  m_queue_mutex ()
99  { }
100 
101  ~octave_command_queue (void) = default;
102 
103  //! Adds a new octave command to the command queue.
104  //!
105  //! @param cmd The octave command to be queued.
106 
107  void add_cmd (octave_cmd *cmd);
108 
109  //! Callback routine for executing the command by the worker thread.
110 
111  void execute_command_callback (void);
112 
113  private:
114 
116  QSemaphore m_processing;
118  };
119 }
120 
121 #endif
~octave_command_queue(void)=default
octave_cmd_eval(const QFileInfo &info)
Definition: octave-cmd.h:65
octave_cmd(void)=default
void add_cmd(octave_cmd *cmd)
Adds a new octave command to the command queue.
Definition: octave-cmd.cc:101
void execute_command_callback(void)
Callback routine for executing the command by the worker thread.
Definition: octave-cmd.cc:113
virtual void execute(void)
Definition: octave-cmd.h:45
octave_cmd_exec(const QString &cmd)
Definition: octave-cmd.h:52
QList< octave_cmd * > m_queue
Definition: octave-cmd.h:115
Queuing octave commands from the GUI for the worker thread.
Definition: octave-cmd.h:90
virtual ~octave_cmd(void)=default
octave_cmd_debug(const QString &cmd, bool suppress_location)
Definition: octave-cmd.h:78