home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 12.ddi / CLASSINC.PAK / QUEUES.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  16.3 KB  |  545 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  QUEUES.H                                                              */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1993 Borland International                        */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __CLASSLIB_QUEUES_H )
  11. #define __CLASSLIB_QUEUES_H
  12.  
  13. #if !defined( __CLASSLIB_DEFS_H )
  14. #include "classlib\defs.h"
  15. #endif  // __CLASSLIB_DEFS_H
  16.  
  17. #if !defined( __CLASSLIB_DEQUES_H )
  18. #include "classlib\deques.h"
  19. #endif  // __CLASSLIB_DEQUES_H
  20.  
  21. #pragma option -Vo-
  22. #if defined( BI_CLASSLIB_NO_po )
  23. #pragma option -po-
  24. #endif
  25.  
  26. /*------------------------------------------------------------------------*/
  27. /*                                                                        */
  28. /*  template <class T,class Alloc> class TMQueueAsVector                  */
  29. /*  template <class T,class Alloc> class TMQueueAsVectorIterator          */
  30. /*                                                                        */
  31. /*  Implements a managed queue of objects of type T, using a vector as    */
  32. /*  the underlying implementation.                                        */
  33. /*                                                                        */
  34. /*------------------------------------------------------------------------*/
  35.  
  36. template <class T,class Alloc> class TMQueueAsVectorIterator;
  37.  
  38. template <class T,class Alloc> class TMQueueAsVector :
  39.     private TMDequeAsVector<T,Alloc>
  40. {
  41.  
  42.     typedef TMDequeAsVector<T,Alloc> Parent;
  43.  
  44. public:
  45.  
  46.     friend class TMQueueAsVectorIterator<T,Alloc>;
  47.  
  48.     TMQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  49.         TMDequeAsVector<T,Alloc>(sz)
  50.         {
  51.         }
  52.  
  53.     const T& Peek() const
  54.         {
  55.         return Parent::PeekRight();
  56.         }
  57.  
  58.     T Get()
  59.         {
  60.         return Parent::GetRight();
  61.         }
  62.  
  63.     void Put( const T& t )
  64.         {
  65.         Parent::PutLeft( t );
  66.         }
  67.  
  68.     Parent::IterFunc;
  69.     Parent::CondFunc;
  70.     Parent::ForEach;
  71.     Parent::FirstThat;
  72.     Parent::LastThat;
  73.     Parent::Flush;
  74.     Parent::IsFull;
  75.     Parent::IsEmpty;
  76.     Parent::GetItemsInContainer;
  77.  
  78. #if defined( BI_OLDNAMES )
  79.     T get() { return Get(); }
  80.     void put( const T& t ) { Put(t); }
  81.     Parent::forEach;
  82.     Parent::firstThat;
  83.     Parent::lastThat;
  84.     Parent::flush;
  85.     Parent::isFull;
  86.     Parent::isEmpty;
  87.     Parent::getItemsInContainer;
  88. #endif  // BI_OLDNAMES
  89.  
  90. };
  91.  
  92. template <class T,class Alloc> class TMQueueAsVectorIterator :
  93.     public TMDequeAsVectorIterator<T,Alloc>
  94. {
  95.  
  96. public:
  97.  
  98.     TMQueueAsVectorIterator( const TMQueueAsVector<T,Alloc>& q ) :
  99.         TMDequeAsVectorIterator<T,Alloc>(q)
  100.         {
  101.         }
  102.  
  103. };
  104.  
  105. #if defined( BI_OLDNAMES )
  106. #define BI_MQueueAsVector TMQueueAsVector
  107. #define BI_MQueueAsVectorIterator TMQueueAsVectorIterator
  108. #endif
  109.  
  110. /*------------------------------------------------------------------------*/
  111. /*                                                                        */
  112. /*  template <class T> class TQueueAsVector                               */
  113. /*  template <class T> class TQueueAsVectorIterator                       */
  114. /*                                                                        */
  115. /*  Implements a queue of objects of type T, using a vector as            */
  116. /*  the underlying implementation and TStandardAllocator as its memory    */
  117. /*  manager.                                                              */
  118. /*                                                                        */
  119. /*------------------------------------------------------------------------*/
  120.  
  121. template <class T> class TQueueAsVector :
  122.     public TMQueueAsVector<T,TStandardAllocator>
  123. {
  124.  
  125. public:
  126.  
  127.     TQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  128.         TMQueueAsVector<T,TStandardAllocator>(sz)
  129.         {
  130.         }
  131.  
  132. };
  133.  
  134. template <class T> class TQueueAsVectorIterator :
  135.     public TMQueueAsVectorIterator<T,TStandardAllocator>
  136. {
  137.  
  138. public:
  139.  
  140.     TQueueAsVectorIterator( const TQueueAsVector<T>& q ) :
  141.         TMQueueAsVectorIterator<T,TStandardAllocator>(q)
  142.         {
  143.         }
  144.  
  145. };
  146.  
  147. #if defined( BI_OLDNAMES )
  148. #define BI_QueueAsVector TQueueAsVector
  149. #define BI_QueueAsVectorIterator TQueueAsVectorIterator
  150. #endif
  151.  
  152. /*------------------------------------------------------------------------*/
  153. /*                                                                        */
  154. /*  template <class T,class Alloc> class TMIQueueAsVector                 */
  155. /*  template <class T,class Alloc> class TMIQueueAsVectorIterator         */
  156. /*                                                                        */
  157. /*  Implements a managed queue of pointers to objects of type T,          */
  158. /*  using a vector as the underlying implementation.                      */
  159. /*                                                                        */
  160. /*------------------------------------------------------------------------*/
  161.  
  162. template <class T,class Alloc> class TMIQueueAsVectorIterator;
  163.  
  164. template <class T,class Alloc> class TMIQueueAsVector :
  165.     private TMIDequeAsVector<T,Alloc>
  166. {
  167.  
  168.     typedef TMIDequeAsVector<T,Alloc> Parent;
  169.  
  170. public:
  171.  
  172.     friend class TMIQueueAsVectorIterator<T,Alloc>;
  173.  
  174.     TMIQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  175.         TMIDequeAsVector<T,Alloc>(sz)
  176.         {
  177.         }
  178.  
  179.     T *Peek() const
  180.         {
  181.         return Parent::PeekRight();
  182.         }
  183.  
  184.     T *Get()
  185.         {
  186.         return Parent::GetRight();
  187.         }
  188.  
  189.     void Put( T *t )
  190.         {
  191.         Parent::PutLeft( t );
  192.         }
  193.  
  194.     Parent::IterFunc;
  195.     Parent::CondFunc;
  196.     Parent::IsFull;
  197.     Parent::IsEmpty;
  198.     Parent::GetItemsInContainer;
  199.     Parent::Flush;
  200.     Parent::ForEach;
  201.     Parent::FirstThat;
  202.     Parent::LastThat;
  203.  
  204. #if defined( BI_OLDNAMES )
  205.     T *peek() const { return Peek(); }
  206.     T *get() { return Get(); }
  207.     void put( T *t ) { Put(t); }
  208.     Parent::isFull;
  209.     Parent::isEmpty;
  210.     Parent::getItemsInContainer;
  211.     Parent::flush;
  212.     Parent::forEach;
  213.     Parent::firstThat;
  214.     Parent::lastThat;
  215. #endif  // BI_OLDNAMES
  216.  
  217. };
  218.  
  219. template <class T,class Alloc> class TMIQueueAsVectorIterator :
  220.     public TMIDequeAsVectorIterator<T,Alloc>
  221. {
  222.  
  223. public:
  224.  
  225.     TMIQueueAsVectorIterator( const TMIQueueAsVector<T,Alloc>& q ) :
  226.         TMIDequeAsVectorIterator<T,Alloc>(q) {}
  227.  
  228. };
  229.  
  230. #if defined( BI_OLDNAMES )
  231. #define BI_MIQueueAsVector TMIQueueAsVector
  232. #define BI_MIQueueAsVectorIterator TMIQueueAsVectorIterator
  233. #endif
  234.  
  235. /*------------------------------------------------------------------------*/
  236. /*                                                                        */
  237. /*  template <class T> class TIQueueAsVector                              */
  238. /*  template <class T> class TIQueueAsVectorIterator                      */
  239. /*                                                                        */
  240. /*  Implements a queue of pointers to objects of type T,                  */
  241. /*  using a vector as the underlying implementation and                   */
  242. /*  TStandardAllocator as its memory manager.                             */
  243. /*                                                                        */
  244. /*------------------------------------------------------------------------*/
  245.  
  246. template <class T> class TIQueueAsVector :
  247.     public TMIQueueAsVector<T,TStandardAllocator>
  248. {
  249.  
  250. public:
  251.  
  252.     TIQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  253.         TMIQueueAsVector<T,TStandardAllocator>(sz)
  254.         {
  255.         }
  256.  
  257. };
  258.  
  259. template <class T> class TIQueueAsVectorIterator :
  260.     public TMIQueueAsVectorIterator<T,TStandardAllocator>
  261. {
  262.  
  263. public:
  264.  
  265.     TIQueueAsVectorIterator( const TIQueueAsVector<T>& q ) :
  266.         TMIQueueAsVectorIterator<T,TStandardAllocator>(q)
  267.         {
  268.         }
  269.  
  270. };
  271.  
  272. #if defined( BI_OLDNAMES )
  273. #define BI_IQueueAsVector TIQueueAsVector
  274. #define BI_IQueueAsVectorIterator TIQueueAsVectorIterator
  275. #endif
  276.  
  277. /*------------------------------------------------------------------------*/
  278. /*                                                                        */
  279. /*  template <class T,class Alloc> class TMQueueAsDoubleList              */
  280. /*  template <class T,class Alloc> class TMQueueAsDoubleListIterator      */
  281. /*                                                                        */
  282. /*  Implements a managed queue of objects of type T, using a double       */
  283. /*  linked list as the underlying implementation.                         */
  284. /*                                                                        */
  285. /*------------------------------------------------------------------------*/
  286.  
  287. template <class T,class Alloc> class TMQueueAsDoubleListIterator;
  288.  
  289. template <class T,class Alloc> class TMQueueAsDoubleList :
  290.     private TMDequeAsDoubleList<T,Alloc>
  291. {
  292.  
  293.     typedef TMDequeAsDoubleList<T,Alloc> Parent;
  294.  
  295. public:
  296.  
  297.     friend class TMQueueAsDoubleListIterator<T,Alloc>;
  298.  
  299.     const T& Peek() const
  300.         {
  301.         return Parent::PeekRight();
  302.         }
  303.  
  304.     T Get()
  305.         {
  306.         return Parent::GetRight();
  307.         }
  308.  
  309.     void Put( const T& t )
  310.         {
  311.         Parent::PutLeft( t );
  312.         }
  313.  
  314.     Parent::IterFunc;
  315.     Parent::CondFunc;
  316.     Parent::IsFull;
  317.     Parent::IsEmpty;
  318.     Parent::GetItemsInContainer;
  319.     Parent::Flush;
  320.     Parent::ForEach;
  321.     Parent::FirstThat;
  322.     Parent::LastThat;
  323.  
  324. #if defined( BI_OLDNAMES )
  325.     T peek() const { return Peek(); }
  326.     T get() { return Get(); }
  327.     void put( const T& t ) { Put(t); }
  328.     Parent::isFull;
  329.     Parent::isEmpty;
  330.     Parent::getItemsInContainer;
  331.     Parent::flush;
  332.     Parent::forEach;
  333.     Parent::firstThat;
  334.     Parent::lastThat;
  335. #endif  // BI_OLDNAMES
  336.  
  337. };
  338.  
  339. template <class T,class Alloc> class TMQueueAsDoubleListIterator :
  340.     public TMDequeAsDoubleListIterator<T,Alloc>
  341. {
  342.  
  343. public:
  344.  
  345.     TMQueueAsDoubleListIterator( const TMQueueAsDoubleList<T,Alloc>& q ) :
  346.         TMDequeAsDoubleListIterator<T,Alloc>(q)
  347.         {
  348.         }
  349.  
  350. };
  351.  
  352. #if defined( BI_OLDNAMES )
  353. #define BI_QueueAsDoubleList TQueueAsDoubleList
  354. #define BI_QueueAsDoubleListIterator TQueueAsDoubleListIterator
  355. #endif
  356.  
  357. /*------------------------------------------------------------------------*/
  358. /*                                                                        */
  359. /*  template <class T> class TQueueAsDoubleList                           */
  360. /*  template <class T> class TQueueAsDoubleListIterator                   */
  361. /*                                                                        */
  362. /*  Implements a queue of objects of type T, using a double linked list   */
  363. /*  as the underlying implementation and TStandardAllocator as its        */
  364. /*  memory manager.                                                       */
  365. /*                                                                        */
  366. /*------------------------------------------------------------------------*/
  367.  
  368. template <class T> class TQueueAsDoubleList :
  369.     public TMQueueAsDoubleList<T,TStandardAllocator>
  370. {
  371. };
  372.  
  373. template <class T> class TQueueAsDoubleListIterator :
  374.     public TMQueueAsDoubleListIterator<T,TStandardAllocator>
  375. {
  376.  
  377. public:
  378.  
  379.     TQueueAsDoubleListIterator( const TQueueAsDoubleList<T>& q ) :
  380.         TMQueueAsDoubleListIterator<T,TStandardAllocator>(q)
  381.         {
  382.         }
  383.  
  384. };
  385.  
  386. #if defined( BI_OLDNAMES )
  387. #define BI_QueueAsDoubleList TQueueAsDoubleList
  388. #define BI_QueueAsDoubleListIterator TQueueAsDoubleListIterator
  389. #endif
  390.  
  391. /*------------------------------------------------------------------------*/
  392. /*                                                                        */
  393. /*  template <class T,class Alloc> class TMIQueueAsDoubleList             */
  394. /*  template <class T,class Alloc> class TMIQueueAsDoubleListIterator     */
  395. /*                                                                        */
  396. /*  Implements a managed queue of pointers to objects of type T,          */
  397. /*  using a double linked list as the underlying implementation.          */
  398. /*                                                                        */
  399. /*------------------------------------------------------------------------*/
  400.  
  401. template <class T,class Alloc> class TMIQueueAsDoubleListIterator;
  402.  
  403. template <class T,class Alloc> class TMIQueueAsDoubleList :
  404.     private TMIDequeAsDoubleList<T,Alloc>
  405. {
  406.  
  407.     typedef TMIDequeAsDoubleList<T,Alloc> Parent;
  408.  
  409. public:
  410.  
  411.     friend class TMIQueueAsDoubleListIterator<T,Alloc>;
  412.  
  413.     T *Peek() const
  414.         {
  415.         return Parent::PeekRight();
  416.         }
  417.  
  418.     T *Get()
  419.         {
  420.         return Parent::GetRight();
  421.         }
  422.  
  423.     void Put( T *t )
  424.         {
  425.         Parent::PutLeft( t );
  426.         }
  427.  
  428.     Parent::IterFunc;
  429.     Parent::CondFunc;
  430.     Parent::IsFull;
  431.     Parent::IsEmpty;
  432.     Parent::GetItemsInContainer;
  433.     Parent::Flush;
  434.     Parent::ForEach;
  435.     Parent::FirstThat;
  436.     Parent::LastThat;
  437.  
  438. #if defined( BI_OLDNAMES )
  439.     T *peek() const { return Peek(); }
  440.     T *get() { return Get(); }
  441.     void put( T *t ) { Put(t); }
  442.     Parent::isFull;
  443.     Parent::isEmpty;
  444.     Parent::getItemsInContainer;
  445.     Parent::flush;
  446.     Parent::forEach;
  447.     Parent::firstThat;
  448.     Parent::lastThat;
  449. #endif  // BI_OLDNAMES
  450.  
  451. };
  452.  
  453. template <class T,class Alloc> class TMIQueueAsDoubleListIterator :
  454.     public TMIDequeAsDoubleListIterator<T,Alloc>
  455. {
  456.  
  457. public:
  458.  
  459.     TMIQueueAsDoubleListIterator( const TMIQueueAsDoubleList<T,Alloc>& q ) :
  460.         TMIDequeAsDoubleListIterator<T,Alloc>(q) {}
  461.  
  462. };
  463.  
  464. #if defined( BI_OLDNAMES )
  465. #define BI_MIQueueAsDoubleList TMIQueueAsDoubleList
  466. #define BI_MIQueueAsDoubleListIterator TMIQueueAsDoubleListIterator
  467. #endif
  468.  
  469. /*------------------------------------------------------------------------*/
  470. /*                                                                        */
  471. /*  template <class T> class TIQueueAsDoubleList                          */
  472. /*  template <class T> class TIQueueAsDoubleListIterator                  */
  473. /*                                                                        */
  474. /*  Implements a queue of pointers to objects of type T, using a double   */
  475. /*  linked list as the underlying implementation and TStandardAllocator   */
  476. /*  as its memory manager.                                                */
  477. /*                                                                        */
  478. /*------------------------------------------------------------------------*/
  479.  
  480. template <class T> class TIQueueAsDoubleList :
  481.     public TMIQueueAsDoubleList<T,TStandardAllocator>
  482. {
  483. };
  484.  
  485. template <class T> class TIQueueAsDoubleListIterator :
  486.     public TMIQueueAsDoubleListIterator<T,TStandardAllocator>
  487. {
  488.  
  489. public:
  490.  
  491.     TIQueueAsDoubleListIterator( const TIQueueAsDoubleList<T>& q ) :
  492.         TMIQueueAsDoubleListIterator<T,TStandardAllocator>(q) {}
  493.  
  494. };
  495.  
  496. #if defined( BI_OLDNAMES )
  497. #define BI_IQueueAsDoubleList TIQueueAsDoubleList
  498. #define BI_IQueueAsDoubleListIterator TIQueueAsDoubleListIterator
  499. #endif
  500.  
  501. /*------------------------------------------------------------------------*/
  502. /*                                                                        */
  503. /*  template <class T> class TQueue                                       */
  504. /*  template <class T> class TQueueIterator                               */
  505. /*                                                                        */
  506. /*  Easy names for TQueueAsVector and TQueueAsVectorIterator              */
  507. /*                                                                        */
  508. /*------------------------------------------------------------------------*/
  509.  
  510. template <class T> class TQueue :
  511.     public TQueueAsVector<T>
  512. {
  513.  
  514. public:
  515.  
  516.     TQueue( unsigned max = DEFAULT_QUEUE_SIZE ) :
  517.         TQueueAsVector<T>( max )
  518.         {
  519.         }
  520.  
  521. }
  522.  
  523. template <class T> class TQueueIterator :
  524.     public TQueueAsVectorIterator<T>
  525. {
  526.  
  527. public:
  528.  
  529.  
  530.     TQueueIterator( const TQueue<T>& a ) :
  531.         TQueueAsVectorIterator<T>(a)
  532.         {
  533.         }
  534.  
  535. };
  536.  
  537. #if defined( BI_CLASSLIB_NO_po )
  538. #pragma option -po.
  539. #endif
  540.  
  541. #pragma option -Vo.
  542.  
  543. #endif  // __CLASSLIB_QUEUES_H
  544.  
  545.