GNU Octave
4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
corefcn
event-queue.h
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2012-2015 John W. Eaton
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 the
9
Free Software Foundation; either version 3 of the License, or (at your
10
option) any later version.
11
12
Octave is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
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
<http://www.gnu.org/licenses/>.
20
21
*/
22
23
#if !defined (octave_event_queue_h)
24
#define octave_event_queue_h 1
25
26
#include <queue>
27
#include <memory>
28
29
#include "
action-container.h
"
30
31
class
32
event_queue
:
public
action_container
33
{
34
public
:
35
36
event_queue
(
void
) : fifo () { }
37
38
// Destructor should not raise an exception, so all actions
39
// registered should be exception-safe (but setting error_state is
40
// allowed). If you're not sure, see event_queue_safe.
41
42
~event_queue
(
void
) {
run
(); }
43
44
void
add
(
elem
*new_elem)
45
{
46
fifo.push (new_elem);
47
}
48
49
void
run_first
(
void
)
50
{
51
if
(!
empty
())
52
{
53
// No leak on exception!
54
std::auto_ptr<elem> ptr (fifo.front ());
55
fifo.pop ();
56
ptr->run ();
57
}
58
}
59
60
void
discard_first
(
void
)
61
{
62
if
(!
empty
())
63
{
64
elem
*ptr = fifo.front ();
65
fifo.pop ();
66
delete
ptr;
67
}
68
}
69
70
size_t
size
(
void
)
const
{
return
fifo.size (); }
71
72
protected
:
73
74
std::queue<elem *>
fifo
;
75
76
private
:
77
78
// No copying!
79
80
event_queue
(
const
event_queue
&);
81
82
event_queue
&
operator =
(
const
event_queue
&);
83
};
84
85
// Like event_queue, but this one will guard against the
86
// possibility of seeing an exception (or interrupt) in the cleanup
87
// actions. Not that we can do much about it, but at least we won't
88
// crash.
89
90
class
91
event_queue_safe
:
public
event_queue
92
{
93
private
:
94
95
static
void
gripe_exception (
void
);
96
97
public
:
98
99
event_queue_safe
(
void
) :
event_queue
() { }
100
101
~event_queue_safe
(
void
)
102
{
103
while
(!
empty
())
104
{
105
try
106
{
107
run_first
();
108
}
109
catch
(...)
// Yes, the black hole. Remember we're in a dtor.
110
{
111
gripe_exception ();
112
}
113
}
114
}
115
116
private
:
117
118
// No copying!
119
120
event_queue_safe
(
const
event_queue_safe
&);
121
122
event_queue_safe
&
operator =
(
const
event_queue_safe
&);
123
};
124
125
#endif
event_queue_safe::~event_queue_safe
~event_queue_safe(void)
Definition:
event-queue.h:101
event_queue::event_queue
event_queue(void)
Definition:
event-queue.h:36
action-container.h
event_queue_safe::event_queue_safe
event_queue_safe(void)
Definition:
event-queue.h:99
event_queue::fifo
std::queue< elem * > fifo
Definition:
event-queue.h:74
event_queue::size
size_t size(void) const
Definition:
event-queue.h:70
unwind_protect::operator=
unwind_protect & operator=(const unwind_protect &)
elem
static int elem
Definition:
__contourc__.cc:49
event_queue::run_first
void run_first(void)
Definition:
event-queue.h:49
action_container::run
void run(void)
Definition:
action-container.h:313
event_queue::discard_first
void discard_first(void)
Definition:
event-queue.h:60
event_queue_safe
Definition:
event-queue.h:90
event_queue::~event_queue
~event_queue(void)
Definition:
event-queue.h:42
event_queue
Definition:
event-queue.h:31
action_container::empty
bool empty(void) const
Definition:
action-container.h:330
unwind_protect::run_first
void run_first(void)
Definition:
unwind-prot.h:62
event_queue::add
void add(elem *new_elem)
Definition:
event-queue.h:44
action_container
Definition:
action-container.h:33
Generated on Thu Jun 4 2015 23:30:12 for GNU Octave by
1.8.8