home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLASSINC.ZIP / QUEUES.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  12.5 KB  |  456 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  QUEUES.H                                                              */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1992                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __QUEUES_H )
  11. #define __QUEUES_H
  12.  
  13. #if !defined( __DEFS_H )
  14. #include <_defs.h>
  15. #endif  // __DEFS_H
  16.  
  17. #if !defined( __DEQUES_H )
  18. #include <Deques.h>
  19. #endif  // __DEQUES_H
  20.  
  21. #pragma option -Vo-
  22. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  23. #pragma option -po-
  24. #endif
  25.  
  26. /*------------------------------------------------------------------------*/
  27. /*                                                                        */
  28. /*  template <class T> class BI_QueueAsVector                             */
  29. /*                                                                        */
  30. /*  Implements a queue of objects of type T, using a vector as            */
  31. /*  the underlying implementation.                                        */
  32. /*                                                                        */
  33. /*------------------------------------------------------------------------*/
  34.  
  35. template <class T> class _CLASSTYPE BI_QueueAsVector :
  36.     public BI_DequeAsVector<T>
  37. {
  38.  
  39. public:
  40.  
  41.     BI_QueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  42.         BI_DequeAsVector<T>(sz)
  43.         {
  44.         }
  45.  
  46.     T get()
  47.         {
  48.         return BI_DequeAsVector<T>::getRight();
  49.         }
  50.  
  51.     void put( T t )
  52.         {
  53.         BI_DequeAsVector<T>::putLeft( t );
  54.         }
  55.  
  56. private:
  57.  
  58.     T getLeft();
  59.     T getRight();
  60.  
  61.     void putLeft( T );
  62.     void putRight( T );
  63.  
  64. };
  65.  
  66. template <class T> class _CLASSTYPE BI_QueueAsVectorIterator :
  67.     public BI_DequeAsVectorIterator<T>
  68. {
  69.  
  70. public:
  71.  
  72.     BI_QueueAsVectorIterator( const BI_DequeAsVector<T> _FAR &q ) :
  73.         BI_DequeAsVectorIterator<T>(q) {}
  74.  
  75. };
  76.  
  77. /*------------------------------------------------------------------------*/
  78. /*                                                                        */
  79. /*  template <class T> class BI_IQueueAsVector                            */
  80. /*                                                                        */
  81. /*  Implements a queue of pointers to objects of type T,                  */
  82. /*  using a vector as the underlying implementation.                      */
  83. /*                                                                        */
  84. /*------------------------------------------------------------------------*/
  85.  
  86. template <class T> class _CLASSTYPE BI_IQueueAsVector :
  87.     public BI_IDequeAsVector<T>
  88. {
  89.  
  90. public:
  91.  
  92.     BI_IQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  93.         BI_IDequeAsVector<T>(sz)
  94.         {
  95.         }
  96.  
  97.     T _FAR *get()
  98.         {
  99.         return BI_IDequeAsVector<T>::getRight();
  100.         }
  101.  
  102.     void put( T _FAR *t )
  103.         {
  104.         BI_IDequeAsVector<T>::putLeft( t );
  105.         }
  106.  
  107. private:
  108.  
  109.     T _FAR *getLeft();
  110.     T _FAR *getRight();
  111.  
  112.     void putLeft( T _FAR * );
  113.     void putRight( T _FAR * );
  114.  
  115. };
  116.  
  117. template <class T> class _CLASSTYPE BI_IQueueAsVectorIterator :
  118.     public BI_IDequeAsVectorIterator<T>
  119. {
  120.  
  121. public:
  122.  
  123.     BI_IQueueAsVectorIterator( const BI_IDequeAsVector<T> _FAR &q ) :
  124.         BI_IDequeAsVectorIterator<T>(q) {}
  125.  
  126. };
  127.  
  128. /*------------------------------------------------------------------------*/
  129. /*                                                                        */
  130. /*  class BI_OQueueAsVector                                               */
  131. /*                                                                        */
  132. /*  Implements a queue of pointers to Object,                             */
  133. /*  using a vector as the underlying implementation.                      */
  134. /*                                                                        */
  135. /*------------------------------------------------------------------------*/
  136.  
  137. class _CLASSTYPE BI_OQueueAsVector : public BI_ODequeAsVector
  138. {
  139.  
  140. public:
  141.  
  142.     BI_OQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  143.         BI_ODequeAsVector(sz)
  144.         {
  145.         }
  146.  
  147.     Object _FAR *get()
  148.         {
  149.         return BI_ODequeAsVector::getRight();
  150.         }
  151.  
  152.     void put( Object _FAR *t )
  153.         {
  154.         BI_ODequeAsVector::putLeft( t );
  155.         }
  156.  
  157. private:
  158.  
  159.     Object _FAR *getLeft();
  160.     Object _FAR *getRight();
  161.  
  162.     void putLeft( Object _FAR * );
  163.     void putRight( Object _FAR * );
  164.  
  165. };
  166.  
  167. class _CLASSTYPE BI_OQueueAsVectorIterator :
  168.     public BI_ODequeAsVectorIterator
  169. {
  170.  
  171. public:
  172.  
  173.     BI_OQueueAsVectorIterator( const BI_ODequeAsVector _FAR &q ) :
  174.         BI_ODequeAsVectorIterator(q) {}
  175.  
  176. };
  177.  
  178. /*------------------------------------------------------------------------*/
  179. /*                                                                        */
  180. /*  class BI_TCQueueAsVector                                              */
  181. /*                                                                        */
  182. /*  Implements an Object queue, with the full semantics of                */
  183. /*  the BC 2.0 style queue, using a vector as the underlying              */
  184. /*  implementation.                                                       */
  185. /*                                                                        */
  186. /*------------------------------------------------------------------------*/
  187.  
  188. class _CLASSTYPE BI_TCQueueAsVector : public BI_TCDequeAsVector
  189. {
  190.  
  191. public:
  192.  
  193.     BI_TCQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  194.         BI_TCDequeAsVector(sz)
  195.         {
  196.         }
  197.  
  198.     Object _FAR & get()
  199.         {
  200.         return BI_TCDequeAsVector::getRight();
  201.         }
  202.  
  203.     void put( Object _FAR & t )
  204.         { BI_TCDequeAsVector::putLeft( t );
  205.         }
  206.  
  207.     virtual classType isA() const
  208.         {
  209.         return queueClass;
  210.         }
  211.  
  212.     virtual char _FAR *nameOf() const
  213.         {
  214.         return "BI_TCQueueAsDoubleList";
  215.         }
  216.  
  217.     virtual ContainerIterator _FAR & initIterator() const;
  218.  
  219. private:
  220.  
  221.     Object _FAR & getLeft();
  222.     Object _FAR & getRight();
  223.  
  224.     void putLeft( Object _FAR & );
  225.     void putRight( Object _FAR & );
  226.  
  227. };
  228.  
  229. class _CLASSTYPE BI_TCQueueAsVectorIterator :
  230.     public BI_TCDequeAsVectorIterator
  231. {
  232.  
  233. public:
  234.  
  235.     BI_TCQueueAsVectorIterator( const BI_TCQueueAsVector _FAR &q ) :
  236.         BI_TCDequeAsVectorIterator(q)
  237.         {
  238.         }
  239.  
  240. };
  241.  
  242. inline ContainerIterator _FAR & BI_TCQueueAsVector::initIterator() const
  243. {
  244.     return *new BI_TCQueueAsVectorIterator( *this );
  245. }
  246.  
  247. /*------------------------------------------------------------------------*/
  248. /*                                                                        */
  249. /*  template <class T> class BI_QueueAsDoubleList                         */
  250. /*                                                                        */
  251. /*  Implements a queue of objects of type T, using a double linked list   */
  252. /*  as the underlying implementation.                                     */
  253. /*                                                                        */
  254. /*------------------------------------------------------------------------*/
  255.  
  256. template <class T> class _CLASSTYPE BI_QueueAsDoubleList :
  257.     public BI_DequeAsDoubleList<T>
  258. {
  259.  
  260. public:
  261.  
  262.     T get()
  263.         {
  264.         return BI_DequeAsDoubleList<T>::getRight();
  265.         }
  266.  
  267.     void put( T t )
  268.         {
  269.         BI_DequeAsDoubleList<T>::putLeft( t );
  270.         }
  271.  
  272. private:
  273.  
  274.     T getLeft();
  275.     T getRight();
  276.  
  277.     void putLeft( T );
  278.     void putRight( T );
  279.  
  280. };
  281.  
  282. template <class T> class _CLASSTYPE BI_QueueAsDoubleListIterator :
  283.     public BI_DequeAsDoubleListIterator<T>
  284. {
  285.  
  286. public:
  287.  
  288.     BI_QueueAsDoubleListIterator( const BI_QueueAsDoubleList<T> _FAR & q ) :
  289.         BI_DequeAsDoubleListIterator<T>(q)
  290.         {
  291.         }
  292.  
  293. };
  294.  
  295. /*------------------------------------------------------------------------*/
  296. /*                                                                        */
  297. /*  template <class T> class BI_IQueueAsDoubleList                        */
  298. /*                                                                        */
  299. /*  Implements a queue of pointers to objects of type T,                  */
  300. /*  using a double linked list as the underlying implementation.          */
  301. /*                                                                        */
  302. /*------------------------------------------------------------------------*/
  303.  
  304. template <class T> class _CLASSTYPE BI_IQueueAsDoubleList :
  305.     public BI_IDequeAsDoubleList<T>
  306. {
  307.  
  308. public:
  309.  
  310.     T _FAR *get()
  311.         {
  312.         return BI_IDequeAsDoubleList<T>::getRight();
  313.         }
  314.  
  315.     void put( T _FAR *t )
  316.         {
  317.         BI_IDequeAsDoubleList<T>::putLeft( t );
  318.         }
  319.  
  320. private:
  321.  
  322.     T _FAR *getLeft();
  323.     T _FAR *getRight();
  324.  
  325.     void putLeft( T _FAR * );
  326.     void putRight( T _FAR * );
  327.  
  328. };
  329.  
  330. template <class T> class _CLASSTYPE BI_IQueueAsDoubleListIterator :
  331.     public BI_IDequeAsDoubleListIterator<T>
  332. {
  333.  
  334. public:
  335.  
  336.     BI_IQueueAsDoubleListIterator( const BI_IQueueAsDoubleList<T> _FAR& q ) :
  337.         BI_IDequeAsDoubleListIterator<T>(q) {}
  338.  
  339. };
  340.  
  341. /*------------------------------------------------------------------------*/
  342. /*                                                                        */
  343. /*  class BI_OQueueAsDoubleList                                           */
  344. /*                                                                        */
  345. /*  Implements a queue of pointers to Object,                             */
  346. /*  using a double linked list as the underlying implementation.          */
  347. /*                                                                        */
  348. /*------------------------------------------------------------------------*/
  349.  
  350. class _CLASSTYPE BI_OQueueAsDoubleList : public BI_ODequeAsDoubleList
  351. {
  352.  
  353. public:
  354.  
  355.     Object _FAR *get()
  356.         {
  357.         return BI_ODequeAsDoubleList::getRight();
  358.         }
  359.  
  360.     void put( Object _FAR *t )
  361.         {
  362.         BI_ODequeAsDoubleList::putLeft( t );
  363.         }
  364.  
  365. private:
  366.  
  367.     Object _FAR *getLeft();
  368.     Object _FAR *getRight();
  369.  
  370.     void putLeft( Object _FAR * );
  371.     void putRight( Object _FAR * );
  372.  
  373. };
  374.  
  375. class _CLASSTYPE BI_OQueueAsDoubleListIterator :
  376.     public BI_ODequeAsDoubleListIterator
  377. {
  378.  
  379. public:
  380.  
  381.     BI_OQueueAsDoubleListIterator( const BI_OQueueAsDoubleList _FAR & q ) :
  382.         BI_ODequeAsDoubleListIterator(q) {}
  383.  
  384. };
  385.  
  386. /*------------------------------------------------------------------------*/
  387. /*                                                                        */
  388. /*  class BI_TCQueueAsDoubleList                                          */
  389. /*                                                                        */
  390. /*  Implements an Object queue, with the full semantics of                */
  391. /*  the BC 2.0 style queue, using a double linked list as the underlying  */
  392. /*  implementation.                                                       */
  393. /*                                                                        */
  394. /*------------------------------------------------------------------------*/
  395.  
  396. class _CLASSTYPE BI_TCQueueAsDoubleList : public BI_TCDequeAsDoubleList
  397. {
  398.  
  399. public:
  400.  
  401.     Object _FAR & get()
  402.         {
  403.         return BI_TCDequeAsDoubleList::getRight();
  404.         }
  405.  
  406.     void put( Object _FAR & t )
  407.         {
  408.         BI_TCDequeAsDoubleList::putLeft( t );
  409.         }
  410.  
  411.     virtual classType isA() const
  412.         {
  413.         return queueClass;
  414.         }
  415.  
  416.     virtual char _FAR *nameOf() const
  417.         {
  418.         return "BI_TCQueueAsDoubleList";
  419.         }
  420.  
  421.     virtual ContainerIterator _FAR & initIterator() const;
  422.  
  423. private:
  424.  
  425.     Object _FAR & getLeft();
  426.     Object _FAR & getRight();
  427.  
  428.     void putLeft( Object _FAR & );
  429.     void putRight( Object _FAR & );
  430.  
  431. };
  432.  
  433. class _CLASSTYPE BI_TCQueueAsDoubleListIterator :
  434.     public BI_TCDequeAsDoubleListIterator
  435. {
  436.  
  437. public:
  438.  
  439.     BI_TCQueueAsDoubleListIterator( const BI_TCQueueAsDoubleList _FAR &q ) :
  440.         BI_TCDequeAsDoubleListIterator(q) {}
  441.  
  442. };
  443.  
  444. inline ContainerIterator _FAR & BI_TCQueueAsDoubleList::initIterator() const
  445. {
  446.     return *new BI_TCQueueAsDoubleListIterator( *this );
  447. }
  448.  
  449. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  450. #pragma option -po.
  451. #endif
  452. #pragma option -Vo.
  453.  
  454. #endif  // __QUEUES_H
  455.  
  456.