Logo ROOT   6.08/07
Reference Guide
TNamed.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 26/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TNamed
13 \ingroup Base
14 
15 The TNamed class is the base class for all named ROOT classes.
16 
17 A TNamed contains the essential elements (name, title)
18 to identify a derived object in containers, directories and files.
19 Most member functions defined in this base class are in general
20 overridden by the derived classes.
21 */
22 
23 #include "Riostream.h"
24 #include "Strlen.h"
25 #include "TNamed.h"
26 #include "TROOT.h"
27 #include "TVirtualPad.h"
28 #include "TClass.h"
29 
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// TNamed copy ctor.
34 
35 TNamed::TNamed(const TNamed &named) : TObject(named),fName(named.fName),fTitle(named.fTitle)
36 {
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// TNamed assignment operator.
41 
43 {
44  if (this != &rhs) {
45  TObject::operator=(rhs);
46  fName = rhs.fName;
47  fTitle = rhs.fTitle;
48  }
49  return *this;
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Set name and title to empty strings ("").
54 
56 {
57  fName = "";
58  fTitle = "";
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Make a clone of an object using the Streamer facility.
63 /// If newname is specified, this will be the name of the new object.
64 
65 TObject *TNamed::Clone(const char *newname) const
66 {
67  TNamed *named = (TNamed*)TObject::Clone(newname);
68  if (newname && strlen(newname)) named->SetName(newname);
69  return named;
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Compare two TNamed objects. Returns 0 when equal, -1 when this is
74 /// smaller and +1 when bigger (like strcmp).
75 
76 Int_t TNamed::Compare(const TObject *obj) const
77 {
78  if (this == obj) return 0;
79  return fName.CompareTo(obj->GetName());
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Copy this to obj.
84 
85 void TNamed::Copy(TObject &obj) const
86 {
87  TObject::Copy(obj);
88  ((TNamed&)obj).fName = fName;
89  ((TNamed&)obj).fTitle = fTitle;
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Encode TNamed into output buffer.
94 
95 void TNamed::FillBuffer(char *&buffer)
96 {
97  fName.FillBuffer(buffer);
98  fTitle.FillBuffer(buffer);
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// List TNamed name and title.
103 
104 void TNamed::ls(Option_t *opt) const
105 {
107  if (opt && strstr(opt,"noaddr")) {
108  std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
109  << Int_t(TestBit(kCanDelete)) << std::endl;
110  } else {
111  std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
112  << Int_t(TestBit(kCanDelete)) << " at: "<<this<< std::endl;
113  }
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Print TNamed name and title.
118 
119 void TNamed::Print(Option_t *) const
120 {
121  std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Set the name of the TNamed.
126 ///
127 /// WARNING: if the object is a member of a THashTable or THashList container
128 /// the container must be Rehash()'ed after SetName(). For example the list
129 /// of objects in the current directory is a THashList.
130 
131 void TNamed::SetName(const char *name)
132 {
133  fName = name;
134  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Set all the TNamed parameters (name and title).
139 //
140 /// WARNING: if the name is changed and the object is a member of a
141 /// THashTable or THashList container the container must be Rehash()'ed
142 /// after SetName(). For example the list of objects in the current
143 /// directory is a THashList.
144 
145 void TNamed::SetNameTitle(const char *name, const char *title)
146 {
147  fName = name;
148  fTitle = title;
149  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Set the title of the TNamed.
154 
155 void TNamed::SetTitle(const char *title)
156 {
157  fTitle = title;
158  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Return size of the TNamed part of the TObject.
163 
165 {
166  Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
167  return nbytes;
168 }
TString fTitle
Definition: TNamed.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual Int_t Compare(const TObject *obj) const
Compare two TNamed objects.
Definition: TNamed.cxx:76
const char Option_t
Definition: RtypesCore.h:62
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
virtual Int_t Sizeof() const
Return size of the TNamed part of the TObject.
Definition: TNamed.cxx:164
int Int_t
Definition: RtypesCore.h:41
virtual void FillBuffer(char *&buffer)
Encode TNamed into output buffer.
Definition: TNamed.cxx:95
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:145
if object in a list can be deleted
Definition: TObject.h:56
virtual void Clear(Option_t *option="")
Set name and title to empty strings ("").
Definition: TNamed.cxx:55
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:123
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:103
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TNamed.cxx:119
virtual void ls(Option_t *option="") const
List TNamed name and title.
Definition: TNamed.cxx:104
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:42
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2618
TString fName
Definition: TNamed.h:36
if object destructor must call RecursiveRemove()
Definition: TObject.h:57
#define ClassImp(name)
Definition: Rtypes.h:279
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
Definition: TString.cxx:1298
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:386
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:65
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:204
virtual void Copy(TObject &named) const
Copy this to obj.
Definition: TNamed.cxx:85
#define gPad
Definition: TVirtualPad.h:289
virtual void FillBuffer(char *&buffer) const
Copy string into I/O buffer.
Definition: TString.cxx:1207
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
char name[80]
Definition: TGX11.cxx:109
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52