//*-- Author : Valeriy Onuchin 11/09/2000 
//
//
////////////////////////////////////////////////////////////////////////////////
//
// rooClassObject corresponds to Class_Object class
//
// The class rooClassObject is a self-describing data type for persistent 
// objects. An instance of this class is called a class object; it provides 
// access to persistent data contained within some persistent object, called 
// its associated persistent object.
//
//______________________________________________________________________________
//          About Class Objects
//
// Each class object provides access to values of the properties defined in 
// one particular class, called its described class. A class object uses a 
// class descriptor for its described class to guide its access to the 
// associated data. You can construct a class object for an existing 
// persistent object using either rooObj object. You can create a class object 
// for a new object to be added to the database by calling the static member 
// function rooClassObject::new_persistent_object ( not implemented yet). 
// You can create a class object for a new container to be added to the 
// database by calling the static member function 
// rooClassObject::new_persistent_container_object (not implemented).
// From one class object, you can obtain class objects above and below it 
// in the hierarchy of class objects for the associated persistent object:
//
//    You can call the contained_in() member function to get the parent class 
//    object.
//
//    You can call the get_class_obj() member function to get the child class 
//    object corresponding to a particular immediate parent class or embedded
//    class of the described class.
//    From a class object, you can access the data for properties of the 
//    associated persistent object.
//
////////////////////////////////////////////////////////////////////////////////

#include "rooObjy.h"
#include <ooas.h>
#include <oo.h>

ClassImp(rooClassObject)

////////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
 rooClassObject::rooClassObject()
{
   //  Creates a class object with no associated class descriptor or 
   // persistent object. You can set a newly created class object 
   // using operator=
   
   fImp = new Class_Object();
}

//______________________________________________________________________________
 rooClassObject::rooClassObject(const rooClassObject & cl)
{
   // Copy constructor, which creates a new class object with
   // the same class descriptor and persistent object as the specified class 
   // object. Both copies access the same persistent object. Any change made 
   // with one class object will be seen by the other class object

   fImp = new Class_Object(*((Class_Object*)cl.getImp()));
}

//______________________________________________________________________________
 rooClassObject::rooClassObject(const rooObj & obj, const rooClass &cl)
{
   // Creates a class object for the specified persistent
   // object. Opens a handle for the persistent object, if necessary.   
   // Throws an InvalidShape exception if the specified object is not an
   // instance of the specified class. Throws an InvalidHandle exception 
   // if the specified handle is not valid. 

   fImp = new Class_Object(*((ooHandle(ooObj)*)obj.getImp()),*((d_Class*)cl.getImp()));
}

//______________________________________________________________________________
 rooClassObject::rooClassObject(const rooObj & obj, Int_t idx, 
                               const rooModule & md)
{
   // Creates a class object for the specified persistent
   // object. Opens a handle for the persistent object, if necessary.   
   // Throws an InvalidShape exception if the specified object is not an
   // instance of the specified class. Throws an InvalidHandle exception 
   // if the specified handle is not valid. 

   fImp = new Class_Object(*((ooHandle(ooObj)*)obj.getImp()),idx,*((d_Module*)md.getImp())); }

//______________________________________________________________________________
 rooClassObject::rooClassObject(const rooObj & obj)
{
   // Creates a class object for the referenced persistent object 
   // (rooObj object).  It creates and opens a handle for the persistent object, 
   // if necessary. It sets the class descriptor for the new class object 
   // by looking up  the type number of the specified object in the top-level 
   // module. 

   ooHandle(ooObj)* ho = (ooHandle(ooObj)*)obj.getImp();
   fImp = new Class_Object(*ho);
}

//______________________________________________________________________________
 rooClassObject::~rooClassObject()
{
   // dtor
   
   fImp = 0;
}

//______________________________________________________________________________
 rooNumericValue rooClassObject::get(Int_t pos)
{
   // Gets the data for the specified numeric attribute of the persistent 
   // object.
   //
   // Returns: 
   //    The numeric value at the specified index in the specified attribute
   // of the associated persistent object.
   //
   // Throws an AttributeTypeError exception if the specified attribute is
   // not a numeric attribute.

   if(!fImp) return 0;
   Numeric_Value val = ((Class_Object*)fImp)->get(pos);
        
   if(!fNumericValue) fNumericValue = new rooNumericValue((void*)&val);
   else fNumericValue->setImp((void*)&val);
   return *fNumericValue;   
}

