home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / CLOBSH.PAK / QUEUE.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  9KB  |  332 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  QUEUE.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __QUEUE_H )
  11. #define __QUEUE_H
  12.  
  13. #define BI_OLDNAMES
  14.  
  15. #if !defined( TEMPLATES )
  16.  
  17. #if !defined( __CLSTYPES_H )
  18. #include "classlib\obsolete\ClsTypes.h"
  19. #endif  // __CLSTYPES_H
  20.  
  21. #if !defined( __DEQUE_H )
  22. #include "classlib\obsolete\Deque.h"
  23. #endif  // __DEQUE_H
  24.  
  25. #pragma option -Vo-
  26. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  27. #pragma option -po-
  28. #endif
  29.  
  30. _CLASSDEF(Queue)
  31.  
  32. class _CLASSTYPE Queue : public Deque
  33. {
  34.  
  35. public:
  36.  
  37.     Object _FAR & get()
  38.         {
  39.         return Deque::getRight();
  40.         }
  41.  
  42.     void put( Object _FAR & o )
  43.         {
  44.         Deque::putLeft( o );
  45.         }
  46.  
  47.     virtual classType isA() const
  48.         {
  49.         return queueClass;
  50.         }
  51.  
  52.     virtual char _FAR *nameOf() const
  53.         {
  54.         return "Queue";
  55.         }
  56.  
  57. private:
  58.  
  59.     Object _FAR & getLeft();
  60.     Object _FAR & getRight();
  61.  
  62.     void putLeft( Object _FAR & );
  63.     void putRight( Object _FAR & );
  64.  
  65. };
  66.  
  67. #else   // TEMPLATES
  68.  
  69. #if !defined( __QUEUES_H )
  70. #include "classlib\Queues.h"
  71. #endif  // __QUEUES_H
  72.  
  73. #pragma option -Vo-
  74. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  75. #pragma option -po-
  76. #endif
  77.  
  78. #define Queue   BI_TCQueueAsDoubleList
  79. #define PQueue  PBI_TCQueueAsDoubleList
  80. #define RQueue  RBI_TCQueueAsDoubleList
  81. #define RPQueue RPBI_TCQueueAsDoubleList
  82. #define PCQueue PCBI_TCQueueAsDoubleList
  83. #define RCQueue RCBI_TCQueueAsDoubleList
  84.  
  85. _CLASSDEF( BI_TCQueueAsDoubleList )
  86.  
  87. #define QueueIterator   BI_TCQueueAsDoubleListIterator
  88. #define PQueueIterator  PBI_TCQueueAsDoubleListIterator
  89. #define RQueueIterator  RBI_TCQueueAsDoubleListIterator
  90. #define RPQueueIterator RPBI_TCQueueAsDoubleListIterator
  91. #define PCQueueIterator PCBI_TCQueueAsDoubleListIterator
  92. #define RCQueueIterator RCBI_TCQueueAsDoubleListIterator
  93.  
  94. _CLASSDEF( BI_TCQueueAsDoubleListIterator )
  95.  
  96. /*------------------------------------------------------------------------*/
  97. /*                                                                        */
  98. /*  class BI_OQueueAsVector                                               */
  99. /*                                                                        */
  100. /*  Implements a queue of pointers to Object,                             */
  101. /*  using a vector as the underlying implementation.                      */
  102. /*                                                                        */
  103. /*------------------------------------------------------------------------*/
  104.  
  105. class _CLASSTYPE BI_OQueueAsVector : public BI_ODequeAsVector
  106. {
  107.  
  108. public:
  109.  
  110.     BI_OQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  111.         BI_ODequeAsVector(sz)
  112.         {
  113.         }
  114.  
  115.     Object _FAR *get()
  116.         {
  117.         return BI_ODequeAsVector::getRight();
  118.         }
  119.  
  120.     void put( Object _FAR *t )
  121.         {
  122.         BI_ODequeAsVector::putLeft( t );
  123.         }
  124.  
  125. private:
  126.  
  127.     Object _FAR *getLeft();
  128.     Object _FAR *getRight();
  129.  
  130.     void putLeft( Object _FAR * );
  131.     void putRight( Object _FAR * );
  132.  
  133. };
  134.  
  135. class _CLASSTYPE BI_OQueueAsVectorIterator :
  136.     public BI_ODequeAsVectorIterator
  137. {
  138.  
  139. public:
  140.  
  141.     BI_OQueueAsVectorIterator( const BI_ODequeAsVector _FAR &q ) :
  142.         BI_ODequeAsVectorIterator(q) {}
  143.  
  144. };
  145.  
  146. /*------------------------------------------------------------------------*/
  147. /*                                                                        */
  148. /*  class BI_TCQueueAsVector                                              */
  149. /*                                                                        */
  150. /*  Implements an Object queue, with the full semantics of                */
  151. /*  the BC 2.0 style queue, using a vector as the underlying              */
  152. /*  implementation.                                                       */
  153. /*                                                                        */
  154. /*------------------------------------------------------------------------*/
  155.  
  156. class _CLASSTYPE BI_TCQueueAsVector : public BI_TCDequeAsVector
  157. {
  158.  
  159. public:
  160.  
  161.     BI_TCQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  162.         BI_TCDequeAsVector(sz)
  163.         {
  164.         }
  165.  
  166.     Object _FAR & get()
  167.         {
  168.         return BI_TCDequeAsVector::getRight();
  169.         }
  170.  
  171.     void put( Object _FAR & t )
  172.         { BI_TCDequeAsVector::putLeft( t );
  173.         }
  174.  
  175.     virtual classType isA() const
  176.         {
  177.         return queueClass;
  178.         }
  179.  
  180.     virtual char _FAR *nameOf() const
  181.         {
  182.         return "BI_TCQueueAsDoubleList";
  183.         }
  184.  
  185.     virtual ContainerIterator _FAR & initIterator() const;
  186.  
  187. private:
  188.  
  189.     Object _FAR & getLeft();
  190.     Object _FAR & getRight();
  191.  
  192.     void putLeft( Object _FAR & );
  193.     void putRight( Object _FAR & );
  194.  
  195. };
  196.  
  197. class _CLASSTYPE BI_TCQueueAsVectorIterator :
  198.     public BI_TCDequeAsVectorIterator
  199. {
  200.  
  201. public:
  202.  
  203.     BI_TCQueueAsVectorIterator( const BI_TCQueueAsVector _FAR &q ) :
  204.         BI_TCDequeAsVectorIterator(q)
  205.         {
  206.         }
  207.  
  208. };
  209.  
  210. inline ContainerIterator _FAR & BI_TCQueueAsVector::initIterator() const
  211. {
  212.     return *new BI_TCQueueAsVectorIterator( *this );
  213. }
  214.  
  215. /*------------------------------------------------------------------------*/
  216. /*                                                                        */
  217. /*  class BI_OQueueAsDoubleList                                           */
  218. /*                                                                        */
  219. /*  Implements a queue of pointers to Object,                             */
  220. /*  using a double linked list as the underlying implementation.          */
  221. /*                                                                        */
  222. /*------------------------------------------------------------------------*/
  223.  
  224. class _CLASSTYPE BI_OQueueAsDoubleList : public BI_ODequeAsDoubleList
  225. {
  226.  
  227. public:
  228.  
  229.     Object _FAR *get()
  230.         {
  231.         return BI_ODequeAsDoubleList::getRight();
  232.         }
  233.  
  234.     void put( Object _FAR *t )
  235.         {
  236.         BI_ODequeAsDoubleList::putLeft( t );
  237.         }
  238.  
  239. private:
  240.  
  241.     Object _FAR *getLeft();
  242.     Object _FAR *getRight();
  243.  
  244.     void putLeft( Object _FAR * );
  245.     void putRight( Object _FAR * );
  246.  
  247. };
  248.  
  249. class _CLASSTYPE BI_OQueueAsDoubleListIterator :
  250.     public BI_ODequeAsDoubleListIterator
  251. {
  252.  
  253. public:
  254.  
  255.     BI_OQueueAsDoubleListIterator( const BI_OQueueAsDoubleList _FAR & q ) :
  256.         BI_ODequeAsDoubleListIterator(q) {}
  257.  
  258. };
  259.  
  260. /*------------------------------------------------------------------------*/
  261. /*                                                                        */
  262. /*  class BI_TCQueueAsDoubleList                                          */
  263. /*                                                                        */
  264. /*  Implements an Object queue, with the full semantics of                */
  265. /*  the BC 2.0 style queue, using a double linked list as the underlying  */
  266. /*  implementation.                                                       */
  267. /*                                                                        */
  268. /*------------------------------------------------------------------------*/
  269.  
  270. class _CLASSTYPE BI_TCQueueAsDoubleList : public BI_TCDequeAsDoubleList
  271. {
  272.  
  273. public:
  274.  
  275.     Object _FAR & get()
  276.         {
  277.         return BI_TCDequeAsDoubleList::getRight();
  278.         }
  279.  
  280.     void put( Object _FAR & t )
  281.         {
  282.         BI_TCDequeAsDoubleList::putLeft( t );
  283.         }
  284.  
  285.     virtual classType isA() const
  286.         {
  287.         return queueClass;
  288.         }
  289.  
  290.     virtual char _FAR *nameOf() const
  291.         {
  292.         return "BI_TCQueueAsDoubleList";
  293.         }
  294.  
  295.     virtual ContainerIterator _FAR & initIterator() const;
  296.  
  297. private:
  298.  
  299.     Object _FAR & getLeft();
  300.     Object _FAR & getRight();
  301.  
  302.     void putLeft( Object _FAR & );
  303.     void putRight( Object _FAR & );
  304.  
  305. };
  306.  
  307. class _CLASSTYPE BI_TCQueueAsDoubleListIterator :
  308.     public BI_TCDequeAsDoubleListIterator
  309. {
  310.  
  311. public:
  312.  
  313.     BI_TCQueueAsDoubleListIterator( const BI_TCQueueAsDoubleList _FAR &q ) :
  314.         BI_TCDequeAsDoubleListIterator(q) {}
  315.  
  316. };
  317.  
  318. inline ContainerIterator _FAR & BI_TCQueueAsDoubleList::initIterator() const
  319. {
  320.     return *new BI_TCQueueAsDoubleListIterator( *this );
  321. }
  322.  
  323. #endif  // TEMPLATES
  324.  
  325. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  326. #pragma option -po.
  327. #endif
  328. #pragma option -Vo.
  329.  
  330. #endif  // __QUEUE_H
  331.  
  332.