ROOT logo
// @(#)root/cont:$Id: TArray.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Fons Rademakers   21/10/97

 * 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.             *

//                                                                      //
// TArray                                                               //
//                                                                      //
// Abstract array base class. Used by TArrayC, TArrayS, TArrayI,        //
// TArrayL, TArrayF and TArrayD.                                        //
// Data member is public for historical reasons.                        //
//                                                                      //

#include "TArray.h"
#include "TError.h"
#include "TClass.h"
#include "TBuffer.h"


Bool_t TArray::OutOfBoundsError(const char *where, Int_t i) const
   // Generate an out-of-bounds error. Always returns false.

   ::Error(where, "index %d out of bounds (size: %d, this: 0x%08x)", i, fN, this);
   return kFALSE;

TArray *TArray::ReadArray(TBuffer &b, const TClass *clReq)
   // Read TArray object from buffer. Simplified version of
   // TBuffer::ReadObject (does not keep track of multiple
   // references to same array).


   // Make sure ReadArray is initialized

   // Before reading object save start position
   UInt_t startpos = UInt_t(b.Length());

   UInt_t tag;
   TClass *clRef = b.ReadClass(clReq, &tag);

   TArray *a;
   if (!clRef) {

      a = 0;

   } else {

      a = (TArray *) clRef->New();
      if (!a) {
         ::Error("TArray::ReadArray", "could not create object of class %s",
         // Exception


      b.CheckByteCount(startpos, tag, clRef);

   return a;

void TArray::WriteArray(TBuffer &b, const TArray *a)
   // Write TArray object to buffer. Simplified version of
   // TBuffer::WriteObject (does not keep track of multiple
   // references to the same array).


   // Make sure WriteMap is initialized

   if (!a) {

      b << (UInt_t) 0;

   } else {

      // Reserve space for leading byte count
      UInt_t cntpos = UInt_t(b.Length());

      TClass *cl = a->IsA();

      ((TArray *)a)->Streamer(b);

      // Write byte count

TBuffer &operator<<(TBuffer &buf, const TArray *obj)
   // Write TArray or derived object to buffer.

   TArray::WriteArray(buf, obj);
   return buf;