ROOT  6.06/09
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 The TNamed class is the base class for all named ROOT classes.
14 
15 A TNamed contains the essential elements (name, title)
16 to identify a derived object in containers, directories and files.
17 Most member functions defined in this base class are in general
18 overridden by the derived classes.
19 */
20 
21 #include "Riostream.h"
22 #include "Strlen.h"
23 #include "TNamed.h"
24 #include "TROOT.h"
25 #include "TVirtualPad.h"
26 #include "TClass.h"
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// TNamed copy ctor.
32 
33 TNamed::TNamed(const TNamed &named) : TObject(named),fName(named.fName),fTitle(named.fTitle)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// TNamed assignment operator.
39 
41 {
42  if (this != &rhs) {
43  TObject::operator=(rhs);
44  fName = rhs.fName;
45  fTitle = rhs.fTitle;
46  }
47  return *this;
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Set name and title to empty strings ("").
52 
54 {
55  fName = "";
56  fTitle = "";
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Make a clone of an object using the Streamer facility.
61 /// If newname is specified, this will be the name of the new object.
62 
63 TObject *TNamed::Clone(const char *newname) const
64 {
65  TNamed *named = (TNamed*)TObject::Clone(newname);
66  if (newname && strlen(newname)) named->SetName(newname);
67  return named;
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Compare two TNamed objects. Returns 0 when equal, -1 when this is
72 /// smaller and +1 when bigger (like strcmp).
73 
75 {
76  if (this == obj) return 0;
77  return fName.CompareTo(obj->GetName());
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Copy this to obj.
82 
83 void TNamed::Copy(TObject &obj) const
84 {
85  TObject::Copy(obj);
86  ((TNamed&)obj).fName = fName;
87  ((TNamed&)obj).fTitle = fTitle;
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Encode TNamed into output buffer.
92 
93 void TNamed::FillBuffer(char *&buffer)
94 {
95  fName.FillBuffer(buffer);
96  fTitle.FillBuffer(buffer);
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// List TNamed name and title.
101 
102 void TNamed::ls(Option_t *opt) const
103 {
105  if (opt && strstr(opt,"noaddr")) {
106  std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
107  << Int_t(TestBit(kCanDelete)) << std::endl;
108  } else {
109  std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
110  << Int_t(TestBit(kCanDelete)) << " at: "<<this<< std::endl;
111  }
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Print TNamed name and title.
116 
117 void TNamed::Print(Option_t *) const
118 {
119  std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Change (i.e. set) the name of the TNamed.
124 /// WARNING: if the object is a member of a THashTable or THashList container
125 /// the container must be Rehash()'ed after SetName(). For example the list
126 /// of objects in the current directory is a THashList.
127 
128 void TNamed::SetName(const char *name)
129 {
130  fName = name;
131  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Change (i.e. set) all the TNamed parameters (name and title).
136 //
137 /// WARNING: if the name is changed and the object is a member of a
138 /// THashTable or THashList container the container must be Rehash()'ed
139 /// after SetName(). For example the list of objects in the current
140 /// directory is a THashList.
141 
142 void TNamed::SetNameTitle(const char *name, const char *title)
143 {
144  fName = name;
145  fTitle = title;
146  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Change (i.e. set) the title of the TNamed.
151 
152 void TNamed::SetTitle(const char *title)
153 {
154  fTitle = title;
155  if (gPad && TestBit(kMustCleanup)) gPad->Modified();
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Return size of the TNamed part of the TObject.
160 
162 {
163  Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
164  return nbytes;
165 }
TString fTitle
Definition: TNamed.h:37
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void FillBuffer(char *&buffer) const
Copy string into I/O buffer.
Definition: TString.cxx:1206
const char Option_t
Definition: RtypesCore.h:62
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
int Int_t
Definition: RtypesCore.h:41
virtual void FillBuffer(char *&buffer)
Encode TNamed into output buffer.
Definition: TNamed.cxx:93
virtual void SetNameTitle(const char *name, const char *title)
Change (i.e. set) all the TNamed parameters (name and title).
Definition: TNamed.cxx:142
virtual void Clear(Option_t *option="")
Set name and title to empty strings ("").
Definition: TNamed.cxx:53
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:203
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void Copy(TObject &named) const
Copy this to obj.
Definition: TNamed.cxx:83
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:102
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:63
virtual void ls(Option_t *option="") const
List TNamed name and title.
Definition: TNamed.cxx:102
virtual Int_t Compare(const TObject *obj) const
Compare two TNamed objects.
Definition: TNamed.cxx:74
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:122
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:40
TClass * IsA() const
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TNamed.cxx:117
TString fName
Definition: TNamed.h:36
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
#define name(a, b)
Definition: linkTestLib0.cpp:5
ClassImp(TNamed) TNamed
TNamed copy ctor.
Definition: TNamed.cxx:28
virtual Int_t Sizeof() const
Return size of the TNamed part of the TObject.
Definition: TNamed.cxx:161
Mother of all ROOT objects.
Definition: TObject.h:58
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
Definition: TString.cxx:1297
#define gPad
Definition: TVirtualPad.h:288
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2461
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TObject * obj
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:385