"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/include/IQueue.h" (21 Jul 2005, 1228 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "IQueue.h" see the Fossies "Dox" file reference documentation.

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