TNamed.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TNamed.cxx 20877 2007-11-19 11:17:07Z rdm $
00002 // Author: Rene Brun   26/12/94
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TNamed                                                               //
00015 //                                                                      //
00016 // The TNamed class is the base class for all named ROOT classes        //
00017 // A TNamed contains the essential elements (name, title)               //
00018 // to identify a derived object in containers, directories and files.   //
00019 // Most member functions defined in this base class are in general      //
00020 // overridden by the derived classes.                                   //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #include "Riostream.h"
00025 #include "Strlen.h"
00026 #include "TNamed.h"
00027 #include "TROOT.h"
00028 #include "TVirtualPad.h"
00029 #include "TClass.h"
00030 
00031 ClassImp(TNamed)
00032 
00033 //______________________________________________________________________________
00034 TNamed::TNamed(const TNamed &named) : TObject(named),fName(named.fName),fTitle(named.fTitle)
00035 {
00036    // TNamed copy ctor.
00037 }
00038 
00039 //______________________________________________________________________________
00040 TNamed& TNamed::operator=(const TNamed& rhs)
00041 {
00042    // TNamed assignment operator.
00043 
00044    if (this != &rhs) {
00045       TObject::operator=(rhs);
00046       fName  = rhs.fName;
00047       fTitle = rhs.fTitle;
00048    }
00049    return *this;
00050 }
00051 
00052 //______________________________________________________________________________
00053 void TNamed::Clear(Option_t *)
00054 {
00055    // Set name and title to empty strings ("").
00056 
00057    fName  = "";
00058    fTitle = "";
00059 }
00060 
00061 //______________________________________________________________________________
00062 TObject *TNamed::Clone(const char *newname) const
00063 {
00064    // Make a clone of an object using the Streamer facility.
00065    // If newname is specified, this will be the name of the new object.
00066 
00067    TNamed *named = (TNamed*)TObject::Clone(newname);
00068    if (newname && strlen(newname)) named->SetName(newname);
00069    return named;
00070 }
00071 
00072 //______________________________________________________________________________
00073 Int_t TNamed::Compare(const TObject *obj) const
00074 {
00075    // Compare two TNamed objects. Returns 0 when equal, -1 when this is
00076    // smaller and +1 when bigger (like strcmp).
00077 
00078    if (this == obj) return 0;
00079    return fName.CompareTo(obj->GetName());
00080 }
00081 
00082 //______________________________________________________________________________
00083 void TNamed::Copy(TObject &obj) const
00084 {
00085    // Copy this to obj.
00086 
00087    TObject::Copy(obj);
00088    ((TNamed&)obj).fName  = fName;
00089    ((TNamed&)obj).fTitle = fTitle;
00090 }
00091 
00092 //______________________________________________________________________________
00093 void TNamed::FillBuffer(char *&buffer)
00094 {
00095    // Encode TNamed into output buffer.
00096 
00097    fName.FillBuffer(buffer);
00098    fTitle.FillBuffer(buffer);
00099 }
00100 
00101 //______________________________________________________________________________
00102 void TNamed::ls(Option_t *) const
00103 {
00104    // List TNamed name and title.
00105 
00106    TROOT::IndentLevel();
00107    cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
00108         << Int_t(TestBit(kCanDelete)) << " at: "<<this<< endl;
00109 }
00110 
00111 //______________________________________________________________________________
00112 void TNamed::Print(Option_t *) const
00113 {
00114    // Print TNamed name and title.
00115 
00116    cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << endl;
00117 }
00118 
00119 //______________________________________________________________________________
00120 void TNamed::SetName(const char *name)
00121 {
00122    // Change (i.e. set) the name of the TNamed.
00123    // WARNING: if the object is a member of a THashTable or THashList container
00124    // the container must be Rehash()'ed after SetName(). For example the list
00125    // of objects in the current directory is a THashList.
00126 
00127    fName = name;
00128    if (gPad && TestBit(kMustCleanup)) gPad->Modified();
00129 }
00130 
00131 //______________________________________________________________________________
00132 void TNamed::SetNameTitle(const char *name, const char *title)
00133 {
00134    // Change (i.e. set) all the TNamed parameters (name and title).
00135    // WARNING: if the name is changed and the object is a member of a
00136    // THashTable or THashList container the container must be Rehash()'ed
00137    // after SetName(). For example the list of objects in the current
00138    // directory is a THashList.
00139 
00140    fName  = name;
00141    fTitle = title;
00142    if (gPad && TestBit(kMustCleanup)) gPad->Modified();
00143 }
00144 
00145 //______________________________________________________________________________
00146 void TNamed::SetTitle(const char *title)
00147 {
00148    // Change (i.e. set) the title of the TNamed.
00149 
00150    fTitle = title;
00151    if (gPad && TestBit(kMustCleanup)) gPad->Modified();
00152 }
00153 
00154 //______________________________________________________________________________
00155 Int_t TNamed::Sizeof() const
00156 {
00157    // Return size of the TNamed part of the TObject.
00158 
00159    Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
00160    return nbytes;
00161 }

Generated on Tue Jul 5 14:11:21 2011 for ROOT_528-00b_version by  doxygen 1.5.1