Class Hierarchy   Class Index   Method Index  

CHMreference.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Copyright (C) 1997-2004 iNTERFACEWARE Inc.  All Rights Reserved
00004 //
00005 //
00006 // Module: Definition of CHMreference object
00007 //
00008 // Description:
00009 //
00010 // Parent class for all reference counted objects
00011 //
00012 // Author: Henry
00013 // Date:   07/15/03
00014 // Revision: $Revision: 1.3 $
00015 //
00016 // Last Edit Date: $Date: 2005-02-03 19:33:42 $
00017 // Source: $Source: /home/cvs/cvsroot/CHM/CHMreference.h,v $
00018 // Locker: $Locker:  $
00019 //
00020 //---------------------------------------------------------------------------
00021 
00022 #ifndef __CHM_REFERENCE__
00023 #define __CHM_REFERENCE__
00024 
00025 #include <stdlib.h>
00026 
00027 class CHMreference
00028 {
00029 public:
00030    CHMreference();
00031    virtual ~CHMreference();
00032 
00033    void AddRef() const;
00034    void Release() const;
00035 
00036 protected:
00037    size_t m_CountOfRef;
00038 };
00039 
00040 
00041 inline CHMreference::CHMreference()
00042  : m_CountOfRef(0)
00043 {
00044   // do nothing
00045 }
00046 
00047 inline CHMreference::~CHMreference()
00048 {
00049 }
00050 
00051 inline void CHMreference::AddRef() const
00052 {
00053    ((CHMreference*)this)->m_CountOfRef++;
00054 }
00055 
00056 inline void CHMreference::Release() const
00057 {
00058    ((CHMreference*)this)->m_CountOfRef--;
00059    if (0 == m_CountOfRef)
00060    {
00061       delete (CHMreference*)this;
00062    }
00063 }
00064 
00065 #endif // end of defensive include