//______________________________________________________________________________
 rooClassObject rooClassObject::get_class_obj(Int_t pos)
{
   // Gets the data for the specified base class, embedded-class attribute, 
   // or object-reference attribute of the persistent object.
   //
   // Returns: 
   //    For a base class or an embedded-class attribute, a class object for 
   //    the embedded object element at the specified index; for an 
   //    object-reference attribute, a class object for the persistent object
   //    referenced by the value at the specified index.
   //
   // To obtain a value from an object-reference attribute without opening a 
   // handle for the referenced object, call get_ooref() instead of this member
   // function.
   // Throws an AttributeTypeError exception if the specified attribute is
   // not a base class, an embedded-class attribute, or an object-reference 
   // attribute.
 
   if(!fImp) return 0;
   Class_Object co = ((Class_Object*)fImp)->get_class_obj(pos);
   if(!co) return 0;

   if(!fClassObject) fClassObject = new rooClassObject((void*)&co);
   else fClassObject->setImp((void*)&co);
   return *fClassObject; 
}

//______________________________________________________________________________
 rooVArrayObject rooClassObject::get_varray(Int_t pos)
{
   // Gets the data for the specified embedded-class or VArray attribute of the
   // persistent object.

   if(!fImp) return 0;
   VArray_Object vo = ((Class_Object*)fImp)->get_varray(pos);
   if(!vo) return 0;

   if(!fVArrayObject) fVArrayObject = new rooVArrayObject((void*)&vo);
   else fVArrayObject->setImp((void*)&vo);
   return *fVArrayObject; 
}

//______________________________________________________________________________
 rooRelationshipObject rooClassObject::get_relationship(Int_t pos)
{
   // Gets the data for the specified relationship of the persistent object.

   if(!fImp) return 0;
   Relationship_Object ro = ((Class_Object*)fImp)->get_relationship(pos);
   if(!ro) return 0;  

   if(!fRelationshipObject) fRelationshipObject = new rooRelationshipObject((void*)&ro);
   else fRelationshipObject->setImp((void*)&ro);
   return *fRelationshipObject;
}

//______________________________________________________________________________
 rooObj  rooClassObject::get_ooref(Int_t pos)
{
   // Gets the object reference in the specified object-reference attribute 
   // (rooObj obect) of the persistent object.
   //
   // Returns:
   //    A class object for the persistent object referenced by the value at 
   //    the specified index of the specified attribute.
   //
   // To open a handle for the reference object and obtain a class object for it, 
   // call get_class_obj instead of this member function.
   // Throws an AttributeTypeError exception if the specified attribute is
   // not an object-reference attribute.

   if(!fImp) return 0;
   ooHandle(ooObj) obj = ((Class_Object*)fImp)->get_ooref(pos);

   if(!fOoref) fOoref = new rooObj((void*)&obj);
   else fOoref->setImp((void*)&obj);
   return *fOoref; 
}

//______________________________________________________________________________
 rooStringValue  rooClassObject::get_string(Int_t pos)
{
   // Gets the data for the specified string attribute of the persistent object.

   String_Value sv = ((Class_Object*)fImp)->get_string(pos);

   if(!fStringValue) fStringValue = new rooStringValue((void*)&sv);
   else fStringValue->setImp((void*)&sv);
   return *fStringValue; 
}

//______________________________________________________________________________
 Bool_t rooClassObject::set(Int_t pos, const rooNumericValue& val)
{
   //Sets the specified numeric attribute of the persistent object. 

   return fImp ? ((Class_Object*)fImp)->set(pos,*((Numeric_Value*)val.getImp())) : 0;
}

//______________________________________________________________________________
 Bool_t rooClassObject::set_ooref(Int_t pos, const rooObj& val)
{
   //Sets the specified object-reference attribute of the persistent object. 

   const ooRef(ooObj) obj = *((ooHandle(ooObj)*)val.getImp());   
   return fImp ? ((Class_Object*)fImp)->set_ooref(pos,obj) : 0;
}

