home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / classinc.pak / QUEUES.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  17KB  |  549 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  QUEUES.H                                                              */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1994 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
  16.  
  17. #if !defined( CLASSLIB_DEQUES_H )
  18. #include <classlib/deques.h>
  19. #endif
  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.     Parent::OwnsElements;
  204.  
  205. #if defined( BI_OLDNAMES )
  206.     T *peek() const { return Peek(); }
  207.     T *get() { return Get(); }
  208.     void put( T *t ) { Put(t); }
  209.     Parent::isFull;
  210.     Parent::isEmpty;
  211.     Parent::getItemsInContainer;
  212.     Parent::flush;
  213.     Parent::forEach;
  214.     Parent::firstThat;
  215.     Parent::lastThat;
  216.     Parent::ownsElements;
  217. #endif  // BI_OLDNAMES
  218.  
  219. };
  220.  
  221. template <class T,class Alloc> class TMIQueueAsVectorIterator :
  222.     public TMIDequeAsVectorIterator<T,Alloc>
  223. {
  224.  
  225. public:
  226.  
  227.     TMIQueueAsVectorIterator( const TMIQueueAsVector<T,Alloc>& q ) :
  228.         TMIDequeAsVectorIterator<T,Alloc>(q) {}
  229.  
  230. };
  231.  
  232. #if defined( BI_OLDNAMES )
  233. #define BI_MIQueueAsVector TMIQueueAsVector
  234. #define BI_MIQueueAsVectorIterator TMIQueueAsVectorIterator
  235. #endif
  236.  
  237. /*------------------------------------------------------------------------*/
  238. /*                                                                        */
  239. /*  template <class T> class TIQueueAsVector                              */
  240. /*  template <class T> class TIQueueAsVectorIterator                      */
  241. /*                                                                        */
  242. /*  Implements a queue of pointers to objects of type T,                  */
  243. /*  using a vector as the underlying implementation and                   */
  244. /*  TStandardAllocator as its memory manager.                             */
  245. /*                                                                        */
  246. /*------------------------------------------------------------------------*/
  247.  
  248. template <class T> class TIQueueAsVector :
  249.     public TMIQueueAsVector<T,TStandardAllocator>
  250. {
  251.  
  252. public:
  253.  
  254.     TIQueueAsVector( unsigned sz = DEFAULT_QUEUE_SIZE ) :
  255.         TMIQueueAsVector<T,TStandardAllocator>(sz)
  256.         {
  257.         }
  258.  
  259. };
  260.  
  261. template <class T> class TIQueueAsVectorIterator :
  262.     public TMIQueueAsVectorIterator<T,TStandardAllocator>
  263. {
  264.  
  265. public:
  266.  
  267.     TIQueueAsVectorIterator( const TIQueueAsVector<T>& q ) :
  268.         TMIQueueAsVectorIterator<T,TStandardAllocator>(q)
  269.         {
  270.         }
  271.  
  272. };
  273.  
  274. #if defined( BI_OLDNAMES )
  275. #define BI_IQueueAsVector TIQueueAsVector
  276. #define BI_IQueueAsVectorIterator TIQueueAsVectorIterator
  277. #endif
  278.  
  279. /*------------------------------------------------------------------------*/
  280. /*                                                                        */
  281. /*  template <class T,class Alloc> class TMQueueAsDoubleList              */
  282. /*  template <class T,class Alloc> class TMQueueAsDoubleListIterator      */
  283. /*                                                                        */
  284. /*  Implements a managed queue of objects of type T, using a double       */
  285. /*  linked list as the underlying implementation.                         */
  286. /*                                                                        */
  287. /*------------------------------------------------------------------------*/
  288.  
  289. template <class T,class Alloc> class TMQueueAsDoubleListIterator;
  290.  
  291. template <class T,class Alloc> class TMQueueAsDoubleList :
  292.     private TMDequeAsDoubleList<T,Alloc>
  293. {
  294.  
  295.     typedef TMDequeAsDoubleList<T,Alloc> Parent;
  296.  
  297. public:
  298.  
  299.     friend class TMQueueAsDoubleListIterator<T,Alloc>;
  300.  
  301.     const T& Peek() const
  302.         {
  303.         return Parent::PeekRight();
  304.         }
  305.  
  306.     T Get()
  307.         {
  308.         return Parent::GetRight();
  309.         }
  310.  
  311.     void Put( const T& t )
  312.         {
  313.         Parent::PutLeft( t );
  314.         }
  315.  
  316.     Parent::IterFunc;
  317.     Parent::CondFunc;
  318.     Parent::IsFull;
  319.     Parent::IsEmpty;
  320.     Parent::GetItemsInContainer;
  321.     Parent::Flush;
  322.     Parent::ForEach;
  323.     Parent::FirstThat;
  324.     Parent::LastThat;
  325.  
  326. #if defined( BI_OLDNAMES )
  327.     T peek() const { return Peek(); }
  328.     T get() { return Get(); }
  329.     void put( const T& t ) { Put(t); }
  330.     Parent::isFull;
  331.     Parent::isEmpty;
  332.     Parent::getItemsInContainer;
  333.     Parent::flush;
  334.     Parent::forEach;
  335.     Parent::firstThat;
  336.     Parent::lastThat;
  337. #endif  // BI_OLDNAMES
  338.  
  339. };
  340.  
  341. template <class T,class Alloc> class TMQueueAsDoubleListIterator :
  342.     public TMDequeAsDoubleListIterator<T,Alloc>
  343. {
  344.  
  345. public:
  346.  
  347.     TMQueueAsDoubleListIterator( const TMQueueAsDoubleList<T,Alloc>& q ) :
  348.         TMDequeAsDoubleListIterator<T,Alloc>(q)
  349.         {
  350.         }
  351.  
  352. };
  353.  
  354. #if defined( BI_OLDNAMES )
  355. #define BI_QueueAsDoubleList TQueueAsDoubleList
  356. #define BI_QueueAsDoubleListIterator TQueueAsDoubleListIterator
  357. #endif
  358.  
  359. /*------------------------------------------------------------------------*/
  360. /*                                                                        */
  361. /*  template <class T> class TQueueAsDoubleList                           */
  362. /*  template <class T> class TQueueAsDoubleListIterator                   */
  363. /*                                                                        */
  364. /*  Implements a queue of objects of type T, using a double linked list   */
  365. /*  as the underlying implementation and TStandardAllocator as its        */
  366. /*  memory manager.                                                       */
  367. /*                                                                        */
  368. /*------------------------------------------------------------------------*/
  369.  
  370. template <class T> class TQueueAsDoubleList :
  371.     public TMQueueAsDoubleList<T,TStandardAllocator>
  372. {
  373. };
  374.  
  375. template <class T> class TQueueAsDoubleListIterator :
  376.     public TMQueueAsDoubleListIterator<T,TStandardAllocator>
  377. {
  378.  
  379. public:
  380.  
  381.     TQueueAsDoubleListIterator( const TQueueAsDoubleList<T>& q ) :
  382.         TMQueueAsDoubleListIterator<T,TStandardAllocator>(q)
  383.         {
  384.         }
  385.  
  386. };
  387.  
  388. #if defined( BI_OLDNAMES )
  389. #define BI_QueueAsDoubleList TQueueAsDoubleList
  390. #define BI_QueueAsDoubleListIterator TQueueAsDoubleListIterator
  391. #endif
  392.  
  393. /*------------------------------------------------------------------------*/
  394. /*                                                                        */
  395. /*  template <class T,class Alloc> class TMIQueueAsDoubleList             */
  396. /*  template <class T,class Alloc> class TMIQueueAsDoubleListIterator     */
  397. /*                                                                        */
  398. /*  Implements a managed queue of pointers to objects of type T,          */
  399. /*  using a double linked list as the underlying implementation.          */
  400. /*                                                                        */
  401. /*------------------------------------------------------------------------*/
  402.  
  403. template <class T,class Alloc> class TMIQueueAsDoubleListIterator;
  404.  
  405. template <class T,class Alloc> class TMIQueueAsDoubleList :
  406.     private TMIDequeAsDoubleList<T,Alloc>
  407. {
  408.  
  409.     typedef TMIDequeAsDoubleList<T,Alloc> Parent;
  410.  
  411. public:
  412.  
  413.     friend class TMIQueueAsDoubleListIterator<T,Alloc>;
  414.  
  415.     T *Peek() const
  416.         {
  417.         return Parent::PeekRight();
  418.         }
  419.  
  420.     T *Get()
  421.         {
  422.         return Parent::GetRight();
  423.         }
  424.  
  425.     void Put( T *t )
  426.         {
  427.         Parent::PutLeft( t );
  428.         }
  429.  
  430.     Parent::IterFunc;
  431.     Parent::CondFunc;
  432.     Parent::IsFull;
  433.     Parent::IsEmpty;
  434.     Parent::GetItemsInContainer;
  435.     Parent::Flush;
  436.     Parent::ForEach;
  437.     Parent::FirstThat;
  438.     Parent::LastThat;
  439.     Parent::OwnsElements;
  440.  
  441. #if defined( BI_OLDNAMES )
  442.     T *peek() const { return Peek(); }
  443.     T *get() { return Get(); }
  444.     void put( T *t ) { Put(t); }
  445.     Parent::isFull;
  446.     Parent::isEmpty;
  447.     Parent::getItemsInContainer;
  448.     Parent::flush;
  449.     Parent::forEach;
  450.     Parent::firstThat;
  451.     Parent::lastThat;
  452.     Parent::ownsElements;
  453. #endif  // BI_OLDNAMES
  454.  
  455. };
  456.  
  457. template <class T,class Alloc> class TMIQueueAsDoubleListIterator :
  458.     public TMIDequeAsDoubleListIterator<T,Alloc>
  459. {
  460.  
  461. public:
  462.  
  463.     TMIQueueAsDoubleListIterator( const TMIQueueAsDoubleList<T,Alloc>& q ) :
  464.         TMIDequeAsDoubleListIterator<T,Alloc>(q) {}
  465.  
  466. };
  467.  
  468. #if defined( BI_OLDNAMES )
  469. #define BI_MIQueueAsDoubleList TMIQueueAsDoubleList
  470. #define BI_MIQueueAsDoubleListIterator TMIQueueAsDoubleListIterator
  471. #endif
  472.  
  473. /*------------------------------------------------------------------------*/
  474. /*                                                                        */
  475. /*  template <class T> class TIQueueAsDoubleList                          */
  476. /*  template <class T> class TIQueueAsDoubleListIterator                  */
  477. /*                                                                        */
  478. /*  Implements a queue of pointers to objects of type T, using a double   */
  479. /*  linked list as the underlying implementation and TStandardAllocator   */
  480. /*  as its memory manager.                                                */
  481. /*                                                                        */
  482. /*------------------------------------------------------------------------*/
  483.  
  484. template <class T> class TIQueueAsDoubleList :
  485.     public TMIQueueAsDoubleList<T,TStandardAllocator>
  486. {
  487. };
  488.  
  489. template <class T> class TIQueueAsDoubleListIterator :
  490.     public TMIQueueAsDoubleListIterator<T,TStandardAllocator>
  491. {
  492.  
  493. public:
  494.  
  495.     TIQueueAsDoubleListIterator( const TIQueueAsDoubleList<T>& q ) :
  496.         TMIQueueAsDoubleListIterator<T,TStandardAllocator>(q) {}
  497.  
  498. };
  499.  
  500. #if defined( BI_OLDNAMES )
  501. #define BI_IQueueAsDoubleList TIQueueAsDoubleList
  502. #define BI_IQueueAsDoubleListIterator TIQueueAsDoubleListIterator
  503. #endif
  504.  
  505. /*------------------------------------------------------------------------*/
  506. /*                                                                        */
  507. /*  template <class T> class TQueue                                       */
  508. /*  template <class T> class TQueueIterator                               */
  509. /*                                                                        */
  510. /*  Easy names for TQueueAsVector and TQueueAsVectorIterator              */
  511. /*                                                                        */
  512. /*------------------------------------------------------------------------*/
  513.  
  514. template <class T> class TQueue :
  515.     public TQueueAsVector<T>
  516. {
  517.  
  518. public:
  519.  
  520.     TQueue( unsigned max = DEFAULT_QUEUE_SIZE ) :
  521.         TQueueAsVector<T>( max )
  522.         {
  523.         }
  524.  
  525. }
  526.  
  527. template <class T> class TQueueIterator :
  528.     public TQueueAsVectorIterator<T>
  529. {
  530.  
  531. public:
  532.  
  533.  
  534.     TQueueIterator( const TQueue<T>& a ) :
  535.         TQueueAsVectorIterator<T>(a)
  536.         {
  537.         }
  538.  
  539. };
  540.  
  541. #if defined( BI_CLASSLIB_NO_po )
  542. #pragma option -po.
  543. #endif
  544.  
  545. #pragma option -Vo.
  546.  
  547. #endif  // CLASSLIB_QUEUES_H
  548.  
  549.