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