// @(#)root/base:$Id$
// Author: Rene Brun   26/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TNamed                                                               //
//                                                                      //
// The TNamed class is the base class for all named ROOT classes        //
// A TNamed contains the essential elements (name, title)               //
// to identify a derived object in containers, directories and files.   //
// Most member functions defined in this base class are in general      //
// overridden by the derived classes.                                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "Riostream.h"
#include "Strlen.h"
#include "TNamed.h"
#include "TROOT.h"
#include "TVirtualPad.h"
#include "TClass.h"

ClassImp(TNamed)

//______________________________________________________________________________
TNamed::TNamed(const TNamed &named) : TObject(named),fName(named.fName),fTitle(named.fTitle)
{
   // TNamed copy ctor.
}

//______________________________________________________________________________
TNamed& TNamed::operator=(const TNamed& rhs)
{
   // TNamed assignment operator.

   if (this != &rhs) {
      TObject::operator=(rhs);
      fName  = rhs.fName;
      fTitle = rhs.fTitle;
   }
   return *this;
}

//______________________________________________________________________________
void TNamed::Clear(Option_t *)
{
   // Set name and title to empty strings ("").

   fName  = "";
   fTitle = "";
}

//______________________________________________________________________________
TObject *TNamed::Clone(const char *newname) const
{
   // Make a clone of an object using the Streamer facility.
   // If newname is specified, this will be the name of the new object.

   TNamed *named = (TNamed*)TObject::Clone(newname);
   if (newname && strlen(newname)) named->SetName(newname);
   return named;
}

//______________________________________________________________________________
Int_t TNamed::Compare(const TObject *obj) const
{
   // Compare two TNamed objects. Returns 0 when equal, -1 when this is
   // smaller and +1 when bigger (like strcmp).

   if (this == obj) return 0;
   return fName.CompareTo(obj->GetName());
}

//______________________________________________________________________________
void TNamed::Copy(TObject &obj) const
{
   // Copy this to obj.

   TObject::Copy(obj);
   ((TNamed&)obj).fName  = fName;
   ((TNamed&)obj).fTitle = fTitle;
}

//______________________________________________________________________________
void TNamed::FillBuffer(char *&buffer)
{
   // Encode TNamed into output buffer.

   fName.FillBuffer(buffer);
   fTitle.FillBuffer(buffer);
}

//______________________________________________________________________________
void TNamed::ls(Option_t *opt) const
{
   // List TNamed name and title.

   TROOT::IndentLevel();
   if (opt && strstr(opt,"noaddr")) {
      std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
                << Int_t(TestBit(kCanDelete)) << std::endl;
   } else {
      std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
                 << Int_t(TestBit(kCanDelete)) << " at: "<<this<< std::endl;
   }
}

//______________________________________________________________________________
void TNamed::Print(Option_t *) const
{
   // Print TNamed name and title.

   std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
}

//______________________________________________________________________________
void TNamed::SetName(const char *name)
{
   // Change (i.e. set) the name of the TNamed.
   // WARNING: if the object is a member of a THashTable or THashList container
   // the container must be Rehash()'ed after SetName(). For example the list
   // of objects in the current directory is a THashList.

   fName = name;
   if (gPad && TestBit(kMustCleanup)) gPad->Modified();
}

//______________________________________________________________________________
void TNamed::SetNameTitle(const char *name, const char *title)
{
   // Change (i.e. set) all the TNamed parameters (name and title).
   // WARNING: if the name is changed and the object is a member of a
   // THashTable or THashList container the container must be Rehash()'ed
   // after SetName(). For example the list of objects in the current
   // directory is a THashList.

   fName  = name;
   fTitle = title;
   if (gPad && TestBit(kMustCleanup)) gPad->Modified();
}

//______________________________________________________________________________
void TNamed::SetTitle(const char *title)
{
   // Change (i.e. set) the title of the TNamed.

   fTitle = title;
   if (gPad && TestBit(kMustCleanup)) gPad->Modified();
}

