This is tmb_tree, version p15-br-07 | See all available versions

TClassRef


class description - source file - inheritance tree (.ps)

class TClassRef : public TObject

Inheritance Chart:
TObject
<-
TClassRef

    public:
TClassRef(const TClass* cl = 0) TClassRef(const char* clname) TClassRef(const TClassRef&) virtual ~TClassRef() static TClass* Class() virtual Int_t Compare(const TObject* obj) const const TClass* GetClass() const virtual ULong_t Hash() const virtual TClass* IsA() const virtual Bool_t IsEqual(const TObject* obj) const virtual Bool_t IsSortable() const void SetClass(const char* clname) void SetClass(const TClass* cl) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b)

Data Members

    private:
const TClass* fClass ! referenced TClass

Class Description

  Persistent reference to a TClass.
  (TClass itself is not persistent.)

  Implements Compare(), IsEqual() and Hash() (mostly
  by forwarding to TClass), and can thus be used e.g.
  as a key for TMap.

  Example application:
  A TMap which stores objects of different types, not
  necessarily known during compile time. The objects'
  TClass can be used to access the objects in the map.
  Thus at compile time the container does not need to
  know the type of the objects stored.

  Let's assume one wants to store these classes:

    class TSomeObject:  public TCommonBase {...};
    class TOtherObject: public TCommonBase {...};

  Instead of

    class THasObjects {
    public:
       TSomeObject*  GetSomeObject()  { return fObjects[0]; }
       TOtherObject* GetOtherObject() { return fObjects[1]; }
    private:
       TCommonBase*  fObjects; // array of objects
    };

  (which can't be extended in a modular way or at
  runtime to allow for additional objects) one could
  use:

    class TClassMap {
    public:
       TClassMap(){ fMap.SetOwner(); }
       TObject* GetValue(TClass* cl) {
          TClassRef cr(cl);
          return fMap.GetValue(&cr);
       }
       void Add(TObject* obj) {
          fMap.Add(new TClassRef(obj->IsA()), obj);
       }
    private:
       TMap fMap;
    };

  Here, TClassMap does not know anything about the objects
  it contains. TCommonBase class could access them like
  this:

    class TCommonBase: TObject {
       TCommonBase* LookMeUp(TClassMap* cm) {
         return (TCommonBase*) cm->GetValue(IsA());
       }
    };

  Objects of class TClassMap can be stored as its TMap
  contains keys of class TClassRef instead of class TClass.



Int_t Compare(const TObject * obj) const
 Compare two TClassRefs or a TClassRef with a TClass
 Forwards the implementation to the referenced TClass::Compare()

ULong_t Hash() const
 Creates a hash value.
 Forwarded to TClass->Hash() if a referenced class is set,
 otherwise fallback to TObject::Hash()

void SetClass(const char *clname)
 Sets clname to be the referenced class.
 A warning is issued if the class is unknown, and the class
 returned by GetClass() is set to NULL.

void Streamer(TBuffer & R__b)
 Stream an object of class TClassRef.



Inline Functions


                 void ~TClassRef()
            TClassRef TClassRef(const TClass* cl = 0)
            TClassRef TClassRef(const char* clname)
                 void SetClass(const TClass* cl)
        const TClass* GetClass() const
               Bool_t IsEqual(const TObject* obj) const
               Bool_t IsSortable() const
              TClass* Class()
              TClass* IsA() const
                 void ShowMembers(TMemberInspector& insp, char* parent)
                 void StreamerNVirtual(TBuffer& b)
            TClassRef TClassRef(const TClassRef&)


Author: Axel Naumann 01/08/2002
Last update: root/meta:$Name: p15-br-07 $:$Id: TClassRef.cpp,v 1.1 2003/01/09 18:09:58 axel Exp $
Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *


ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.