Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
30 ClassImp(TNamed);
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 destructor.
41 
42 TNamed::~TNamed()
43 {
44  // Required since we overload TObject::Hash.
45  ROOT::CallRecursiveRemoveIfNeeded(*this);
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// TNamed assignment operator.
50 
51 TNamed& TNamed::operator=(const TNamed& rhs)
52 {
53  if (this != &rhs) {
54  TObject::operator=(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 
64 void TNamed::Clear(Option_t *)
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 
74 TObject *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 
85 Int_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 
94 void 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 
104 void TNamed::FillBuffer(char *&buffer)
105 {
106  fName.FillBuffer(buffer);
107  fTitle.FillBuffer(buffer);
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// List TNamed name and title.
112 
113 void TNamed::ls(Option_t *opt) const
114 {
115  TROOT::IndentLevel();
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 
128 void TNamed::Print(Option_t *) const
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 
140 void 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 
154 void 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 
164 void 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 
173 Int_t TNamed::Sizeof() const
174 {
175  Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
176  return nbytes;
177 }