Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
66
cde/programs/nsgmls/IQueue.h
Normal file
66
cde/programs/nsgmls/IQueue.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* $XConsortium: IQueue.h /main/1 1996/07/29 16:53:51 cde-hp $ */
|
||||
// Copyright (c) 1994 James Clark
|
||||
// See the file COPYING for copying permission.
|
||||
|
||||
#ifndef IQueue_INCLUDED
|
||||
#define IQueue_INCLUDED 1
|
||||
|
||||
#include "Boolean.h"
|
||||
#include "Link.h"
|
||||
|
||||
#ifdef SP_NAMESPACE
|
||||
namespace SP_NAMESPACE {
|
||||
#endif
|
||||
|
||||
class IQueueBase {
|
||||
public:
|
||||
IQueueBase() : last_(0) { }
|
||||
~IQueueBase() { }
|
||||
Boolean empty() const { return last_ == 0; }
|
||||
Link *get() {
|
||||
Link *tem = last_->next_;
|
||||
if (tem == last_)
|
||||
last_ = 0;
|
||||
else
|
||||
last_->next_ = tem->next_;
|
||||
return tem;
|
||||
}
|
||||
void append(Link *p) {
|
||||
if (last_) {
|
||||
p->next_ = last_->next_;
|
||||
last_ = last_->next_ = p;
|
||||
}
|
||||
else
|
||||
last_ = p->next_ = p;
|
||||
}
|
||||
void swap(IQueueBase &with) {
|
||||
Link *tem = last_;
|
||||
last_ = with.last_;
|
||||
with.last_ = tem;
|
||||
}
|
||||
private:
|
||||
Link *last_;
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class IQueue : private IQueueBase {
|
||||
public:
|
||||
IQueue() { }
|
||||
~IQueue() { clear(); }
|
||||
void clear();
|
||||
T *get() { return (T *)IQueueBase::get(); }
|
||||
void append(T *p) { IQueueBase::append(p); }
|
||||
Boolean empty() const { return IQueueBase::empty(); }
|
||||
void swap(IQueue<T> &to) { IQueueBase::swap(to); }
|
||||
};
|
||||
|
||||
#ifdef SP_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* not IQueue_INCLUDED */
|
||||
|
||||
#ifdef SP_DEFINE_TEMPLATES
|
||||
#include "IQueue.C"
|
||||
#endif
|
||||
Reference in New Issue
Block a user