//______________________________________________________________________________
Int_t TNamed::Sizeof() const
{
   // Return size of the TNamed part of the TObject.

   Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
   return nbytes;
}
 TNamed.cxx:1
 TNamed.cxx:2
 TNamed.cxx:3
 TNamed.cxx:4
 TNamed.cxx:5
 TNamed.cxx:6
 TNamed.cxx:7
 TNamed.cxx:8
 TNamed.cxx:9
 TNamed.cxx:10
 TNamed.cxx:11
 TNamed.cxx:12
 TNamed.cxx:13
 TNamed.cxx:14
 TNamed.cxx:15
 TNamed.cxx:16
 TNamed.cxx:17
 TNamed.cxx:18
 TNamed.cxx:19
 TNamed.cxx:20
 TNamed.cxx:21
 TNamed.cxx:22
 TNamed.cxx:23
 TNamed.cxx:24
 TNamed.cxx:25
 TNamed.cxx:26
 TNamed.cxx:27
 TNamed.cxx:28
 TNamed.cxx:29
 TNamed.cxx:30
 TNamed.cxx:31
 TNamed.cxx:32
 TNamed.cxx:33
 TNamed.cxx:34
 TNamed.cxx:35
 TNamed.cxx:36
 TNamed.cxx:37
 TNamed.cxx:38
 TNamed.cxx:39
 TNamed.cxx:40
 TNamed.cxx:41
 TNamed.cxx:42
 TNamed.cxx:43
 TNamed.cxx:44
 TNamed.cxx:45
 TNamed.cxx:46
 TNamed.cxx:47
 TNamed.cxx:48
 TNamed.cxx:49
 TNamed.cxx:50
 TNamed.cxx:51
 TNamed.cxx:52
 TNamed.cxx:53
 TNamed.cxx:54
 TNamed.cxx:55
 TNamed.cxx:56
 TNamed.cxx:57
 TNamed.cxx:58
 TNamed.cxx:59
 TNamed.cxx:60
 TNamed.cxx:61
 TNamed.cxx:62
 TNamed.cxx:63
 TNamed.cxx:64
 TNamed.cxx:65
 TNamed.cxx:66
 TNamed.cxx:67
 TNamed.cxx:68
 TNamed.cxx:69
 TNamed.cxx:70
 TNamed.cxx:71
 TNamed.cxx:72
 TNamed.cxx:73
 TNamed.cxx:74
 TNamed.cxx:75
 TNamed.cxx:76
 TNamed.cxx:77
 TNamed.cxx:78
 TNamed.cxx:79
 TNamed.cxx:80
 TNamed.cxx:81
 TNamed.cxx:82
 TNamed.cxx:83
 TNamed.cxx:84
 TNamed.cxx:85
 TNamed.cxx:86
 TNamed.cxx:87
 TNamed.cxx:88
 TNamed.cxx:89
 TNamed.cxx:90
 TNamed.cxx:91
 TNamed.cxx:92
 TNamed.cxx:93
 TNamed.cxx:94
 TNamed.cxx:95
 TNamed.cxx:96
 TNamed.cxx:97
 TNamed.cxx:98
 TNamed.cxx:99
 TNamed.cxx:100
 TNamed.cxx:101
 TNamed.cxx:102
 TNamed.cxx:103
 TNamed.cxx:104
 TNamed.cxx:105
 TNamed.cxx:106
 TNamed.cxx:107
 TNamed.cxx:108
 TNamed.cxx:109
 TNamed.cxx:110
 TNamed.cxx:111
 TNamed.cxx:112
 TNamed.cxx:113
 TNamed.cxx:114
 TNamed.cxx:115
 TNamed.cxx:116
 TNamed.cxx:117
 TNamed.cxx:118
 TNamed.cxx:119
 TNamed.cxx:120
 TNamed.cxx:121
 TNamed.cxx:122
 TNamed.cxx:123
 TNamed.cxx:124
 TNamed.cxx:125
 TNamed.cxx:126
 TNamed.cxx:127
 TNamed.cxx:128
 TNamed.cxx:129
 TNamed.cxx:130
 TNamed.cxx:131
 TNamed.cxx:132
 TNamed.cxx:133
 TNamed.cxx:134
 TNamed.cxx:135
 TNamed.cxx:136
 TNamed.cxx:137
 TNamed.cxx:138
 TNamed.cxx:139
 TNamed.cxx:140
 TNamed.cxx:141
 TNamed.cxx:142
 TNamed.cxx:143
 TNamed.cxx:144
 TNamed.cxx:145
 TNamed.cxx:146
 TNamed.cxx:147
 TNamed.cxx:148
 TNamed.cxx:149
 TNamed.cxx:150
 TNamed.cxx:151
 TNamed.cxx:152
 TNamed.cxx:153
 TNamed.cxx:154
 TNamed.cxx:155
 TNamed.cxx:156
 TNamed.cxx:157
 TNamed.cxx:158
 TNamed.cxx:159
 TNamed.cxx:160
 TNamed.cxx:161
 TNamed.cxx:162
 TNamed.cxx:163
 TNamed.cxx:164
 TNamed.cxx:165
 TNamed.cxx:166