home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / MachOViewer / Source / Queue.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  1.7 KB  |  58 lines

  1. #ifndef _QUEUE_H
  2. #define _QUEUE_H
  3.  
  4. //H+
  5. // A first-in, first-out queue, or last-in, first-out stack.
  6. //
  7. // Holds a series of (void *)pointers for generality, but may require
  8. // casting to get the push: method to compile clean.
  9. //
  10. //    $Id: Queue.h,v 1.3 94/05/23 20:33:04 ediger Exp Locker: ediger $
  11. /*    $Log:    Queue.h,v $
  12.  * Revision 1.3  94/05/23  20:33:04  ediger
  13.  * better comments
  14.  * 
  15.  * Revision 1.2  94/05/15  18:55:28  ediger
  16.  * remove a method namespace clash by changing -empty to -isEmpty.
  17.  * 
  18.  * Revision 1.1  94/05/14  17:44:50  ediger
  19.  * Initial revision
  20.  * 
  21.  */
  22. //H-
  23.  
  24. #import <objc/Object.h>
  25.  
  26. // Here's the data structure for the implementation: a doubly-linked list.
  27. // Elaborate struct tag to avoid name-space collisions.
  28. struct qs_internal_node {
  29.     struct qs_internal_node *prev;
  30.     struct qs_internal_node *next;
  31.     void                    *ptr;
  32. };
  33.  
  34. // It's possible that the ptr member should be a union of all
  35. // inherent Obj-C datatypes.  That would certainly ensure that
  36. // enough space is reserved for the stored data.  Doing the class
  37. // with that data would require "typed" pushes and pops, wouldn't it?
  38. // At least to avoid casting the data on pushes or pops.
  39.  
  40. @interface Queue: Object
  41. {
  42.     struct qs_internal_node *head;
  43.     struct qs_internal_node *tail;
  44. }
  45.  
  46. - init;
  47. - push:(void *)something;  // put something on end of container
  48. -(void *)first;            // FIFO access to container
  49. -(void *)pop;              // LIFO access to container
  50. -(void *)head;             // peek at what's at the head of container
  51. -(void *)tail;             // peek at what's at the tail of container
  52. -(BOOL)isEmpty;            // check if container has something in it.
  53. - free;                    // deallocate implementation of container
  54.  
  55. @end
  56.  
  57. #endif /* _QUEUE_H */
  58.