home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / queue.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  8.6 KB  |  262 lines

  1. #ifndef __QUEUE_H
  2. #define __QUEUE_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __STD_QUEUE__
  6. #define __STD_QUEUE__
  7.  
  8. /***************************************************************************
  9.  *
  10.  * queue - declarations for the Standard Library queue classes
  11.  *
  12.  ***************************************************************************
  13.  *
  14.  * Copyright (c) 1994
  15.  * Hewlett-Packard Company
  16.  *
  17.  * Permission to use, copy, modify, distribute and sell this software
  18.  * and its documentation for any purpose is hereby granted without fee,
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both that copyright notice and this permission notice appear
  21.  * in supporting documentation.  Hewlett-Packard Company makes no
  22.  * representations about the suitability of this software for any
  23.  * purpose.  It is provided "as is" without express or implied warranty.
  24.  *
  25.  *
  26.  ***************************************************************************
  27.  *
  28.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  29.  *
  30.  * This computer software is owned by Rogue Wave Software, Inc. and is
  31.  * protected by U.S. copyright laws and other laws and by international
  32.  * treaties.  This computer software is furnished by Rogue Wave Software,
  33.  * Inc. pursuant to a written license agreement and may be used, copied,
  34.  * transmitted, and stored only in accordance with the terms of such
  35.  * license and with the inclusion of the above copyright notice.  This
  36.  * computer software or any other copies thereof may not be provided or
  37.  * otherwise made available to any other person.
  38.  *
  39.  * U.S. Government Restricted Rights.  This computer software is provided
  40.  * with Restricted Rights.  Use, duplication, or disclosure by the
  41.  * Government is subject to restrictions as set forth in subparagraph (c)
  42.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  43.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  44.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  45.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  46.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  47.  *
  48.  **************************************************************************/
  49.  
  50. #include <stdcomp.h>
  51.  
  52. #include <algorithm>
  53. #include <functional>
  54. #include <deque>
  55. #include <vector>
  56.  
  57. #ifndef _RWSTD_NO_NAMESPACE
  58. namespace std {
  59. #endif
  60.  
  61.   template <class T, class Container _RWSTD_COMPLEX_DEFAULT(deque<T>) > 
  62.   class queue;
  63.  
  64. #ifdef _RWSTD_NO_UNDEFINED_FRIEND
  65.   template <class T, class Container>
  66.   inline bool operator== (const queue<T,Container>& x, 
  67.                           const queue<T,Container>& y);
  68.  
  69.   template <class T, class Container>
  70.   inline bool operator< (const queue<T,Container>& x, 
  71.                          const queue<T,Container>& y);
  72. #endif
  73.  
  74.   template <class T, class Container>
  75.   class queue
  76.   {
  77. #ifdef __TURBOC__
  78.     friend bool (std::operator==) (const queue<T,Container>& x,
  79.                             const queue<T,Container>& y);
  80.     friend bool (std::operator<)  (const queue<T,Container>& x,
  81.                             const queue<T,Container>& y);
  82. #else
  83.     friend bool operator== (const queue<T,Container>& x,
  84.                             const queue<T,Container>& y);
  85.     friend bool operator<  (const queue<T,Container>& x,
  86.                             const queue<T,Container>& y);
  87. #endif
  88.   public:
  89.  
  90.     typedef _TYPENAME Container::value_type         value_type;
  91.     typedef _TYPENAME Container::size_type          size_type;
  92.     typedef _TYPENAME Container::reference          reference;
  93.     typedef _TYPENAME Container::const_reference    const_reference;
  94.     typedef Container                               container_type;
  95.  
  96.   protected:
  97.  
  98.     Container c;
  99.  
  100.   public:
  101.     _EXPLICIT queue(const Container& co _RWSTD_DEFAULT_ARG(Container())) 
  102.     : c(co)
  103.     { ; }
  104.  
  105. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  106.     queue(void) : c(Container())
  107.     { ; }
  108. #endif
  109.  
  110.     bool                  empty () const              { return c.empty(); }
  111.     size_type             size  () const              { return c.size();  }
  112.     reference             front ()                    { return c.front(); }
  113.     const_reference       front () const              { return c.front(); }
  114.     reference             back  ()                    { return c.back();  }
  115.     const_reference       back  () const              { return c.back();  }
  116.     void                  push  (const value_type& x) { c.push_back(x);   }
  117.     void                  pop   ()                    { c.pop_front();    }
  118.  
  119.   };
  120.  
  121.   template <class T, class Container>
  122.   inline bool operator== (const queue<T,Container>& x, 
  123.                           const queue<T,Container>& y)
  124.   {
  125.     return x.c == y.c;
  126.   }
  127.  
  128.   template <class T, class Container>
  129.   inline bool operator< (const queue<T,Container>& x, 
  130.                          const queue<T,Container>& y)
  131.   {
  132.     return x.c < y.c;
  133.   }
  134.  
  135.   template <class T, class Container>
  136.   inline bool operator!= (const queue<T,Container>& x, 
  137.                           const queue<T,Container>& y)
  138.   {
  139.     return !(x == y);
  140.   }
  141.  
  142.   template <class T, class Container>
  143.   inline bool operator> (const queue<T,Container>& x, 
  144.                          const queue<T,Container>& y)
  145.   {
  146.     return y < x;
  147.   }
  148.  
  149.   template <class T, class Container>
  150.   inline bool operator>= (const queue<T,Container>& x, 
  151.                           const queue<T,Container>& y)
  152.   {
  153.     return !(x < y);
  154.   }
  155.  
  156.   template <class T, class Container>
  157.   inline bool operator<= (const queue<T,Container>& x, 
  158.                           const queue<T,Container>& y)
  159.   {
  160.     return !(y <  x);
  161.   }
  162.  
  163. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  164.   template<class T, class Container = vector<T>,
  165.   class Compare = less<_TYPENAME Container::value_type> >
  166. #else
  167.   template <class T, class Container, class Compare> 
  168. #endif
  169.   class priority_queue
  170.   {
  171.   public:
  172.  
  173.     typedef _TYPENAME Container::value_type         value_type;
  174.     typedef _TYPENAME Container::size_type          size_type;
  175.     typedef _TYPENAME Container::const_reference    const_reference;
  176.     typedef Container                               container_type;
  177.  
  178.   protected:
  179.  
  180.     Container c;
  181.     Compare   comp;
  182.  
  183.   public:
  184.  
  185.     _EXPLICIT priority_queue (const Compare& x _RWSTD_DEFAULT_ARG(Compare()),
  186.                               const Container& co _RWSTD_DEFAULT_ARG(Container())) 
  187.       : c(co), comp(x) 
  188.     { ; }
  189.  
  190. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  191.     priority_queue (void)
  192.       : c(Container()), comp(Compare()) 
  193.     { ; }
  194.  
  195.     _EXPLICIT priority_queue (const Compare& x _RWSTD_DEFAULT_ARG(Compare()))
  196.       : c(Container()), comp(x) 
  197.     { ; }
  198. #endif
  199.  
  200. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  201.     template <class InputIterator>
  202.     priority_queue (InputIterator first, InputIterator last, 
  203.                     const Compare& x = Compare(),
  204.                     const Container& y = Container())
  205.       : c(y), comp(x) 
  206.     {
  207.       c.insert(c.end(),first,last);
  208.       make_heap(c.begin(), c.end(), comp);
  209.     }
  210. #else
  211.     priority_queue (_TYPENAME Container::const_iterator first,
  212.                     _TYPENAME Container::const_iterator last,
  213.                     const Compare& x _RWSTD_DEFAULT_ARG(Compare()))
  214.  
  215.       : c(first, last, Container::allocator_type()), comp(x)
  216.     {
  217.       make_heap(c.begin(), c.end(), comp);
  218.     }
  219. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  220.     priority_queue (_TYPENAME Container::const_iterator first,
  221.                     _TYPENAME Container::const_iterator last,
  222.                     const Compare& x _RWSTD_DEFAULT_ARG(Compare()))
  223.       : c(first, last, Container::allocator_type()), comp(x)
  224.     {
  225.       make_heap(c.begin(), c.end(), comp);
  226.     }
  227.  
  228.     priority_queue (_TYPENAME Container::const_iterator first,
  229.                     _TYPENAME Container::const_iterator last)
  230.       : c(first, last, Container::allocator_type()), comp(Compare())
  231.     {
  232.       make_heap(c.begin(), c.end(), comp);
  233.     }
  234. #endif
  235. #endif
  236.     
  237.     bool                  empty () const { return c.empty(); }
  238.     size_type             size  () const { return c.size();  }
  239.     const_reference       top   () const { return c.front(); }
  240.  
  241.     void push (const value_type& x)
  242.     { 
  243.       c.push_back(x); push_heap(c.begin(), c.end(), comp);
  244.     }
  245.     void pop ()
  246.     {
  247.       pop_heap(c.begin(), c.end(), comp); c.pop_back(); 
  248.     }
  249.   };
  250.  
  251. #ifndef _RWSTD_NO_NAMESPACE
  252. }
  253. #endif
  254.  
  255. #endif /* __STD_QUEUE__ */
  256. #ifndef __USING_STD_NAMES__
  257.   using namespace std;
  258. #endif
  259.  
  260. #pragma option pop
  261. #endif /* __QUEUE_H */
  262.