xref: /onnv-gate/usr/src/cmd/man/src/util/nsgmls.src/include/IQueue.h (revision 0:68f95e015346)
1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
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:
IQueueBase()17   IQueueBase() : last_(0) { }
~IQueueBase()18   ~IQueueBase() { }
empty()19   Boolean empty() const { return last_ == 0; }
get()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   }
append(Link * p)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   }
swap(IQueueBase & with)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:
IQueue()49   IQueue() { }
~IQueue()50   ~IQueue() { clear(); }
51   void clear();
get()52   T *get() { return (T *)IQueueBase::get(); }
append(T * p)53   void append(T *p) { IQueueBase::append(p); }
empty()54   Boolean empty() const { return IQueueBase::empty(); }
swap(IQueue<T> & to)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.cxx"
66 #endif
67