home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / VPSTACK.CPP < prev    next >
C/C++ Source or Header  |  1996-07-08  |  4KB  |  121 lines

  1. /****************************************************************************
  2.     $Id: vpstack.cpp 501.0 1995/03/07 12:26:28 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Implementation of class TLVPStack.
  10.  
  11.     $Log: vpstack.cpp $
  12.     Revision 501.0  1995/03/07 12:26:28  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.7  1995/01/31 16:30:34  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.6  1995/01/06  15:58:57  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.5  1994/11/16  15:46:15  ron
  21.     Added module info; rearranged #include directives
  22.  
  23.     Revision 1.4  1994/09/28  14:48:00  ron
  24.     Removed Macintosh-style #include references
  25.  
  26.     Revision 1.3  1994/09/27  20:23:35  ron
  27.     Changed path separator from / to \
  28.  
  29.     Revision 1.2  1994/09/26  15:52:01  ron
  30.     Changed include file references
  31.  
  32.     Revision 1.1  1994/08/16  18:13:24  ron
  33.     Initial revision
  34.  
  35. ****************************************************************************/
  36.  
  37. #include <tlx\501\_build.h>
  38.  
  39. TLX_MODULE_INFO("$Revision: 501.0 $");
  40.  
  41. #include <string.h>        // For memcpy(), memmove()
  42. #include <tlx\501\except.h>        // Exception handling
  43. #include <tlx\501\vparrays.h>    // Class declaration
  44.  
  45. /*-------------------------------------------------------------------------*/
  46.     TLVPStack::TLVPStack(size_t aSize, size_t aDelta)
  47.  
  48. /*  Conctructor, creates a stack of specific initial capacity and
  49.     expansion factor. Also doubles as default constructor, creating
  50.     and empty and nonexpandable stack.
  51. ---------------------------------------------------------------------------*/
  52. : mSeq(aSize, aDelta)
  53. {
  54.     TLX_ASSERT(Size() == aSize);
  55. }
  56.  
  57. /*-------------------------------------------------------------------------*/
  58.     TLVPStack::TLVPStack(void *aPtr)
  59.  
  60. /*  Creates a single element stack that is not expandable.
  61. ---------------------------------------------------------------------------*/
  62. : mSeq(aPtr)
  63. {
  64.     TLX_ASSERT(Size() == 1);
  65. }
  66.  
  67. /*-------------------------------------------------------------------------*/
  68.     TLVPStack::TLVPStack(void **aVector, size_t aSize)
  69.  
  70. /*  Creates a stack that contains a copy of a C-style vector. The stack is
  71.     not expandable initially.
  72. ---------------------------------------------------------------------------*/
  73. : mSeq(aVector, aSize)
  74. {
  75.     TLX_ASSERT(Size() == aSize);
  76. }
  77.  
  78. /*-------------------------------------------------------------------------*/
  79.     TLVPStack::TLVPStack(const TLVPStack &aStack)
  80.  
  81. /*  Copy constructor. Creates a copy of another stack.
  82. ---------------------------------------------------------------------------*/
  83. : mSeq(aStack.mSeq)
  84. {
  85.     TLX_ASSERT(Size() == aStack.Size());
  86. }
  87.  
  88. /*-------------------------------------------------------------------------*/
  89.     TLVPStack &TLVPStack::operator =(const TLVPStack &aStack)
  90.  
  91. /*  Overloading of assignment operator for class TLVPStack. The overloading
  92.     is not really necessary (the compiler generated version would work as
  93.     well), but is useful for extra tests and breakpoints.
  94. ---------------------------------------------------------------------------*/
  95. {
  96.     if (TLX_CHECK(this != &aStack))
  97.     mSeq = aStack.mSeq;
  98.  
  99.     return *this;
  100. }
  101.  
  102. /*-------------------------------------------------------------------------*/
  103.     TLVPStack &TLVPStack::operator =(void *aPtr)
  104.  
  105. /*  Overloading of assignment operator that allows a single pointer to be
  106.     assigned to the stack. The stack consists of a single element
  107.     afterwards.
  108.  
  109.     NOTE: If the current stack has currently a physical size of zero and is
  110.     not allowed to expand, this function fails.
  111. ---------------------------------------------------------------------------*/
  112. {
  113.     RemoveAll();
  114.     Push(aPtr);
  115.  
  116.     TLX_ASSERT(Size() == 1);
  117.     TLX_ASSERT(PeekTop() == aPtr);
  118.  
  119.     return *this;
  120. }
  121.