//______________________________________________________________________________
 rooNumericValue  rooClassObject::get(Int_t pos, Int_t idx)
{
   // Gets the data for the specified numeric attribute of the persistent 
   // object.
   //
   // Returns: 
   //    The numeric value at the specified index in the specified attribute
   // of the associated persistent object.
   //
   // Throws an AttributeTypeError exception if the specified attribute is
   // not a numeric attribute.
   // Throws an ArrayBoundsError exception if idx exceeds the upper bound 
   // for the array in the specified attribute.
         
   Numeric_Value val = ((Class_Object*)fImp)->get(pos,idx);
      
   if(!fNumericValue) fNumericValue = new rooNumericValue((void*)&val);
   else fNumericValue->setImp((void*)&val);
   return *fNumericValue;  
}

//______________________________________________________________________________
 rooClassObject  rooClassObject::get_class_obj(Int_t pos, Int_t idx)
{
   // Gets the data for the specified base class, embedded-class attribute, 
   // or object-reference attribute of the persistent object.
   //
   // Returns: 
   //    For a base class or an embedded-class attribute, a class object for 
   //    the embedded object element at the specified index; for an 
   //    object-reference attribute, a class object for the persistent object
   //    referenced by the value at the specified index.
   //
   // To obtain a value from an object-reference attribute without opening a 
   // handle for the referenced object, call get_ooref() instead of this member
   // function.
   // Throws an AttributeTypeError exception if the specified attribute is
   // not a base class, an embedded-class attribute, or an object-reference 
   // attribute.
   // Throws an ArrayBoundsError exception if idx exceeds the upper bound 
   // for the array in the specified attribute.
   
   Class_Object co = ((Class_Object*)fImp)->get_class_obj(pos,idx);
   if(!co) return 0;
      
   if(!fClassObject) fClassObject = new rooClassObject((void*)&co);
   else fClassObject->setImp((void*)&co);
   return *fClassObject;
}

//______________________________________________________________________________
 rooVArrayObject rooClassObject::get_varray(Int_t pos, Int_t idx)
{
   // Gets the data for the specified embedded-class or VArray attribute of the
   // persistent object.

   VArray_Object vo = ((Class_Object*)fImp)->get_varray(pos,idx);
   if(!vo) return 0;

   if(!fVArrayObject) fVArrayObject = new rooVArrayObject((void*)&vo);
   else fVArrayObject->setImp((void*)&vo);
   return *fVArrayObject; 
}

//______________________________________________________________________________
 rooObj rooClassObject::get_ooref(Int_t pos, Int_t idx)
{
   // Gets the object reference in the specified object-reference attribute 
   // (rooObj obect) of the persistent object.
   //
   // Returns:
   //    A class object for the persistent object referenced by the value at 
   //    the specified index of the specified attribute.
   //
   // To open a handle for the reference object and obtain a class object for it, 
   // call get_class_obj instead of this member function.
   // Throws an AttributeTypeError exception if the specified attribute is
   // not an object-reference attribute.
   // Throws an ArrayBoundsError exception if idx exceeds the upper bound 
   // for the array in the specified attribute.
   
   ooHandle(ooObj) obj = ((Class_Object*)fImp)->get_ooref(pos,idx);
   if(!obj) return 0;
      
   if(!fOoref) fOoref = new rooObj((void*)&obj);
   else fOoref->setImp((void*)&obj);
   return *fOoref; 
}

//______________________________________________________________________________
 rooStringValue  rooClassObject::get_string(Int_t pos, Int_t idx)
{
   // Gets the data for the specified string attribute of the persistent object.

   String_Value sv = ((Class_Object*)fImp)->get_string(pos,idx);
      
   if(!fStringValue) fStringValue = new rooStringValue((void*)&sv);
   else fStringValue->setImp((void*)&sv);
   return *fStringValue; 
}

//______________________________________________________________________________
 Bool_t rooClassObject::set(Int_t pos, Int_t idx, const rooNumericValue& val)
{
   //Sets the specified numeric attribute of the persistent object. 

   return fImp ? ((Class_Object*)fImp)->set(pos,idx,*((Numeric_Value*)val.getImp())) : 0;
}

