home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qstack.h.z / qstack.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  3.6 KB  |  108 lines

  1. /****************************************************************************
  2. ** $Id: qstack.h,v 2.3 1998/07/03 00:09:46 hanord Exp $
  3. **
  4. ** Definition of QStack template/macro class
  5. **
  6. ** Created : 920917
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QSTACK_H
  25. #define QSTACK_H
  26.  
  27. #ifndef QT_H
  28. #include "qglist.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QStackdeclare QStackMdeclare
  43. #define QStack QStackM
  44. #endif
  45. #define QStackM(type) name2(QStackM_,type)
  46.  
  47. #define QStackMdeclare(type)                              \
  48. class QStackM(type) : private QGList                          \
  49. {                                          \
  50. public:                                          \
  51.     QStackM(type)()            {}                      \
  52.     QStackM(type)( const QStackM(type) &s ) : QGList(s) {}              \
  53.    ~QStackM(type)()            { clear(); }                  \
  54.     QStackM(type) &operator=(const QStackM(type) &s)                  \
  55.             { return (QStackM(type)&)QGList::operator=(s); }      \
  56.     bool  autoDelete() const        { return QCollection::autoDelete(); } \
  57.     void  setAutoDelete( bool del )    { QCollection::setAutoDelete(del); }  \
  58.     uint  count()   const        { return QGList::count(); }          \
  59.     bool  isEmpty() const        { return QGList::count() == 0; }      \
  60.     void  push( const type *d )        { QGList::insertAt(0,GCI(d)); }          \
  61.     type *pop()                { return (type *)QGList::takeFirst();}\
  62.     bool  remove()            { return QGList::removeFirst(); }     \
  63.     void  clear()            { QGList::clear(); }              \
  64.     type *top()        const        { return (type *)QGList::cfirst(); }  \
  65.       operator type *() const    { return (type *)QGList::cfirst(); }  \
  66.     type *current() const        { return (type *)QGList::cfirst(); }  \
  67. private:                                      \
  68.     void  deleteItem( GCI d ) { if ( del_item ) delete (type *)d; }          \
  69. }
  70.  
  71. #endif // USE_MACROCLASS
  72.  
  73.  
  74. #if defined(USE_TEMPLATECLASS)
  75.  
  76. #if defined(DEFAULT_TEMPLATECLASS)
  77. #undef    QStack
  78. #define QStack QStackT
  79. #endif
  80.  
  81. template<class type> class QStackT : private QGList
  82. {
  83. public:
  84.     QStackT()                {}
  85.     QStackT( const QStackT<type> &s ) : QGList(s) {}
  86.    ~QStackT()                { clear(); }
  87.     QStackT<type> &operator=(const QStackT<type> &s)
  88.             { return (QStackT<type>&)QGList::operator=(s); }
  89.     bool  autoDelete() const        { return QCollection::autoDelete(); }
  90.     void  setAutoDelete( bool del )    { QCollection::setAutoDelete(del); }
  91.     uint  count()   const        { return QGList::count(); }
  92.     bool  isEmpty() const        { return QGList::count() == 0; }
  93.     void  push( const type *d )        { QGList::insertAt(0,GCI(d)); }
  94.     type *pop()                { return (type *)QGList::takeFirst(); }
  95.     bool  remove()            { return QGList::removeFirst(); }
  96.     void  clear()            { QGList::clear(); }
  97.     type *top()        const        { return (type *)QGList::cfirst(); }
  98.       operator type *() const    { return (type *)QGList::cfirst(); }
  99.     type *current() const        { return (type *)QGList::cfirst(); }
  100. private:
  101.     void  deleteItem( GCI d ) { if ( del_item ) delete (type *)d; }
  102. };
  103.  
  104. #endif // USE_TEMPLATECLASS
  105.  
  106.  
  107. #endif // QSTACK_H
  108.