00001 // @(#)root/base:$Id: TRefCnt.h 20877 2007-11-19 11:17:07Z rdm $ 00002 // Author: Fons Rademakers 04/08/95 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TRefCnt 00013 #define ROOT_TRefCnt 00014 00015 00016 ////////////////////////////////////////////////////////////////////////// 00017 // // 00018 // TRefCnt // 00019 // // 00020 // Base class for reference counted objects. // 00021 // // 00022 ////////////////////////////////////////////////////////////////////////// 00023 00024 #ifndef ROOT_Rtypes 00025 #include "Rtypes.h" 00026 #endif 00027 00028 00029 class TRefCnt { 00030 00031 protected: 00032 UInt_t fRefs; // (1 less than) number of references 00033 00034 public: 00035 enum EReferenceFlag { kStaticInit }; 00036 00037 TRefCnt(Int_t initRef = 0) : fRefs((UInt_t)initRef-1) { } 00038 TRefCnt(EReferenceFlag); 00039 virtual ~TRefCnt() { } 00040 UInt_t References() const { return fRefs+1; } 00041 void SetRefCount(UInt_t r) { fRefs = r-1; } 00042 void AddReference() { fRefs++; } 00043 UInt_t RemoveReference() { return fRefs--; } 00044 }; 00045 00046 #endif