//______________________________________________________________________________
 Bool_t rooClassObject::set_ooref(Int_t pos, Int_t idx, const rooObj& val)
{
   // Sets the specified object-reference attribute of the persistent object. 

   const ooRef(ooObj) obj = *((ooHandle(ooObj)*)val.getImp()); 
   return fImp ? ((Class_Object*)fImp)->set_ooref(pos,idx,obj) : 0;
}

//______________________________________________________________________________
 rooNumericValue  rooClassObject::get(const rooClassPosition & pos, Int_t idx)
{
   // Gets the data for the specified numeric attribute of the persistent 
   // object.
   //
   // Returns: 
   //    The numeric value at the specified index in the specified attribute
   // of the associated persistent object.
   //
   // Throws an AttributeTypeError exception if the specified attribute is
   // not a numeric attribute.
   // Throws an ArrayBoundsError exception if idx exceeds the upper bound 
   // for the array in the specified attribute.
      
   Numeric_Value val = ((Class_Object*)fImp)->get(*((Class_Position*)pos.getImp()),idx);

   if(!fNumericValue) fNumericValue = new rooNumericValue((void*)&val);
   else fNumericValue->setImp((void*)&val);
   return *fNumericValue;   
}

//______________________________________________________________________________
 rooClassObject  rooClassObject::get_class_obj(const rooClassPosition & pos, Int_t idx)
{
   // Gets the data for the specified base class, embedded-class attribute, 
   // or object-reference attribute of the persistent object.
   //
   // Returns: 
   //    For a base class or an embedded-class attribute, a class object for 
   //    the embedded object element at the specified index; for an 
   //    object-reference attribute, a class object for the persistent object
   //    referenced by the value at the specified index.
   //
   // To obtain a value from an object-reference attribute without opening a 
   // handle for the referenced object, call get_ooref() instead of this member
   // function.
   // Throws an AttributeTypeError exception if the specified attribute is
   // not a base class, an embedded-class attribute, or an object-reference 
   // attribute.
   // Throws an ArrayBoundsError exception if idx exceeds the upper bound 
   // for the array in the specified attribute.
      
   Class_Object co = ((Class_Object*)fImp)->get_class_obj(*((Class_Position*)pos.getImp()),idx);
   if(!co) return 0;
      
   if(!fClassObject) fClassObject = new rooClassObject((void*)&co);
   else fClassObject->setImp((void*)&co);
   return *fClassObject; 
}

//______________________________________________________________________________
 rooVArrayObject rooClassObject::get_varray(const rooClassPosition & pos,Int_t idx)
{
   // Gets the data for the specified embedded-class or VArray attribute of the
   // persistent object.

   VArray_Object vo = ((Class_Object*)fImp)->get_varray(*((Class_Position*)pos.getImp()),idx);
   if(!vo) return 0;
   
   if(!fVArrayObject) fVArrayObject = new rooVArrayObject((void*)&vo);
   else fVArrayObject->setImp((void*)&vo);
   return *fVArrayObject; 
}

//______________________________________________________________________________
 rooRelationshipObject rooClassObject::get_relationship(const rooClassPosition & pos)
{
   // Gets the data for the specified relationship of the persistent object.

   Relationship_Object ro = ((Class_Object*)fImp)->get_relationship(*((Class_Position*)pos.getImp()));
   if(!ro) return 0;
      
   if(!fRelationshipObject) fRelationshipObject = new rooRelationshipObject((void*)&ro);
   else fRelationshipObject->setImp((void*)&ro);
   return *fRelationshipObject;
}

