home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / AETSK101 / SYSQVFNC.H < prev    next >
C/C++ Source or Header  |  1992-05-31  |  2KB  |  81 lines

  1. /*
  2.     sysqvfnc.h
  3.  
  4.     queues of objects of type Qable
  5.     
  6.     copyright (c) 1991 J. Alan Eldridge
  7.     
  8.     history:
  9.     
  10.     < from sysqtmpl.h -- the template version >
  11.  
  12.     10/28/91    created
  13.     
  14.     10/30/91    changed class hierarchy so we now have:
  15.     
  16.                 SysQ<T>     queue of Ts
  17.                 SysPriQ<T>  priority queue of Ts
  18.                 SysQP<T>    queue of ptrs to T
  19.                 SysPriQP<T> priority queue of ptrs to T
  20.  
  21.     11/08/91    created this virtual function version...
  22.                 this has only classes SysQP and SysPriQP
  23. */
  24.  
  25. /*
  26.     in the virtual function version of SysQ, anything that can
  27.     be put on a queue must define operator <, so it can be put
  28.     on a priority queue... <sorry, but without templates I've
  29.     gotta impose rules>
  30. */    
  31.  
  32. class Qable {
  33. private:
  34.     //  nothing right now
  35. public:
  36.     virtual int operator<(Qable &) = 0;
  37. };
  38.  
  39. struct SysQNode {
  40.     Qable       *data;
  41.     SysQNode    *next;
  42.     SysQNode    *prev;
  43. };
  44.     
  45. class SysQP {
  46. protected:
  47.     int         nused, nfree, maxnodes;
  48.     SysQNode    *head, *tail, *free;
  49.  
  50.     SysQNode    *getfree(int=1);
  51.     void        putfree(SysQNode*);
  52.  
  53.     SysQNode            *findnode(Qable*);
  54.     virtual SysQNode    *findpred(Qable*);
  55.     
  56.     void        create(SysQNode*);
  57.     void        insert(SysQNode*, SysQNode*);
  58.  
  59.     int         Ins(Qable*);
  60.     int         Get(Qable* &,int rmv=1);
  61. public:
  62.     SysQP(int n=0, int lim=INT_MAX);
  63.     virtual ~SysQP();
  64.     int         Add(Qable*);
  65.     int         Del(Qable*);
  66.     Qable*      Get(int rmv=1);
  67.     int         Cnt()
  68.         { return nused; }
  69.     int         Max()
  70.         { return maxnodes; }
  71. };
  72.  
  73. class SysPriQP: public SysQP {
  74. public:
  75.     SysPriQP(int n=0,int lim=INT_MAX): SysQP(n,lim)
  76.         { }
  77.     int Add(Qable *t)
  78.         { return SysQP::Ins(t); }
  79. };
  80.  
  81.