GNU Octave
10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Loading...
Searching...
No Matches
event-queue.h
Go to the documentation of this file.
1
////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2012-2025 The Octave Project Developers
4
//
5
// See the file COPYRIGHT.md in the top-level directory of this
6
// distribution or <https://octave.org/copyright/>.
7
//
8
// This file is part of Octave.
9
//
10
// Octave is free software: you can redistribute it and/or modify it
11
// under the terms of the GNU General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// Octave is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU General Public License for more details.
19
//
20
// You should have received a copy of the GNU General Public License
21
// along with Octave; see the file COPYING. If not, see
22
// <https://www.gnu.org/licenses/>.
23
//
24
////////////////////////////////////////////////////////////////////////
25
26
#if ! defined (octave_event_queue_h)
27
#define octave_event_queue_h 1
28
29
#include "octave-config.h"
30
31
#include <queue>
32
#include <memory>
33
34
#include "
action-container.h
"
35
36
OCTAVE_BEGIN_NAMESPACE
(octave)
37
38
class
event_queue
: public
action_container
39
{
40
public
:
41
42
event_queue
() : m_fifo () { }
43
44
OCTAVE_DISABLE_COPY_MOVE (
event_queue
)
45
46
// Destructor should not raise an exception, so all actions registered
47
// should be exception-safe. If you're not sure, see event_queue_safe.
48
49
~event_queue
() { run (); }
50
51
void
run_first
()
52
{
53
if
(! empty ())
54
{
55
// No leak on exception!
56
std::unique_ptr<elem> ptr (m_fifo.front ());
57
m_fifo.pop ();
58
ptr->run ();
59
}
60
}
61
62
void
discard_first
()
63
{
64
if
(! empty ())
65
{
66
elem
*ptr = m_fifo.front ();
67
m_fifo.pop ();
68
delete
ptr;
69
}
70
}
71
72
std::size_t
size
()
const
{
return
m_fifo.size (); }
73
74
protected
:
75
76
void
add_action
(
elem
*new_elem)
77
{
78
m_fifo.push (new_elem);
79
}
80
81
//--------
82
83
std::queue<elem *>
m_fifo
;
84
};
85
86
// Like event_queue, but this one will guard against the
87
// possibility of seeing an exception (or interrupt) in the cleanup actions.
88
// Not that we can do much about it, but at least we won't crash.
89
90
class
event_queue_safe
:
public
event_queue
91
{
92
public
:
93
94
event_queue_safe
() :
event_queue
() { }
95
96
OCTAVE_DISABLE_COPY_MOVE (
event_queue_safe
)
97
98
~event_queue_safe
()
99
{
100
while
(!
empty
())
101
{
102
try
103
{
104
run_first
();
105
}
106
catch
(...)
// Yes, the black hole. Remember we're in a dtor.
107
{
108
warn_unhandled_exception ();
109
}
110
}
111
}
112
113
private
:
114
115
void
warn_unhandled_exception ()
const
;
116
117
};
118
119
OCTAVE_END_NAMESPACE(octave)
120
121
#endif
action-container.h
action_container::elem
Definition
action-container.h:66
action_container
Definition
action-container.h:60
action_container::empty
bool empty() const
Definition
action-container.h:224
event_queue_safe
Definition
event-queue.h:91
event_queue_safe::event_queue_safe
event_queue_safe()
Definition
event-queue.h:94
event_queue_safe::~event_queue_safe
~event_queue_safe()
Definition
event-queue.h:98
event_queue
Definition
event-queue.h:39
event_queue::run_first
void run_first()
Definition
event-queue.h:51
event_queue::discard_first
void discard_first()
Definition
event-queue.h:62
event_queue::event_queue
event_queue()
Definition
event-queue.h:42
event_queue::size
std::size_t size() const
Definition
event-queue.h:72
event_queue::~event_queue
~event_queue()
Definition
event-queue.h:49
event_queue::m_fifo
std::queue< elem * > m_fifo
Definition
event-queue.h:83
event_queue::add_action
void add_action(elem *new_elem)
Definition
event-queue.h:76
OCTAVE_BEGIN_NAMESPACE
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
libinterp
corefcn
event-queue.h
Generated on Sat Aug 2 2025 06:52:10 for GNU Octave by
1.9.8