home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bcpp1611.zip / BCPP / BASEQ.H < prev    next >
C/C++ Source or Header  |  1996-12-18  |  4KB  |  114 lines

  1. #ifndef _QUEUE_LIST_HEADER
  2. #define _QUEUE_LIST_HEADER
  3.  
  4. // Code written by Steven De Toni ACBC 11
  5. // this header definition contains a container class that stores data
  6. // in a queued linked list.
  7.  
  8. #include "anyobj.h"           // include base class
  9.  
  10. struct LinkItem
  11. {
  12.     LinkItem*   pLinkedItem;  // linker (pointer to the next item in the list)
  13.     ANYOBJECT*  pStoredItem;  // data that is store within a list item
  14. };
  15.  
  16.  
  17. class QueueList
  18. {
  19.     protected:
  20.         int           itemCount;
  21.         LinkItem*     pEndPos;
  22.                                   // set to 0 for space available,
  23.         int           spaceAvailable;
  24.         // -1 if no space available;
  25.  
  26.         // Create new list item and place programmer's data within it,
  27.         // make new links with previous item if wished.
  28.         // returns a pointer to the new item, NULL if operation failed.
  29.         //
  30.         // Parameters:
  31.         //     pItem    : Pointer to the object to be stored.
  32.         //     LinkItem : Pointer to end of list where item to be added.
  33.         //
  34.         // Return Values:
  35.         //     LinkItem : returns pointer to newly added item in list,
  36.         //                NULL if operation failed. However items within list
  37.         //                before hand still exist.
  38.         LinkItem* newItem (ANYOBJECT* pItem, LinkItem* pEndList);
  39.  
  40.     public:
  41.         // constructors
  42.         QueueList       (void);
  43.  
  44.         // Parameters:
  45.         //     pItem    : Pointer to a object to be stored, must be decendant of
  46.         //                base class ANYOBJECT.
  47.         QueueList       (ANYOBJECT* pItem);
  48.  
  49.         // Place programmers object into list
  50.         //
  51.         // Parameters:
  52.         //     pItem    : Pointer to a object to be stored, must be decendant of
  53.         //                base class ANYOBJECT.
  54.         //
  55.         // Return Values:
  56.         //     int      : Returns a error code indicating whether operation was
  57.         //                successful.
  58.         //                Values:
  59.         //                    0 = No Worries
  60.         //                   -1 = Arrgh ... No memory
  61.         //
  62.         int      putLast       (ANYOBJECT* pItem);
  63.  
  64.         // Take first item placed in Queue, out and return it.
  65.         // Type casting is required to return object back to it's orginial
  66.         // state.
  67.         //
  68.         // Return Values:
  69.         //     ANYOBJECT* : Pointer to the object that was stored within queue.
  70.         //
  71.         ANYOBJECT* takeNext      (void);
  72.  
  73.         // Returns the number of items contained within the queue.
  74.         //
  75.         // Returns Values:
  76.         //     int :    Num of items within queue.
  77.         //
  78.         int      status          (void);
  79.  
  80.         // Method returns whether last operation failed due to memory allocation
  81.         // failure.
  82.         //
  83.         // Return Values:
  84.         //     int  : Returns 1 of two values ...
  85.         //            Values:
  86.         //              0  =  memory available
  87.         //             -1  =  Last memory allocation failed.
  88.         //
  89.                                   // return Queue space left
  90.         int      space           (void);
  91.  
  92.         // Methods is used to peek within the queue at objects, and return there
  93.         // pointer without taking them out of the queue.
  94.         //
  95.         // Parameters:
  96.         //     NumFromNext : The object number to look at from the start of the
  97.         //                   queue. The start of the queue is 1, not 0.
  98.         //
  99.         // Return Values:
  100.         //     ANYOBJECT* : Pointer to the object that is stored within queue,
  101.         //                  at said position. Returns NULL if operation failed.
  102.         //
  103.         ANYOBJECT*   peek (int numFromNext);
  104.  
  105.         // Method will remove all list items from memory if they still exist,
  106.         // no garabage collection provided, or used.
  107.         //
  108.         ~QueueList      (void);
  109. };
  110.  
  111.  
  112. #endif
  113.  
  114.