/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/DecayChain/DecayChain-00-00-03-slc6tag/DecayChain/Element/ReferenceCount.h

Go to the documentation of this file.
00001 #ifndef DCHAIN_REFERENCECOUNT_H
00002 #define DCHAIN_REFERENCECOUNT_H
00003 // -*- C++ -*-
00004 //
00005 // Package:     DChain
00006 // Module:      ReferenceCount
00007 // 
00008 // Description: Base class for classes that need reference counting
00009 //
00010 // Usage:
00011 //   ReferenceCount()  - default constructor
00012 //   ~ReferenceCount() - destructor
00013 //   addLink()  - record that another object points to this object
00014 //   dropLink() - record that an object no longer points to this object
00015 //
00016 // Author:      Simon Patton
00017 // Created:     Fri May 17 08:01:51 EDT 1996
00018 // $Id: ReferenceCount.h,v 1.1.1.1 2009/03/03 06:06:56 maqm Exp $
00019 //
00020 // Revision history
00021 //
00022 // $Log: ReferenceCount.h,v $
00023 // Revision 1.1.1.1  2009/03/03 06:06:56  maqm
00024 // first import of DecayChain
00025 //
00026 // Revision 1.1  2006/01/11 20:28:09  cdj
00027 // massive class renaming, addition of [] for selection and unit tests
00028 //
00029 // Revision 1.4  2004/05/12 20:12:52  ryd
00030 // Added missing #include
00031 //
00032 // Revision 1.3  2004/05/11 02:39:17  ryd
00033 // Change reference count to UInt32 and throw exception if count exceeds maximum
00034 //
00035 // Revision 1.2  2003/05/15 19:56:01  cdj
00036 // revamped memory handling so always use a ReferenceHolder to deal with the reference counting
00037 //
00038 // Revision 1.1.1.1  2000/12/18 22:16:49  cdj
00039 // imported DChain
00040 //
00041 // Revision 1.2  1998/08/21 00:46:09  sjp
00042 // removed unnecessary include
00043 //
00044 // Revision 1.1  1998/08/19 20:56:46  sjp
00045 // New heder for reference counting class
00046 //
00047 // Revision 1.1  1998/08/17 23:59:22  sjp
00048 // New file to make libraries standalone
00049 //
00050 
00051 // system include files
00052 #include <stdint.h>
00053 
00054 // user include files
00055 //#include "DecayChain/util/DAException.h"
00056 
00057 // forward declarations
00058 namespace dchain {
00059 
00060    /*
00061    class TooManyReferencesException : public DAException
00062    {
00063       public:
00064          TooManyReferencesException():DAException("Too many references to object in a DChain list.\n check sizes of list that you multiply."){}
00065    };
00066    */
00067 
00068 
00069 class ReferenceCount
00070 {
00071    public:
00072       // Constructors and destructor
00073       ReferenceCount();
00074       virtual ~ReferenceCount() {}
00075 
00076       // const member functions
00077       void addLink() const ;
00078       void dropLink() const ;
00079 
00080    private:
00081       // Constructors and destructor
00082       ReferenceCount( const ReferenceCount& ) ; // stop default
00083 
00084       // assignment operator(s)
00085       const ReferenceCount& operator=( const ReferenceCount& ) ; // stop default
00086 
00087       // data members
00088       mutable uint32_t m_linkCount ;
00089 
00090 };
00091 
00092 // inline function definitions
00093 
00094 //
00095 // constructors and destructor
00096 //
00097 
00098 inline ReferenceCount::ReferenceCount() :
00099    m_linkCount( 0 )
00100 {
00101 }
00102 
00103 //
00104 // member functions
00105 //
00106 
00107 inline void ReferenceCount::addLink() const
00108 {
00109    //if (m_linkCount==0xFFFFFFFF) {
00110    //   throw TooManyReferencesException();
00111    //}
00112    ++m_linkCount ;
00113 }
00114 
00115 inline void ReferenceCount::dropLink() const
00116 {
00117    --m_linkCount ;
00118    if ( 0 == m_linkCount ) {
00119 // It is necessary to throw away the 'const' so that the object
00120 //   can be deleted
00121       delete const_cast<ReferenceCount*>(this) ;
00122    }
00123 }
00124 }
00125 #endif // DCHAIN_REFERENCECOUNT_H

Generated on Tue Nov 29 22:58:22 2016 for BOSS_7.0.2 by  doxygen 1.4.7