home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 4.4 KB | 144 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCouPtr.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWCOUPTR_H
- #include "FWCouPtr.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CCountedPtr
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::FW_CCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtr::FW_CCountedPtr() :
- fRep(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::~FW_CCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtr::~FW_CCountedPtr()
- {
- FW_START_DESTRUCTOR
- DownCount();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::FW_CCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtr::FW_CCountedPtr(const FW_CCountedPtr& other) :
- fRep(other.fRep)
- {
- UpCount();
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::FW_CCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtr::FW_CCountedPtr(FW_CCountedPtrRep* rep) :
- fRep(rep)
- {
- UpCount();
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtr& FW_CCountedPtr::operator=(const FW_CCountedPtr& other)
- {
- SetRep(other.fRep);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtr& FW_CCountedPtr::operator=(FW_CCountedPtrRep* rep)
- {
- SetRep(rep);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::SetRep
- //----------------------------------------------------------------------------------------
-
- void FW_CCountedPtr::SetRep(FW_CCountedPtrRep* rep)
- {
- if (fRep != rep)
- {
- DownCount();
- fRep = rep;
- UpCount();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::UpCount
- //----------------------------------------------------------------------------------------
-
- void FW_CCountedPtr::UpCount()
- {
- if (fRep)
- fRep->IncrementReferenceCount();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::DownCount
- //----------------------------------------------------------------------------------------
-
- void FW_CCountedPtr::DownCount()
- {
- if (fRep && !fRep->DecrementReferenceCount())
- delete fRep;
- // It is not necessary to set fRep to 0. To see why, see how DownCount is used above.
- // In all cases, fRep is either immediately reset, or the instance is being destroyed.
- // Note too that DownCount is private, so the usages above all all possible usages.
- }
-
- //========================================================================================
- // CLASS FW_CCountedPtrRep
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtrRep::FW_CCountedPtrRep
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtrRep::FW_CCountedPtrRep() :
- fRefCount(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtrRep::~FW_CCountedPtrRep
- //----------------------------------------------------------------------------------------
-
- FW_CCountedPtrRep::~FW_CCountedPtrRep()
- {
- }
-
-