a997eba78bc0c25c94bcf7b28b57d7e9abfb55f1
[yazpp-moved-to-github.git] / src / gduqueue.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2013 Index Data and Mike Taylor
3  * See the file LICENSE for details.
4  */
5
6 #if HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 #include <yazpp/gdu.h>
10 #include <yazpp/gduqueue.h>
11
12 using namespace yazpp_1;
13
14 GDUQueue::GDUQueue()
15 {
16     m_list = 0;
17 }
18
19 int GDUQueue::size()
20 {
21     int no = 0;
22     GDUQueue_List *l;
23     for (l = m_list; l; l = l->m_next)
24         no++;
25     return no;
26 }
27
28 void GDUQueue::enqueue(GDU *gdu)
29 {
30     GDUQueue_List *l = new GDUQueue_List;
31     l->m_next = m_list;
32     l->m_item = gdu;
33     m_list = l;
34 }
35
36 GDU *GDUQueue::dequeue()
37 {
38     GDUQueue_List **l = &m_list;
39     if (!*l)
40         return 0;
41     while ((*l)->m_next)
42         l = &(*l)->m_next;
43     GDU *m = (*l)->m_item;
44     delete *l;
45     *l = 0;
46     return m;
47 }
48
49 void GDUQueue::clear()
50 {
51     GDU *g;
52     while ((g = dequeue()))
53         delete g;
54 }
55
56 GDUQueue::~GDUQueue()
57 {
58     clear();
59 }
60 /*
61  * Local variables:
62  * c-basic-offset: 4
63  * c-file-style: "Stroustrup"
64  * indent-tabs-mode: nil
65  * End:
66  * vim: shiftwidth=4 tabstop=8 expandtab
67  */
68