CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/TopQuarkAnalysis/TopHitFit/interface/Refcount.h

Go to the documentation of this file.
00001 //
00002 // $Id: Refcount.h,v 1.1 2011/05/26 09:46:53 mseidel Exp $
00003 //
00004 // File: Refcount.h
00005 // Purpose: A base class for a simple reference-counted object.
00006 // Created: Aug 2000, sss, from the version that used to be in d0om.
00007 //
00008 // To make a reference counted type, derive from class d0_util::Refcount.
00009 // When the object is created, its refcount is initially set to 0;
00010 // the first action taken by the creator should be to call incref()
00011 // to bump the refcount to 1.  Thereafter, the refcount may be incremented
00012 // by incref() and decremented by decref().  If the reference count reaches
00013 // 0, the object calls delete on itself.
00014 //
00015 // If the object is deleted explicitly, the reference count must be 0 or 1.
00016 // Otherwise, an assertion violation will be reported.
00017 //
00018 // CMSSW File      : interface/Refcount.h
00019 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
00020 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
00021 //
00022 
00023 
00046 #ifndef D0_UTIL_REFCOUNT_H
00047 #define D0_UTIL_REFCOUNT_H
00048 
00049 #include<stdexcept>
00050 #include<sstream>
00051 #include<cassert>
00052 namespace hitfit {
00053 
00054 
00068 class Refcount
00069 //
00070 // Purpose: Simple reference-counted object.
00071 //
00072 {
00073 public:
00074   // Constructor, destructor.
00075 
00079   Refcount ();
00080 
00085   virtual ~Refcount ();
00086 
00087   // Increment and decrement reference count.
00091   void incref () const;
00092 
00096   void decref () const;
00097 
00098   // True if calling decref() will delete the object.
00103   bool decref_will_delete () const;
00104 
00105   // True if incref() has never been called, or if the object is being
00106   // deleted.
00111   bool unowned () const;
00112 
00113 
00114 protected:
00115   // Reset the refcount to zero.
00116   // This should only be used in the context of a dtor of a derived
00117   // class that wants to throw an exception.
00118   // It may also be used to implement a `release' function.
00124   void nuke_refcount ();
00125 
00126 
00127 private:
00128   // The reference count itself.
00132   mutable unsigned _refcount;
00133 };
00134 
00135 
00136 } // namespace hitfit
00137 
00138 
00139 #include "TopQuarkAnalysis/TopHitFit/interface/Refcount.i"
00140 
00141 
00142 #endif // not D0_UTIL_REFCOUNT_H