//______________________________________________________________________________
 rooObj rooClassObject::get_ooref(const rooClassPosition & pos, Int_t idx)
{
   // Gets the object reference in the specified object-reference attribute 
   // (rooObj obect) of the persistent object.
   //
   // Returns:
   //    A class object for the persistent object referenced by the value at 
   //    the specified index of the specified attribute.
   //
   // It can access attributes defined in or inherited by this class object's 
   // described class.
   // To open a handle for the reference object and obtain a class object for it, 
   // call get_class_obj instead of this member function.
   // Throws an AttributeTypeError exception if the specified attribute is
   // not an object-reference attribute.
   // Throws an ArrayBoundsError exception if idx exceeds the upper bound 
   // for the array in the specified attribute.
   
   ooHandle(ooObj) obj = ((Class_Object*)fImp)->get_ooref(*((Class_Position*)pos.getImp()),idx);
   if(!obj) return 0;
      
   if(!fOoref) fOoref = new rooObj((void*)&obj);
   else fOoref->setImp((void*)&obj);
   return *fOoref; 
}

//______________________________________________________________________________
 rooStringValue rooClassObject::get_string(const rooClassPosition & pos, Int_t idx)
{
   // Gets the data for the specified string attribute of the persistent object.

   String_Value sv = ((Class_Object*)fImp)->get_string(*((Class_Position*)pos.getImp()),idx);

   if(!fStringValue) fStringValue = new rooStringValue((void*)&sv);
   else fStringValue->setImp((void*)&sv);
   return *fStringValue; 
}

//______________________________________________________________________________
 Bool_t rooClassObject::set(const rooClassPosition &pos, const rooNumericValue& val)
{
   //Sets the specified numeric attribute of the persistent object. 

   return fImp ? ((Class_Object*)fImp)->set(*((Class_Position*)pos.getImp()),
                                     *((Numeric_Value*)val.getImp())) : 0;
}

//______________________________________________________________________________
 Bool_t rooClassObject::set(const rooClassPosition & pos,     // attrPosR
                           Int_t idx,                     // arrayIndex
                           const rooNumericValue& val)
{
   //Sets the specified numeric attribute of the persistent object. 

   return fImp ? ((Class_Object*)fImp)->set(*((Class_Position*)pos.getImp()),idx,
                                     *((Numeric_Value*)val.getImp())) : 0;
}

//______________________________________________________________________________
 Bool_t rooClassObject::set_ooref(const rooClassPosition & pos, const rooObj& val)
{
   //Sets the specified object-reference attribute of the persistent object. 

   const ooRef(ooObj) obj = *((ooHandle(ooObj)*)val.getImp());
   return fImp ? ((Class_Object*)fImp)->set_ooref(*((Class_Position*)pos.getImp()),obj) : 0;
}

//______________________________________________________________________________
 Bool_t rooClassObject::set_ooref(const rooClassPosition & pos,       // attrPosR
                                 Int_t idx,                       // arrayIndex
                                 const rooObj& val)
{
   //Sets the specified object-reference attribute of the persistent object. 

   const ooRef(ooObj) obj = *((ooHandle(ooObj)*)val.getImp());
   return fImp ? ((Class_Object*)fImp)->set_ooref(*((Class_Position*)pos.getImp()),idx,obj) : 0;
}

//______________________________________________________________________________
//rooClassObject::operator rooObj()
//{
   //
//
//   Class_Object cl = *(Class_Object*)fImp;
//   ooHandle(ooObj) obj = (ooHandle(ooObj))cl;
//   return  rooObj((void*)&obj);
//}

//______________________________________________________________________________
rooClassObject & rooClassObject::operator=(const rooClassObject &in)
{
   // Assignment operator; sets this class object to a copy of the specified 
   // class object.
   //
   // Parameters:
   //    in - the class object to be copied.
   //
   // Returns: 
   // This class object after it has been updated to be a copy of "in".
   //
   // Both copies access the same persistent object. Any change made with 
   // one class object will be seen by the other class object. 

   if(fImp) *((Class_Object*)fImp) = *((Class_Object*)in.getImp());
   else fImp = new Class_Object(*((Class_Object*)in.getImp())); 
   return *this;
}

//______________________________________________________________________________
rooClassObject & rooClassObject::operator=(const rooObj &in)
{
  // Assignment operator; sets this class object to a copy of the specified 
  // handle object ( rooObj class ).
   
   Class_Object co(*((ooHandle(ooObj)*)in.getImp()));
   if(fImp) *((Class_Object*)fImp) = co;
   else fImp = new Class_Object(co);
   return *this;
}

