Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TArrayL64.cxx
Go to the documentation of this file.
1// @(#)root/cont:$Id$
2// Author: Fons Rademakers 20/11/06
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TArrayL64
13\ingroup Containers
14Array of long64s (64 bits per element).
15*/
16
17#include "TArrayL64.h"
18#include "TBuffer.h"
19
20
22
23////////////////////////////////////////////////////////////////////////////////
24/// Default TArrayL64 ctor.
25
27{
28 fArray = nullptr;
29}
30
31////////////////////////////////////////////////////////////////////////////////
32/// Create TArrayL64 object and set array size to n long64s.
33
35{
36 fArray = nullptr;
37 if (n > 0) Set(n);
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Create TArrayL object and initialize it with values of array.
42
44{
45 fArray = nullptr;
46 Set(n, array);
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Copy constructor.
51
53{
54 fArray = nullptr;
55 Set(array.fN, array.fArray);
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// TArrayL64 assignment operator.
60
62{
63 if (this != &rhs)
64 Set(rhs.fN, rhs.fArray);
65 return *this;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Delete TArrayL64 object.
70
72{
73 delete [] fArray;
74 fArray = 0;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Adopt array arr into TArrayL64, i.e. don't copy arr but use it directly
79/// in TArrayL64. User may not delete arr, TArrayL64 dtor will do it.
80
82{
83 if (fArray)
84 delete [] fArray;
85
86 fN = n;
87 fArray = arr;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Add long64 c at position i. Check for out of bounds.
92
94{
95 if (!BoundsOk("TArrayL64::AddAt", i)) return;
96 fArray[i] = c;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Set size of this array to n long64s.
101/// A new array is created, the old contents copied to the new array,
102/// then the old array is deleted.
103/// This function should not be called if the array was declared via Adopt.
104
106{
107 if (n < 0) return;
108 if (n != fN) {
109 Long64_t *temp = fArray;
110 if (n != 0) {
111 fArray = new Long64_t[n];
112 if (n < fN) {
113 memcpy(fArray, temp, n*sizeof(Long64_t));
114 } else if (temp) {
115 memcpy(fArray, temp, fN*sizeof(Long64_t));
116 memset(&fArray[fN], 0, (n-fN)*sizeof(Long64_t));
117 } else {
118 memset(fArray, 0, n*sizeof(Long64_t));
119 }
120 } else {
121 fArray = nullptr;
122 }
123 if (fN) delete [] temp;
124 fN = n;
125 }
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Set size of this array to n long64s and set the contents.
130/// This function should not be called if the array was declared via Adopt.
131
132void TArrayL64::Set(Int_t n, const Long64_t *array)
133{
134 if (fArray && fN != n) {
135 delete [] fArray;
136 fArray = nullptr;
137 }
138 fN = n;
139 if ((fN == 0) || !array)
140 return;
141 if (!fArray) fArray = new Long64_t[fN];
142 memmove(fArray, array, n*sizeof(Long64_t));
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Stream a TArrayL64 object.
147
148void TArrayL64::Streamer(TBuffer &b)
149{
150 if (b.IsReading()) {
151 Int_t n;
152 b >> n;
153 Set(n);
154 b.ReadFastArray(fArray,n);
155 } else {
156 b << fN;
157 b.WriteFastArray(fArray, fN);
158 }
159}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
int Int_t
Definition RtypesCore.h:45
long long Long64_t
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:364
Array of long64s (64 bits per element).
Definition TArrayL64.h:27
Long64_t * fArray
Definition TArrayL64.h:30
void AddAt(Long64_t c, Int_t i)
Add long64 c at position i. Check for out of bounds.
Definition TArrayL64.cxx:93
virtual ~TArrayL64()
Delete TArrayL64 object.
Definition TArrayL64.cxx:71
TArrayL64 & operator=(const TArrayL64 &rhs)
TArrayL64 assignment operator.
Definition TArrayL64.cxx:61
TArrayL64()
Default TArrayL64 ctor.
Definition TArrayL64.cxx:26
void Set(Int_t n)
Set size of this array to n long64s.
void Adopt(Int_t n, Long64_t *array)
Adopt array arr into TArrayL64, i.e.
Definition TArrayL64.cxx:81
Abstract array base class.
Definition TArray.h:31
Int_t fN
Definition TArray.h:38
Bool_t BoundsOk(const char *where, Int_t at) const
Definition TArray.h:77
Buffer base class used for serializing objects.
Definition TBuffer.h:43
const Int_t n
Definition legend1.C:16