TArrayL.cxx

Go to the documentation of this file.
00001 // @(#)root/cont:$Id: TArrayL.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Rene Brun   06/03/95
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 // TArrayL                                                              //
00015 //                                                                      //
00016 // Array of longs (32 or 64 bits per element).                          //
00017 //                                                                      //
00018 //////////////////////////////////////////////////////////////////////////
00019 
00020 #include "TArrayL.h"
00021 #include "TBuffer.h"
00022 
00023 
00024 ClassImp(TArrayL)
00025 
00026 //______________________________________________________________________________
00027 TArrayL::TArrayL()
00028 {
00029    // Default TArrayL ctor.
00030 
00031    fArray = 0;
00032 }
00033 
00034 //______________________________________________________________________________
00035 TArrayL::TArrayL(Int_t n)
00036 {
00037    // Create TArrayL object and set array size to n longs.
00038 
00039    fArray = 0;
00040    if (n > 0) Set(n);
00041 }
00042 
00043 //______________________________________________________________________________
00044 TArrayL::TArrayL(Int_t n, const Long_t *array)
00045 {
00046    // Create TArrayL object and initialize it with values of array.
00047 
00048    fArray = 0;
00049    Set(n, array);
00050 }
00051 
00052 //______________________________________________________________________________
00053 TArrayL::TArrayL(const TArrayL &array) : TArray(array)
00054 {
00055    // Copy constructor.
00056 
00057    fArray = 0;
00058    Set(array.fN, array.fArray);
00059 }
00060 
00061 //______________________________________________________________________________
00062 TArrayL &TArrayL::operator=(const TArrayL &rhs)
00063 {
00064    // TArrayL assignment operator.
00065 
00066    if (this != &rhs)
00067       Set(rhs.fN, rhs.fArray);
00068    return *this;
00069 }
00070 
00071 //______________________________________________________________________________
00072 TArrayL::~TArrayL()
00073 {
00074    // Delete TArrayL object.
00075 
00076    delete [] fArray;
00077    fArray = 0;
00078 }
00079 
00080 //______________________________________________________________________________
00081 void TArrayL::Adopt(Int_t n, Long_t *arr)
00082 {
00083    // Adopt array arr into TArrayL, i.e. don't copy arr but use it directly
00084    // in TArrayL. User may not delete arr, TArrayL dtor will do it.
00085 
00086    if (fArray)
00087       delete [] fArray;
00088 
00089    fN     = n;
00090    fArray = arr;
00091 }
00092 
00093 //______________________________________________________________________________
00094 void TArrayL::AddAt(Long_t c, Int_t i)
00095 {
00096    // Add long c at position i. Check for out of bounds.
00097 
00098    if (!BoundsOk("TArrayL::AddAt", i)) return;
00099    fArray[i] = c;
00100 }
00101 
00102 //______________________________________________________________________________
00103 void TArrayL::Set(Int_t n)
00104 {
00105    // Set size of this array to n longs.
00106    // A new array is created, the old contents copied to the new array,
00107    // then the old array is deleted.
00108    // This function should not be called if the array was declared via Adopt.
00109 
00110    if (n < 0) return;
00111    if (n != fN) {
00112       Long_t *temp = fArray;
00113       if (n != 0) {
00114          fArray = new Long_t[n];
00115          if (n < fN) memcpy(fArray,temp, n*sizeof(Long_t));
00116          else {
00117             memcpy(fArray,temp,fN*sizeof(Long_t));
00118             memset(&fArray[fN],0,(n-fN)*sizeof(Long_t));
00119          }
00120       } else {
00121          fArray = 0;
00122       }
00123       if (fN) delete [] temp;
00124       fN = n;
00125    }
00126 }
00127 
00128 //______________________________________________________________________________
00129 void TArrayL::Set(Int_t n, const Long_t *array)
00130 {
00131    // Set size of this array to n longs and set the contents.
00132    // This function should not be called if the array was declared via Adopt.
00133 
00134    if (fArray && fN != n) {
00135       delete [] fArray;
00136       fArray = 0;
00137    }
00138    fN = n;
00139    if (fN == 0) return;
00140    if (array == 0) return;
00141    if (!fArray) fArray = new Long_t[fN];
00142    memcpy(fArray,array, n*sizeof(Long_t));
00143 }
00144 
00145 //_______________________________________________________________________
00146 void TArrayL::Streamer(TBuffer &b)
00147 {
00148    // Stream a TArrayL object.
00149 
00150    if (b.IsReading()) {
00151       Int_t n;
00152       b >> n;
00153       Set(n);
00154       b.ReadFastArray(fArray,n);
00155    } else {
00156       b << fN;
00157       b.WriteFastArray(fArray, fN);
00158    }
00159 }
00160 

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