//______________________________________________________________________________
rooClassObject & rooClassObject::contained_in()
{
   // Gets this class object's containing class object.
   //
   // Returns: 
   //    The class object for the persistent object whose data this class 
   //    object accesses.
   //
   // If this class object corresponds to an embedded or base class within 
   // the data of a persistent object, the returned class object is the class 
   // object for that persistent object.
   //    If this is the class object for a persistent object, this member 
   // function returns this class object itself.
   //   If this class object is null, this member function returns this null
   // class object.

   if(!fImp) return 0;
   Class_Object& cl= ((Class_Object*)fImp)->contained_in();
   if(!cl) return 0;

   if(!fContainedIn) fContainedIn = new rooClassObject((void*)&cl);
   else fContainedIn->setImp((void*)&cl);
   return *fContainedIn;
}

//______________________________________________________________________________
rooObj & rooClassObject::object_handle()
{
   // Gets a handle to this class object's associated persistent object.
   //
   // Returns: 
   //    A handle to this class object's associated persistent object, 
   //    or a null object handle if this is the null class object.
   //
   // This member function is valid only for the root class object in the 
   // hierarchy of class objects for the associated persistent object.

   ooHandle(ooObj) & obj = ((Class_Object*)fImp)->object_handle();
   if(!obj) return 0;
      
   if(!fObject) fObject = new rooObj((void*)&obj);
   else fObject->setImp((void*)&obj);
   return *fObject;
}

//______________________________________________________________________________
const rooClass & rooClassObject::type_of()
{
   // Gets this class object's described class.
   // 
   // Returns: 
   //    A class descriptor for this class object's described class.

   if(!fImp) return 0;
   d_Class& cl = ((Class_Object*)fImp)->type_of();
   if(!cl) return 0;

   if(!fClass) fClass = new rooClass((void*)&cl);
   else fClass->setImp((void*)&cl);
   return *fClass;
}

//______________________________________________________________________________
const rooClassPosition & rooClassObject::position_in_class(const TString& memName)
{
   // Gets the class position of the specified attribute within this class 
   // object's described class.
   //
   // Parameters: 
   //    memName - the name of the attribute whose position is desired. 
   //          This string can be a qualified name (such as foo::base::x) 
   //          to disambiguate attributes of the same name inherited from 
   //          different base classes. You should specify a qualified name only 
   //          if necessary, because it takes more time to look up a qualified 
   //          name than an unqualified one.
   //
   // Returns: 
   //          A class position that gives the layout position of the specified 
   //          attribute within the described class.

   if(!fImp) return 0;
   Class_Position& cp = ((Class_Object*)fImp)->position_in_class(memName.Data());
   if(!cp) return 0;

   if(!fClassPosition) fClassPosition = new rooClassPosition((void*)&cp);
   else fClassPosition->setImp((void*)&cp);
   return *fClassPosition;
}

//______________________________________________________________________________
const rooAttribute & rooClassObject::resolve_attribute(const TString& memName)
{
   // Looks up an attribute defined by this class object's described class.
   // 
   // Parameters: 
   //    memName - he name of the attribute to be looked up.
   //
   // Returns: 
   //    The attribute descriptor for the described class's attribute with the 
   //    specified name, or the null descriptor if memNameis not the name of an 
   //    immediate base class of the described class or the name of an attribute
   //    or a relationship defined by the described class.
   
   if(!fImp) return 0;
   d_Attribute& atr = ((Class_Object*)fImp)->resolve_attribute(memName.Data());
   if(!atr) return 0; 

   if(!fAttribute) fAttribute = new rooAttribute((void*)&atr);
   else fAttribute->setImp((void*)&atr);
   return *fAttribute;
}

//______________________________________________________________________________
const rooAttribute & rooClassObject::attribute_at_position(Int_t pos)
{
   // Returns type of attribute at position pos   

   if(!fImp) return 0;
   Class_Object* co = (Class_Object*)fImp;
   
   const d_Class& cl = co->type_of();
   const d_Attribute& atr = cl.attribute_at_position(pos);
   
   if(!fAttribute) fAttribute = new rooAttribute((void*)&atr);
   else fAttribute->setImp((void*)&atr);
   return *fAttribute;   
}


ROOT page - Class index - 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.