/* -*- C++ -*- */ /************************************************************************* * Copyright(c) 1995~2005 Masaharu Goto (root-cint@cern.ch) * * For the licensing terms see the file COPYING * ************************************************************************/ /************************************************************************** * DArray.C * * Array class template * **************************************************************************/ #include "DArray.h" using namespace std; #ifdef __GNUC__ int G__defaultsize=100; #else int DArray::G__defaultsize = 100; #endif /*********************************************** * Destructor ***********************************************/ DArray::~DArray() { if(malloced) delete[] dat; } /*********************************************** * Copy constructor ***********************************************/ DArray::DArray(DArray const & X) { if(X.malloced) { dat = new double[X.n]; memcpy(dat,X.dat,X.n*sizeof(double)); n = X.n; malloced=1; } else { dat=X.dat; n = X.n; malloced=0; } } /*********************************************** * Implicit conversion constructor ***********************************************/ DArray::DArray(double x) { n=G__defaultsize; dat = new double[n]; malloced=1; for(int i=0;i=" << ndat << ". default " << G__defaultsize << "used.\n"; } else { G__defaultsize=ndat; } n = ndat; dat = new double[n]; malloced=1; double res ; res = (stop-start)/(n-1); for(int i=0;i=" << ndat << ". default " << G__defaultsize << "used.\n"; } else { G__defaultsize=ndat; } if(0==isnew) { dat = p; n = G__defaultsize; malloced=0; } else { n=G__defaultsize; dat = new double[ndat]; malloced=1; memcpy(dat,p,ndat*sizeof(double)); } } /*********************************************** * constructor for rvalue subDArray ***********************************************/ DArray::DArray(DArray& X,int offset,int ndat) { int i; if(offset<0||offset>=X.n) { cerr << "Illegal offset. Set to 0\n"; offset = 0; } if(ndat<=0) { n=X.n-offset; } else { n = ndat; } dat = new double[n]; malloced=1; if(offset+n>X.n) { memcpy(dat,X.dat+offset,(X.n-offset)*sizeof(double)); for(i=X.n-offset;i=" << size ; } else if(size!=n) { if(malloced) delete[] dat; n=size; malloced=1; dat=new double[n]; } return(n); } /********************************************************** * operator = as member function **********************************************************/ DArray& DArray::operator =(DArray& a) { if(malloced && a.malloced) { if(a.n=n) c[i] += a[n-1]*b[j]; else c[i] += a[k]*b[j]; } } return(c); } /*********************************************** * integ ***********************************************/ DArray integ(DArray& x,DArray& y) { a.setdefaultsize(a.n); DArray c; int i; double integ=0; for(i=0;i