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

  1. /****************************************************************************
  2.     $Id: iter.cpp 501.0 1995/03/07 12:26:16 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 TLIter and TLPrintFormat.
  10.  
  11.     $Log: iter.cpp $
  12.     Revision 501.0  1995/03/07 12:26:16  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.5  1995/01/31 16:30:16  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.4  1995/01/06  15:57:57  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.3  1994/11/16  15:40:26  ron
  21.     Added module info; rearranged #include directives
  22.  
  23.     Revision 1.2  1994/09/27  20:22:35  ron
  24.     Changed path separator from / to \
  25.  
  26.     Revision 1.1  1994/09/26  15:43:44  ron
  27.     Initial revision
  28.  
  29. ****************************************************************************/
  30.  
  31. #include <tlx\501\_build.h>
  32.  
  33. TLX_MODULE_INFO("$Revision: 501.0 $");
  34.  
  35. #include <tlx\501\iter.h>
  36.  
  37. /*-------------------------------------------------------------------------*/
  38.     TLPrintFormat::TLPrintFormat()
  39.  
  40. /*  Default constructor. Initializes formatting strings to empty.
  41. ---------------------------------------------------------------------------*/
  42. {
  43.     mLeader = mPresep = mPostsep = mTrailer = "";
  44. }
  45.  
  46. /*-------------------------------------------------------------------------*/
  47.     TLPrintFormat::TLPrintFormat
  48.     (
  49.         const char *    aLeader,
  50.     const char *    aPresep,
  51.     const char *    aPostsep,
  52.     const char *    aTrailer
  53.     )
  54.  
  55. /*  Constructor. Uses its arguments to initialize the formatting strings.
  56. ---------------------------------------------------------------------------*/
  57. {
  58.     mLeader  = aLeader;
  59.     mPresep  = aPresep;
  60.     mPostsep = aPostsep;
  61.     mTrailer = aTrailer;
  62. }
  63.  
  64. /*-------------------------------------------------------------------------*/
  65.     TLIter::TLIter()
  66.  
  67. /*  Default constructor. Resets state.
  68. ---------------------------------------------------------------------------*/
  69. {
  70.     mState = stReset;
  71. }
  72.  
  73. /*-------------------------------------------------------------------------*/
  74.     TLIter::~TLIter()
  75.  
  76. /*  Destructor. Does nothing, but is declared virtual for derivation.
  77. ---------------------------------------------------------------------------*/
  78. {
  79. }
  80.  
  81. /*-------------------------------------------------------------------------*/
  82.     bool TLIter::Next()
  83.  
  84. /*  Called to advance the position of the iterator to the next element in
  85.     the associated collection (if any). If the function returns true, the
  86.     next element is available through the appropriate Peek() function,
  87.     else the iteration is finished (and must be reset by Reset()).
  88. ---------------------------------------------------------------------------*/
  89. {
  90.     switch (mState)
  91.     {
  92.     case stReset:            // Reset - go to first
  93.         mState = FirstPos() ? stValid : stEnd;
  94.         break;
  95.  
  96.     case stValid:            // Valid - advance to next
  97.         mState = NextPos() ? stValid : stEnd;
  98.         break;
  99.  
  100.     case stEnd:            // At the end
  101.         break;
  102.  
  103.     default:
  104.         TLX_ASSERT_UNREACHABLE;
  105.         break;
  106.     }
  107.     return IsValid();
  108. }
  109.  
  110. /*-------------------------------------------------------------------------*/
  111.     void TLIter::Reset()
  112.  
  113. /*  Default reset operation. Resets the state of the iterator. If derived
  114.     classes need to reset more than that, they should override this
  115.     function (and adapt their constructor accordingly).
  116. ---------------------------------------------------------------------------*/
  117. {
  118.     mState = stReset;
  119. }
  120.  
  121.