////////////////////////////////////////////////////////////////////////
// $Id: CandRefCounted.h,v 1.3 2003/03/13 23:54:10 gmieg Exp $
//
// CandRefCounted.h
//
// The CandBase class inherits from CandRefCounted for ref-counting.
//
// Each concrete CandBase must define a Dup function.
// Each concrete CandBase must grant friendship to class CandRefer.
//
// Adapted from Babar's BbrRefCounted (written by Gautier Hamel de
// Monchenault and Bob Jacobsen).
//
// Author:  G. Irwin 1/2000
////////////////////////////////////////////////////////////////////////

#ifndef CANDREFCOUNTED_H
#define CANDREFCOUNTED_H

// not inheriting from TObject so we need an explicit Rtypes
#ifndef ROOT_Rtypes
#if !defined(__CINT__) || defined(__MAKECINT__)
#include "Rtypes.h"
#endif
#endif

class CandBase;

class CandRefCounted
{

public:

// Dup - Forces subclasses to define a Dup function (for cloning).
   virtual CandBase *Dup() const = 0;

protected:

// Constructor
   CandRefCounted();

// Destructor
   virtual ~CandRefCounted();

  // Protected modifiers
   Int_t AddLink()  {return ++fNLinks;}     // Includes LocalHandle link
   Int_t DropLink() {return --fNLinks;}     // Includes LocalHandle link

// Protected access
   Int_t GetNLinks() const {return fNLinks;} // Includes LocalHandle ref

private:
  Int_t fNLinks;   //!NOWRITE! - no of CandRefers, including LocalHandle

ClassDef(CandRefCounted,2)                 // Reference counting pointer

};

#endif                                              // CANDREFCOUNTED_H
