Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / IQueue.h
1 /* $XConsortium: IQueue.h /main/1 1996/07/29 16:53:51 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
4
5 #ifndef IQueue_INCLUDED
6 #define IQueue_INCLUDED 1
7
8 #include "Boolean.h"
9 #include "Link.h"
10
11 #ifdef SP_NAMESPACE
12 namespace SP_NAMESPACE {
13 #endif
14
15 class IQueueBase {
16 public:
17   IQueueBase() : last_(0) { }
18   ~IQueueBase() { }
19   Boolean empty() const { return last_ == 0; }
20   Link *get() {
21     Link *tem = last_->next_;
22     if (tem == last_)
23       last_ = 0;
24     else
25       last_->next_ = tem->next_;
26     return tem;
27   }
28   void append(Link *p) {
29     if (last_) {
30       p->next_ = last_->next_;
31       last_ = last_->next_ = p;
32     }
33     else
34       last_ = p->next_ = p;
35   }
36   void swap(IQueueBase &with) {
37     Link *tem = last_;
38     last_ = with.last_;
39     with.last_ = tem;
40   }
41 private:
42   Link *last_;
43
44 };
45
46 template<class T>
47 class IQueue : private IQueueBase {
48 public:
49   IQueue() { }
50   ~IQueue() { clear(); }
51   void clear();
52   T *get() { return (T *)IQueueBase::get(); }
53   void append(T *p) { IQueueBase::append(p); }
54   Boolean empty() const { return IQueueBase::empty(); }
55   void swap(IQueue<T> &to) { IQueueBase::swap(to); }
56 };
57
58 #ifdef SP_NAMESPACE
59 }
60 #endif
61
62 #endif /* not IQueue_INCLUDED */
63
64 #ifdef SP_DEFINE_TEMPLATES
65 #include "IQueue.C"
66 #endif