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

  1. /****************************************************************************
  2.     $Id: cdcheck.cpp 501.0 1995/03/07 12:26:10 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 TLCDChecker.
  10.  
  11.     $Log: cdcheck.cpp $
  12.     Revision 501.0  1995/03/07 12:26:10  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.3  1995/01/31 16:30:06  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.2  1995/01/06  15:57:28  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.1  1994/11/16  15:37:29  ron
  21.     Initial revision
  22.  
  23. ****************************************************************************/
  24.  
  25. #include <tlx\501\_build.h>
  26.  
  27. TLX_MODULE_INFO("$Revision: 501.0 $");
  28.  
  29. #include <tlx\501\dispose.h>
  30.  
  31. /*-------------------------------------------------------------------------*/
  32.     TLCDChecker::TLCDChecker()
  33.  
  34. /*  Constructor. Ensures that the object was not initialized and marks it
  35.     as initialized.
  36. ---------------------------------------------------------------------------*/
  37. {
  38. #ifdef _TLXDBG
  39.     // Note: this is slighly dangerous, since there is always a chance that
  40.     // the storage contains the magic signature by coincidence.
  41.  
  42.     TLX_ASSERT(mState != osConstructed);
  43.     mState = osConstructed;
  44. #endif
  45. }
  46.  
  47. /*-------------------------------------------------------------------------*/
  48.     TLCDChecker::TLCDChecker(const TLCDChecker &)
  49.  
  50. /*  Copy constructor. Does not copy the check field, but checks and
  51.     initializes it.
  52. ---------------------------------------------------------------------------*/
  53. {
  54. #ifdef _TLXDBG
  55.     // Note: this is slighly dangerous, since there is always a chance that
  56.     // the storage contains the magic signature by coincidence.
  57.  
  58.     TLX_ASSERT(mState != osConstructed);
  59.     mState = osConstructed;
  60. #endif
  61. }
  62.  
  63. /*-------------------------------------------------------------------------*/
  64.     TLCDChecker::~TLCDChecker()
  65.  
  66. /*  Destructor. Ensures that the object was initialized and marks it as
  67.     destructed.
  68. ---------------------------------------------------------------------------*/
  69. {
  70. #ifdef _TLXDBG
  71.     TLX_ASSERT(mState == osConstructed);
  72.     mState = osDestructed;
  73. #endif
  74. }
  75.  
  76. /*-------------------------------------------------------------------------*/
  77.     TLCDChecker &TLCDChecker::operator =(const TLCDChecker &)
  78.  
  79. /*  Assignment operator. Does not copy the check field (but checks it).
  80. ---------------------------------------------------------------------------*/
  81. {
  82.     TLX_ASSERT(mState == osConstructed);
  83.     return *this;
  84. }
  85.  
  86. #ifdef _TLXDBG
  87. /*-------------------------------------------------------------------------*/
  88.     void TLCDChecker::AssertValid(const char *aFile, int aLine) const
  89.  
  90. /*  Checks the validity of the object, and generates a diagnostic if
  91.     invalid. Should be called with the filename and line number of the
  92.     location of the check.
  93. ---------------------------------------------------------------------------*/
  94. {
  95.     switch (mState) {
  96.     case osConstructed:        // No problem
  97.         break;
  98.     case osDestructed:        // Destroyed object reused
  99.         TLAssert::Diagnostic(TLAssert::dfError, aFile, aLine,
  100.                      "Object has been destroyed");
  101.         break;
  102.     default:            // Uninitialized object
  103.         TLAssert::Diagnostic(TLAssert::dfError, aFile, aLine,
  104.                      "Object not initialized");
  105.         break;
  106.     }
  107. }
  108. #endif
  109.