TArray.cxx

Go to the documentation of this file.
00001 // @(#)root/cont:$Id: TArray.cxx 35364 2010-09-17 12:36:14Z brun $
00002 // Author: Fons Rademakers   21/10/97
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TArray                                                               //
00015 //                                                                      //
00016 // Abstract array base class. Used by TArrayC, TArrayS, TArrayI,        //
00017 // TArrayL, TArrayF and TArrayD.                                        //
00018 // Data member is public for historical reasons.                        //
00019 //                                                                      //
00020 //////////////////////////////////////////////////////////////////////////
00021 
00022 #include "TArray.h"
00023 #include "TError.h"
00024 #include "TClass.h"
00025 #include "TBuffer.h"
00026 
00027 
00028 ClassImp(TArray)
00029 
00030 //______________________________________________________________________________
00031 Bool_t TArray::OutOfBoundsError(const char *where, Int_t i) const
00032 {
00033    // Generate an out-of-bounds error. Always returns false.
00034 
00035    ::Error(where, "index %d out of bounds (size: %d, this: 0x%lx)", i, fN, (Long_t)this);
00036    return kFALSE;
00037 }
00038 
00039 //______________________________________________________________________________
00040 TArray *TArray::ReadArray(TBuffer &b, const TClass *clReq)
00041 {
00042    // Read TArray object from buffer. Simplified version of
00043    // TBuffer::ReadObject (does not keep track of multiple
00044    // references to same array).
00045 
00046    R__ASSERT(b.IsReading());
00047 
00048    // Make sure ReadArray is initialized
00049    b.InitMap();
00050 
00051    // Before reading object save start position
00052    UInt_t startpos = UInt_t(b.Length());
00053 
00054    UInt_t tag;
00055    TClass *clRef = b.ReadClass(clReq, &tag);
00056 
00057    TArray *a;
00058    if (!clRef) {
00059 
00060       a = 0;
00061 
00062    } else {
00063 
00064       a = (TArray *) clRef->New();
00065       if (!a) {
00066          ::Error("TArray::ReadArray", "could not create object of class %s",
00067                  clRef->GetName());
00068          // Exception
00069          return 0;
00070       }
00071 
00072       a->Streamer(b);
00073 
00074       b.CheckByteCount(startpos, tag, clRef);
00075    }
00076 
00077    return a;
00078 }
00079 
00080 //______________________________________________________________________________
00081 void TArray::WriteArray(TBuffer &b, const TArray *a)
00082 {
00083    // Write TArray object to buffer. Simplified version of
00084    // TBuffer::WriteObject (does not keep track of multiple
00085    // references to the same array).
00086 
00087    R__ASSERT(b.IsWriting());
00088 
00089    // Make sure WriteMap is initialized
00090    b.InitMap();
00091 
00092    if (!a) {
00093 
00094       b << (UInt_t) 0;
00095 
00096    } else {
00097 
00098       // Reserve space for leading byte count
00099       UInt_t cntpos = UInt_t(b.Length());
00100       b.SetBufferOffset(Int_t(cntpos+sizeof(UInt_t)));
00101 
00102       TClass *cl = a->IsA();
00103       b.WriteClass(cl);
00104 
00105       ((TArray *)a)->Streamer(b);
00106 
00107       // Write byte count
00108       b.SetByteCount(cntpos);
00109    }
00110 }
00111 
00112 //______________________________________________________________________________
00113 TBuffer &operator<<(TBuffer &buf, const TArray *obj)
00114 {
00115    // Write TArray or derived object to buffer.
00116 
00117    TArray::WriteArray(buf, obj);
00118    return buf;
00119 }

Generated on Tue Jul 5 14:11:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1