Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <iostream>
24#include "Strlen.h"
25#include "TNamed.h"
26#include "TROOT.h"
27#include "TVirtualPad.h"
28#include "TClass.h"
29
30
31////////////////////////////////////////////////////////////////////////////////
32/// TNamed copy ctor.
33
34TNamed::TNamed(const TNamed &named) : TObject(named),fName(named.fName),fTitle(named.fTitle)
35{
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// TNamed destructor.
40
42{
43 // Required since we overload TObject::Hash.
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// TNamed assignment operator.
49
51{
52 if (this != &rhs) {
54 fName = rhs.fName;
55 fTitle = rhs.fTitle;
56 }
57 return *this;
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Set name and title to empty strings ("").
62
64{
65 fName = "";
66 fTitle = "";
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Make a clone of an object using the Streamer facility.
71/// If newname is specified, this will be the name of the new object.
72
73TObject *TNamed::Clone(const char *newname) const
74{
76 if (newname && strlen(newname)) named->SetName(newname);
77 return named;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Compare two TNamed objects. Returns 0 when equal, -1 when this is
82/// smaller and +1 when bigger (like strcmp).
83
84Int_t TNamed::Compare(const TObject *obj) const
85{
86 if (this == obj) return 0;
87 return fName.CompareTo(obj->GetName());
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Copy this to obj.
92
93void TNamed::Copy(TObject &obj) const
94{
95 TObject::Copy(obj);
96 ((TNamed&)obj).fName = fName;
97 ((TNamed&)obj).fTitle = fTitle;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Encode TNamed into output buffer.
102
103void TNamed::FillBuffer(char *&buffer)
104{
105 fName.FillBuffer(buffer);
106 fTitle.FillBuffer(buffer);
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// List TNamed name and title.
111
112void TNamed::ls(Option_t *opt) const
113{
115 if (opt && strstr(opt,"noaddr")) {
116 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
117 << Int_t(TestBit(kCanDelete)) << std::endl;
118 } else {
119 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
120 << Int_t(TestBit(kCanDelete)) << " at: "<<this<< std::endl;
121 }
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Print TNamed name and title.
126
128{
129 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Save object name and title into the output stream "out".
134
135void TNamed::SavePrimitiveNameTitle(std::ostream &out, const char *variable_name)
136{
137 TString name = GetName(), title = GetTitle();
138 out << " " << variable_name << "->SetName(\"" << name.ReplaceSpecialCppChars() << "\");" << std::endl;
139 out << " " << variable_name << "->SetTitle(\"" << title.ReplaceSpecialCppChars() << "\");" << std::endl;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Set the name of the TNamed.
144///
145/// WARNING: if the object is a member of a THashTable or THashList container
146/// the container must be Rehash()'ed after SetName(). For example the list
147/// of objects in the current directory is a THashList.
148
149void TNamed::SetName(const char *name)
150{
151 fName = name;
152 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Set all the TNamed parameters (name and title).
157//
158/// WARNING: if the name is changed and the object is a member of a
159/// THashTable or THashList container the container must be Rehash()'ed
160/// after SetName(). For example the list of objects in the current
161/// directory is a THashList.
162
163void TNamed::SetNameTitle(const char *name, const char *title)
164{
165 fName = name;
166 fTitle = title;
167 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Set the title of the TNamed.
172
173void TNamed::SetTitle(const char *title)
174{
175 fTitle = title;
176 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Return size of the TNamed part of the TObject.
181
183{
185 return nbytes;
186}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
#define gPad
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void FillBuffer(char *&buffer)
Encode TNamed into output buffer.
Definition TNamed.cxx:103
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition TNamed.cxx:73
void SavePrimitiveNameTitle(std::ostream &out, const char *variable_name)
Save object name and title into the output stream "out".
Definition TNamed.cxx:135
void Copy(TObject &named) const override
Copy this to obj.
Definition TNamed.cxx:93
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
virtual ~TNamed()
TNamed destructor.
Definition TNamed.cxx:41
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fTitle
Definition TNamed.h:33
TNamed()
Definition TNamed.h:38
void Print(Option_t *option="") const override
Print TNamed name and title.
Definition TNamed.cxx:127
TString fName
Definition TNamed.h:32
void Clear(Option_t *option="") override
Set name and title to empty strings ("").
Definition TNamed.cxx:63
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Int_t Compare(const TObject *obj) const override
Compare two TNamed objects.
Definition TNamed.cxx:84
TClass * IsA() const override
Definition TNamed.h:60
virtual Int_t Sizeof() const
Return size of the TNamed part of the TObject.
Definition TNamed.cxx:182
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:50
void ls(Option_t *option="") const override
List TNamed name and title.
Definition TNamed.cxx:112
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition TNamed.cxx:163
Mother of all ROOT objects.
Definition TObject.h:41
TObject & operator=(const TObject &rhs) noexcept
TObject assignment operator.
Definition TObject.h:299
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:242
virtual void Copy(TObject &object) const
Copy this to obj.
Definition TObject.cxx:159
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:70
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2898
Basic string class.
Definition TString.h:138
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:464
virtual void FillBuffer(char *&buffer) const
Copy string into I/O buffer.
Definition TString.cxx:1316
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
Definition TString.cxx:1407
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
Definition TROOT.h:400