Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 09:09:17

0001 // @(#)root/meta:$Id$
0002 // Author: Philippe Canal 15/03/2005
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TClassRef
0013 #define ROOT_TClassRef
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TClassRef                                                            //
0018 //                                                                      //
0019 // Reference to a TClass object and intrusive list of other             //
0020 // to thise same TClass object references                               //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TClass.h"
0025 
0026 #include <string>
0027 #include <atomic>
0028 
0029 class TClassRef {
0030 
0031 private:
0032    std::string                 fClassName; //Name of referenced class
0033    std::atomic<TClass *const*> fClassPtr;  //! Ptr to the permanent TClass ptr/reference
0034 
0035    friend class TClass;
0036 
0037    void Assign(const TClassRef &);
0038    void Assign(TClass *);
0039    TClass   *InternalGetClass() const;
0040 public:
0041    TClassRef() : fClassName(), fClassPtr(nullptr) {}
0042    TClassRef(TClass *cl);
0043    TClassRef(const char *classname);
0044    TClassRef(const TClassRef&);
0045    inline TClassRef &operator=(const TClassRef &rhs) {
0046       // Inline implementation of operator= to speed the no-op case.
0047       if (this != &rhs && (!fClassPtr || fClassPtr != rhs.fClassPtr)) {
0048          this->Assign(rhs);
0049       }
0050       return *this;
0051    }
0052    inline TClassRef &operator=(TClass *rhs) {
0053       // Inline implementation of operator= to speed the no-op case.
0054       if ( !this->fClassPtr|| *(this->fClassPtr) != rhs) {
0055          this->Assign(rhs);
0056       }
0057       return *this;
0058    }
0059 
0060    ~TClassRef() { };
0061 
0062    void SetName(const char* new_name) {
0063       if ( fClassPtr && fClassName != new_name ) Reset();
0064       fClassName = new_name;
0065    }
0066    const char *GetClassName() { return fClassName.c_str(); }
0067    TClass *GetClass()  const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
0068    void Reset() { fClassPtr = nullptr; }
0069 
0070    TClass* operator->() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
0071    operator TClass*() const { return (fClassPtr && *fClassPtr )? *fClassPtr : InternalGetClass(); }
0072 
0073 };
0074 
0075 #endif