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