//*-- Author : Valeriy Onuchin 11/09/2000 
//
//
////////////////////////////////////////////////////////////////////////////////
//
// rooVArrayObject corresponds to VArray_Object class. 
//
// The class rooVArrayObject is a self-describing data type for variable-size 
// arrays.
//
//______________________________________________________________________________
//
//          About VArray Objects
//
// A VArray object provides access to a VArray (called its associated VArray)
// embedded in the data of some persistent object. You obtain a VArray object 
// for a particular VArray attribute of a particular persistent object from 
// a class object for that persistent object. To obtain the VArray object, you 
// call the class object's get_varray member function, specifying the VArray 
// attribute of interest. Member functions of a VArray object enable you to 
// get information about the VArray Object and its associated VArray, to 
// change the size of the VArray, to get an individual element, and to set an 
// individual element. The member functions for getting information about the
// VArray and changing its size are similar to the member functions of the 
// ooVArrayT<element_type> class.
//
//
//!!!!!!!!!!!!!!!!!!!!!! Objectivity V5.2.1 BUG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// rooVArrayObject::get_class_obj(idx) doesn't  work for embedded class
//
//!!!!!!!!!!!!!!!!!!! FIXED in coming Objectivity V6. !!!!!!!!!!!!!!!!!!!!!!!!!

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

ClassImp(rooVArrayObject)

////////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
 rooVArrayObject::rooVArrayObject()
{
   // default ctor. internal use only

   fImp = 0;
}

//______________________________________________________________________________
 rooVArrayObject::rooVArrayObject(const rooVArrayObject& vo)
{
   // Constructs a VArray that is a copy of the specified VArray object.
   //
   // The copy constructor creates a new VArray object for the same attribute 
   // and persistent array data as the specified VArray object. Both copies 
   // access the same persistent data. Any change to the VArray made with one 
   // VArray object will be seen by the other VArray object.

   fImp = new VArray_Object(*((VArray_Object*)vo.getImp()));
}

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

