-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.cpp
More file actions
135 lines (125 loc) · 2.5 KB
/
queue.cpp
File metadata and controls
135 lines (125 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
** ssqueue.cpp --- implementation of speech queue.
**
** Copyright (C) 2000, 2001 Bilingual Emacspeak Project <inoue@argv.org>
**
** Last modified: $Date: 2001/11/18 17:31:53 $ by $Author: inoue $
** Keywords: Emacs, Emacspeak, speech, Linux
**
** This file is part of BEP (Bilingual Emacspeak Project)
** <http://www.argv.org/bep/>
** This file is originally written by Gary Bishop, and modified by BEP
** to make a bilingual, Japanese and English, DECTalk-like speech server
** running under Windows.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include "ssdefs.h"
#include "queue.h"
queue_node::queue_node()
{
content = NULL;
next = NULL;
}
queue::queue()
{
head = NULL;
tail = NULL;
}
queue::~queue()
{
clear();
}
queue_node *
queue::push(void *cnt)
{
queue_node *q = new queue_node();
q->content = cnt;
q->next = NULL;
if (tail != NULL) {
tail->next = q;
}
tail = q;
if (head == NULL) {
head = q;
}
return q;
}
void *
queue::pop()
{
void *p;
queue_node *q;
q = head;
if (q != NULL) {
head = q->next;
if (head == NULL) tail = NULL;
p = q->content;
delete q;
return p;
}
return NULL;
}
int
queue::empty()
{
return (head == NULL);
}
void
queue::clear()
{
queue_node *q, *q0;
q = head;
while(q != NULL) {
q0 = q;
q = q->next;
delete q0->content;
delete q0;
}
head = tail = NULL;
return;
}
/* the same as clear() except that this function doesn't
destroy content of each node. */
void
queue::clear_without_content()
{
queue_node *q, *q0;
q = head;
while(q != NULL) {
q0 = q;
q = q->next;
delete q0;
}
head = tail = NULL;
return;
}
void *
queue::gethead()
{
if (head == NULL) {
return NULL;
}
return head->content;
}
void *
queue::gettail()
{
if (tail == NULL) {
return NULL;
}
return tail->content;
}