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

  1. /****************************************************************************
  2.     $Id: ref.cpp 501.0 1995/03/07 12:26:20 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 TLRefCount.
  10.  
  11.     $Log: ref.cpp $
  12.     Revision 501.0  1995/03/07 12:26:20  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.10  1995/01/31 16:30:22  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.9  1995/01/06  15:58:13  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.8  1995/01/05  15:27:22  ron
  21.     Renamed tracing macro
  22.  
  23.     Revision 1.7  1994/11/16  15:42:20  ron
  24.     Added module info; rearranged #include directives
  25.  
  26.     Revision 1.6  1994/09/28  14:20:42  ron
  27.     Removed Macintosh-style #include references
  28.  
  29.     Revision 1.5  1994/09/27  20:22:50  ron
  30.     Changed path separator from / to \
  31.  
  32.     Revision 1.4  1994/09/26  15:46:04  ron
  33.     Changed include file references
  34.  
  35.     Revision 1.3  1994/09/12  14:56:08  ron
  36.     Changed reference count check in destructor to a warning trace
  37.  
  38.     Revision 1.2  1994/09/06  14:11:53  ron
  39.     Adapted to cange from TLRef to TLRefCount
  40.  
  41.     Revision 1.1  1994/08/16  18:13:10  ron
  42.     Initial revision
  43.  
  44. ****************************************************************************/
  45.  
  46. #include <tlx\501\_build.h>
  47.  
  48. TLX_MODULE_INFO("$Revision: 501.0 $");
  49.  
  50. #include <tlx\501\refcnt.h>        // Class declaration
  51.  
  52. /*-------------------------------------------------------------------------*/
  53.     TLRefCount::TLRefCount()
  54.  
  55. /*  Default constructor. Initializes reference count to 0.
  56. ---------------------------------------------------------------------------*/
  57. : mRefCnt(0)
  58. {
  59. }
  60.  
  61. /*-------------------------------------------------------------------------*/
  62.     TLRefCount::TLRefCount(const TLRefCount &)
  63.  
  64. /*  Copy constructor. Must not copy the reference count, but initialize
  65.     it to 0 instead.
  66. ---------------------------------------------------------------------------*/
  67. : mRefCnt(0)
  68. {
  69. }
  70.  
  71. /*-------------------------------------------------------------------------*/
  72.     TLRefCount::~TLRefCount()
  73.  
  74. /*  Destructor. Does nothing, but is declared virtual for derivation.
  75. ---------------------------------------------------------------------------*/
  76. {
  77.   #ifdef _TLXDBG
  78.     if (mRefCnt > 0)
  79.         TLX_TRACE_WARN(TLX, ("Destructing RefCount with %d references",
  80.               mRefCnt));
  81.   #endif
  82. }
  83.  
  84. /*-------------------------------------------------------------------------*/
  85.     void TLRefCount::Protect()
  86.  
  87. /*  Protects a TLRefCount instance against deletion through smart pointers.
  88.     They are protected if the reference count is positive. Protection
  89.     is cumulative: it takes as many calls to Unprotect() as there were
  90.     to Protect() in order to remove the protection from a TLRefCount
  91.     instance.
  92. ---------------------------------------------------------------------------*/
  93. {
  94.     TLX_ASSERT(mRefCnt >= 0);
  95.     mRefCnt++;
  96. }
  97.  
  98. /*-------------------------------------------------------------------------*/
  99.     void TLRefCount::Unprotect()
  100.  
  101. /*  Removes a layer of protection from a TLRefCount instance. Protection
  102.     is cumulative: it takes as many calls to Unprotect() as there were
  103.     to Protect() in order to remove the protection from a TLRefCount
  104.     instance.
  105. ---------------------------------------------------------------------------*/
  106. {
  107.     TLX_ASSERT(mRefCnt >= 1);
  108.     mRefCnt--;
  109. }
  110.