Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TClassRef.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 
0028 class TClassRef {
0029 
0030 private:
0031    std::string   fClassName; //Name of referenced class
0032    TClass *const*fClassPtr;  //! Ptr to the permanent TClass ptr/reference
0033 
0034    friend class TClass;
0035 
0036    void Assign(const TClassRef &);
0037    void Assign(TClass *);
0038    TClass   *InternalGetClass() const;
0039 public:
0040    TClassRef() : fClassName(), fClassPtr(nullptr) {}
0041    TClassRef(TClass *cl);
0042    TClassRef(const char *classname);
0043    TClassRef(const TClassRef&);
0044    inline TClassRef &operator=(const TClassRef &rhs) {
0045       // Inline implementation of operator= to speed the no-op case.
0046       if (this != &rhs && (!fClassPtr || fClassPtr != rhs.fClassPtr)) {
0047          this->Assign(rhs);
0048       }
0049       return *this;
0050    }
0051    inline TClassRef &operator=(TClass *rhs) {
0052       // Inline implementation of operator= to speed the no-op case.
0053       if ( !this->fClassPtr|| *(this->fClassPtr) != rhs) {
0054          this->Assign(rhs);
0055       }
0056       return *this;
0057    }
0058 
0059    ~TClassRef() { };
0060 
0061    void SetName(const char* new_name) {
0062       if ( fClassPtr && fClassName != new_name ) Reset();
0063       fClassName = new_name;
0064    }
0065    const char *GetClassName() { return fClassName.c_str(); }
0066    TClass *GetClass()  const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
0067    void Reset() { fClassPtr = nullptr; }
0068 
0069    TClass* operator->() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
0070    operator TClass*() const { return (fClassPtr && *fClassPtr )? *fClassPtr : InternalGetClass(); }
0071 
0072 };
0073 
0074 #endif