////////////////////////////////////////////////////////////////////////
// $Id: CandRefer.h,v 1.3 2002/10/16 07:04:30 rhatcher Exp $
//
// CandRefer.h
//
// Class for controlling access to the CandBase class.
//
// 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 BbrReferencer (written by Gautier Hamel de
// Monchenault and Bob Jacobsen).
//
// Author:  G. Irwin 1/2000
////////////////////////////////////////////////////////////////////////

#ifndef CANDREFER_H
#define CANDREFER_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 CandRefer
{

public:

// Constructors
   CandRefer();
   CandRefer(CandBase *ref);
   CandRefer(const CandRefer &cr);
   virtual ~CandRefer();

// Operators -
// Access
   CandBase *operator->() {return  fRef;}
   CandBase& operator*()  {return *fRef;}
   CandBase* operator()() {return  fRef;}

// Const-access
   const CandBase* operator->() const {return  fRef;}
   const CandBase& operator*()  const {return *fRef;}
   const CandBase* operator()() const {return  fRef;}

// Logical operators
   Bool_t operator==(const CandRefer &cr) const;
   Bool_t operator!=(const CandRefer &cr) const;

// Assignment
   CandRefer &operator=(const CandRefer &cr);

// Accessors -
// Number of counted CandRefers to the referenced object (incl. this)
   Int_t GetNRefers() const;

// Exclusive access 
   CandBase *OwnRef();

// Modifiers -
// Decrement the ref counter of the referenced object
   Int_t DecNRefer();

// Drop the reference to the referenced object
   void DropRefer();

// Increment the ref counter of the referenced object
   Int_t IncNRefer();

// Set a new reference (after dropping a possible existing reference)
   void SetRef(CandBase *ref);

private:
   CandBase *fRef;              // Pointer to referenced CandBase object

ClassDef(CandRefer,1) // Controlled access to ref-counted CandBase class

};

#endif                                                    // CANDREFER_H