//______________________________________________________________________________
 rooNumericValue rooVArrayObject::get(Int_t idx)
{
   // Gets the data for the specified element of the associated numeric VArray.
   //
   // Parameters: 
   //    idx - the zero-based index of the desired element.
   //
   // Returns: 
   //       The numeric value at the specified index of the associated VArray.
   //
   //   This member function throws exceptions:
   //       BadVArrayType if the VArray's element type is not a numeric type
   //       VArrayBoundsError if index exceeds the VArray's upper bound

   if(!fImp) return 0;
   Numeric_Value val = ((VArray_Object*)fImp)->get(idx);

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

//______________________________________________________________________________
 rooClassObject rooVArrayObject::get_class_obj(Int_t idx)
{
   // Gets the data for the specified element of the associated embedded-class 
   // or object-reference VArray.
   //
   // Parameters: 
   //    idx - the zero-based index of the desired element.
   //
   // Returns: 
   //    For an embedded-class VArray, a class object for the specified 
   //    element; for an object-reference VArray, a class object for the 
   //    persistent object referenced by the specified element.
   //
   // To obtain an element of an object reference VArray without opening 
   // a handle for the referenced object, call get_ooref instead of this 
   // member function.
   //
   // This member function throws exceptions:
   //
   //    BadVArrayType if the VArray's element type is not an embedded-class 
   //    type or an object-reference type
   //
   //    VArrayBoundsError if index exceeds the VArray's upper bound
   //
   // !!! this method doesn't work for embedded class in Objectivity V5.2.1
   
   if(!fImp) return 0;
   Class_Object co = ((VArray_Object*)fImp)->get_class_obj(idx);
   if(!co) return 0;

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

//______________________________________________________________________________
 rooObj rooVArrayObject::get_ooref(Int_t idx)
{
   // Gets the data for the specified element of the associated 
   // object-reference VArray.
   //
   // Parameters: 
   //    idx - the zero-based index of the desired element.
   //
   // Returns: 
   //    The object reference at the specified index of the associated VArray.
   //
   // To open a handle for the element and obtain a class object for it, call
   // get_class_obj instead of this member function.
   //
   // This member function throws exceptions:
   //       BadVArrayType if the VArray's element type is not an 
   //       object-reference type
   //
   //       VArrayBoundsError if index exceeds the VArray's upper bound
   //
   // See also: set_ooref()

   if(!fImp) return 0;
   ooHandle(ooObj) obj = ((VArray_Object*)fImp)->get_ooref(idx);
   if(!obj) return 0;
      
   if(!fOoref) fOoref = new rooObj(&obj);
   else fOoref->setImp((void*)&obj);
   return *fOoref; 
}

//______________________________________________________________________________
 rooStringValue rooVArrayObject::get_string(Int_t idx)
{
   // Gets the data for the specified element of the associated string VArray.
   //
   // Parameters: 
   //    idx - the zero-based index of the desired element.
   //
   // This member function throws exceptions:
   //    BadVArrayType if the VArray's element type is not a string type
   //
   //    VArrayBoundsError if index exceeds the VArray's upper bound

   if(!fImp) return 0;
   String_Value str = ((VArray_Object*)fImp)->get_string(idx);
   
   if(!fStringValue) fStringValue = new rooStringValue(&str);
   else fStringValue->setImp((void*)&str);
   return *fStringValue; 
}

//______________________________________________________________________________
 Bool_t rooVArrayObject::set(Int_t idx, const rooNumericValue& val)
{
   // Sets the specified element of the associated numeric VArray.
   //
   // The application must be able to obtain an update lock for the containing
   // persistent object, and the lock on its container is upgraded, if 
   // necessary.
   //
   // This member function throws exceptions:
   //
   //    BadVArrayType if the VArray's element type is not a numeric type
   //    VArrayBoundsError if index exceeds the VArray's upper bound

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

//______________________________________________________________________________
 Bool_t rooVArrayObject::set_ooref(Int_t idx, const rooObj& obj)
{
   // Sets the specified element of the associated object-reference VArray.
   //
   // Parameters: 
   //    idx - the zero-based index of the desired element.
   //    obj - the new object reference for the specified element.
   //
   // Returns: kTRUE if successful; otherwise kFALSE.
   //
   // The application must be able to obtain an update lock for the containing
   // persistent object, and the lock on its container is upgraded, if 
   // necessary.
   //
   // This member function throws exceptions:
   //    BadVArrayType if the VArray's element type is not an object-reference 
   //    type
   //    VArrayBoundsError if index exceeds the VArray's upper bound 

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

//______________________________________________________________________________
 UInt_t rooVArrayObject::cardinality() const
{
   // (ODMG) Gets the current number of elements in the associated VArray.
   
   return fImp ? ((VArray_Object*)fImp)->cardinality() : 0;
}

//______________________________________________________________________________
//rooObjItr rooVArrayObject::create_iterator()
//{
   //
//}

//______________________________________________________________________________
 Bool_t rooVArrayObject::extend(const rooNumericValue& val)
{
   // Adds the specified element at the end of the associated numeric or
   // object-reference VArray, increasing the size of the array.
   //
   // Returns: 
   //    kTRUE if successful; otherwise kFALSE.
   //
   // The application must be able to obtain an update lock for the 
   // containing persistent object, and the lock on its container is 
   // upgraded, if necessary. Extending a VArray implicitly resizes it, 
   // which is a potentially expensive operation. You should therefore use 
   // extend as a convenient way to add only a single element to a VArray. 
   // If you need to add multiple elements in a single transaction, you 
   // should instead use resize to allocate all the elements in one
   // operation.
   //
   //See also: resize()
   
   return fImp ? ((VArray_Object*)fImp)->extend(*((Numeric_Value*)val.getImp())) : 0;
}

//______________________________________________________________________________
 Bool_t rooVArrayObject::extend(const rooObj& obj)
{
   // Adds the specified element at the end of the associated numeric or
   // object-reference VArray, increasing the size of the array.
   //
   // Returns: 
   //    kTRUE if successful; otherwise kFALSE.
   //
   // The application must be able to obtain an update lock for the 
   // containing persistent object, and the lock on its container is 
   // upgraded, if necessary. Extending a VArray implicitly resizes it, 
   // which is a potentially expensive operation. You should therefore use 
   // extend as a convenient way to add only a single element to a VArray. 
   // If you need to add multiple elements in a single transaction, you 
   // should instead use resize to allocate all the elements in one
   // operation.
   //
   //See also: resize()

   return fImp ? ((VArray_Object*)fImp)->extend(*((ooHandle(ooObj)*)obj.getImp())) : 0;
}

//______________________________________________________________________________
 void rooVArrayObject::insert_element(const rooNumericValue& val)
{
   // (ODMG) Adds the specified element at the end of the associated numeric or
   // object-reference VArray, increasing the size of the array.
   //
   // The application must be able to obtain an update lock for the containing
   // persistent object, and the lock on its container is upgraded, if 
   // necessary. Extending a VArray implicitly resizes it, which is a 
   // potentially expensive operation. You should therefore use extend as a 
   // convenient way to add only a single element to a VArray. If you need to
   // add multiple elements in a single transaction, you should instead use 
   // resize to allocate all the elements in one  operation.

   if(fImp) ((VArray_Object*)fImp)->insert_element(*((Numeric_Value*)val.getImp()));
}

//______________________________________________________________________________
 void rooVArrayObject::insert_element(const rooObj& obj)
{
   // ODMG) Adds the specified element at the end of the associated numeric or
   // object-reference VArray, increasing the size of the array.
   //
   // The application must be able to obtain an update lock for the containing
   // persistent object, and the lock on its container is upgraded, if 
   // necessary. Extending a VArray implicitly resizes it, which is a 
   // potentially expensive operation. You should therefore use extend as a 
   // convenient way to add only a single element to a VArray. If you need to
   // add multiple elements in a single transaction, you should instead use 
   // resize to allocate all the elements in one  operation.
         
   if(fImp) ((VArray_Object*)fImp)->insert_element(*((ooHandle(ooObj)*)obj.getImp()));
}

//______________________________________________________________________________
 void rooVArrayObject::replace_element_at(const rooNumericValue& val, UInt_t idx)
{
   // (ODMG) Replaces the specified element of the associated numeric or
   // object-reference VArray with the specified value. 

   if(fImp) ((VArray_Object*)fImp)->replace_element_at(*((Numeric_Value*)val.getImp()),idx);
}

//______________________________________________________________________________
 void rooVArrayObject::replace_element_at(const rooObj& obj, UInt_t idx)
{
   // (ODMG) Replaces the specified element of the associated numeric or
   // object-reference VArray with the specified value. 

   const ooRef(ooObj) oid = *((ooHandle(ooObj)*)obj.getImp());
   if(fImp) ((VArray_Object*)fImp)->replace_element_at(oid,idx);
}

//______________________________________________________________________________
//void rooVArrayObject::replace_element_at(const rooNumericValue&, const rooObjItr &)
//{
   //
//}

//______________________________________________________________________________
//void rooVArrayObject::replace_element_at(const rooObj& obj, const rooObjItr & itr)
//{
   //
//}

//______________________________________________________________________________
 Bool_t rooVArrayObject::resize(UInt_t newSize)
{
   // Extends or truncates the associated VArray to the specified number of 
   // elements.
   //
   // Parameters: 
   //    newSize - total number of elements that the associated VArray is to 
   //    have. Specify 0 to remove all the elements, freeing the storage 
   //    allocated for the element vector.
   //
   // Returns: 
   //    kTRUE if successful; otherwise kFALSE.
   //
   // The application must be able to obtain an update lock for the containing
   // persistent object, and the lock on its container is upgraded, if 
   // necessary. If the new size is larger than the current size, resize 
   // allocates storage for the additional elements, creating new, empty 
   // elements. If the new size is smaller than the current size, resize frees 
   // the elements from index newSize + 1 to the end and then truncates the 
   // VArray to the new size.
   
   return fImp ? ((VArray_Object*)fImp)->resize(newSize) : 0;
}

//______________________________________________________________________________
 Bool_t rooVArrayObject::update()
{
   // Explicitly opens the containing persistent object for update.
   //
   // Returns:
   //    kTRUE if successful; otherwise kFALSE.
   //
   // When you explicitly open the persistent object for update, its container 
   // is locked for update; when the transaction commits, the entire VArray is
   // be written to disk. You should use update primarily if you intend to 
   // change a large number of elements in a single transaction.
   
   return fImp ? ((VArray_Object*)fImp)->update() : 0;
}

//______________________________________________________________________________
const rooType & rooVArrayObject::type_of()
{
   // Gets the element type of the associated VArray.
   //
   // Returns:
   //       A type descriptor for the VArray's element type.

   if(!fImp) return 0;
   d_Type& tp = ((VArray_Object*)fImp)->type_of();
   if(!tp) return 0;

   if(!fType) fType = new rooType((void*)&tp);
   else fType->setImp((void*)&tp);
   return *fType;
}

//______________________________________________________________________________
rooClassObject & rooVArrayObject::contained_in()
{
   // Gets this VArray object's containing class object.
   //
   // Returns: 
   //    The class object for the persistent object whose data 
   //    this VArray object accesses.

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

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

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

   if(!fImp) return 0;

   *((VArray_Object*)fImp) = *((VArray_Object*)va.getImp());
   return *this;
}


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.