1 | #ifndef MARS_MArrayD
|
---|
2 | #define MARS_MArrayD
|
---|
3 |
|
---|
4 | #ifndef MARS_MArray
|
---|
5 | #include "MArray.h"
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | class MArrayD : public MArray
|
---|
11 | {
|
---|
12 | private:
|
---|
13 | Double_t *fArray; //[fN] Array of fN chars
|
---|
14 |
|
---|
15 | public:
|
---|
16 |
|
---|
17 | MArrayD()
|
---|
18 | {
|
---|
19 | fN = 0;
|
---|
20 | fArray = NULL;
|
---|
21 | }
|
---|
22 |
|
---|
23 | MArrayD(UInt_t n)
|
---|
24 | {
|
---|
25 | fN = 0;
|
---|
26 | fArray = NULL;
|
---|
27 | Set(n);
|
---|
28 | }
|
---|
29 |
|
---|
30 | MArrayD(UInt_t n, Double_t *array)
|
---|
31 | {
|
---|
32 | // Create TArrayC object and initialize it with values of array.
|
---|
33 | fN = 0;
|
---|
34 | fArray = NULL;
|
---|
35 | Set(n, array);
|
---|
36 | }
|
---|
37 |
|
---|
38 | MArrayD(const MArrayD &array)
|
---|
39 | {
|
---|
40 | // Copy constructor.
|
---|
41 | fArray = NULL;
|
---|
42 | Set(array.fN, array.fArray);
|
---|
43 | }
|
---|
44 |
|
---|
45 | UInt_t GetSize() const
|
---|
46 | {
|
---|
47 | return fN;
|
---|
48 | }
|
---|
49 |
|
---|
50 | MArrayD &operator=(const MArrayD &rhs)
|
---|
51 | {
|
---|
52 | // TArrayC assignment operator.
|
---|
53 | if (this != &rhs)
|
---|
54 | Set(rhs.fN, rhs.fArray);
|
---|
55 | return *this;
|
---|
56 | }
|
---|
57 |
|
---|
58 | virtual ~MArrayD()
|
---|
59 | {
|
---|
60 | // Delete TArrayC object.
|
---|
61 | delete [] fArray;
|
---|
62 | fArray = NULL;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void Adopt(UInt_t n, Double_t *array)
|
---|
66 | {
|
---|
67 | // Adopt array arr into TArrayC, i.e. don't copy arr but use it directly
|
---|
68 | // in TArrayC. User may not delete arr, TArrayC dtor will do it.
|
---|
69 | if (fArray)
|
---|
70 | delete [] fArray;
|
---|
71 |
|
---|
72 | fN = n;
|
---|
73 | fArray = array;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void AddAt(Double_t c, UInt_t i)
|
---|
77 | {
|
---|
78 | // Add char c at position i. Check for out of bounds.
|
---|
79 | fArray[i] = c;
|
---|
80 | }
|
---|
81 |
|
---|
82 | Double_t At(UInt_t i)
|
---|
83 | {
|
---|
84 | return fArray[i];
|
---|
85 | }
|
---|
86 |
|
---|
87 | Double_t *GetArray() const
|
---|
88 | {
|
---|
89 | return fArray;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void Reset()
|
---|
93 | {
|
---|
94 | memset(fArray, 0, fN*sizeof(Double_t));
|
---|
95 | }
|
---|
96 |
|
---|
97 | void Set(UInt_t n)
|
---|
98 | {
|
---|
99 | // Set size of this array to n chars.
|
---|
100 | // A new array is created, the old contents copied to the new array,
|
---|
101 | // then the old array is deleted.
|
---|
102 |
|
---|
103 | if (n==fN)
|
---|
104 | return;
|
---|
105 |
|
---|
106 | Double_t *temp = fArray;
|
---|
107 | if (n == 0)
|
---|
108 | fArray = NULL;
|
---|
109 | else
|
---|
110 | {
|
---|
111 | fArray = new Double_t[n];
|
---|
112 | if (n < fN)
|
---|
113 | memcpy(fArray, temp, n*sizeof(Double_t));
|
---|
114 | else
|
---|
115 | {
|
---|
116 | memcpy(fArray, temp, fN*sizeof(Double_t));
|
---|
117 | memset(&fArray[fN], 0, (n-fN)*sizeof(Double_t));
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (fN)
|
---|
122 | delete [] temp;
|
---|
123 |
|
---|
124 | fN = n;
|
---|
125 | }
|
---|
126 |
|
---|
127 | void Set(UInt_t n, Double_t *array)
|
---|
128 | {
|
---|
129 | // Set size of this array to n chars and set the contents.
|
---|
130 | if (!array)
|
---|
131 | return;
|
---|
132 |
|
---|
133 | if (fArray && fN != n)
|
---|
134 | {
|
---|
135 | delete [] fArray;
|
---|
136 | fArray = 0;
|
---|
137 | }
|
---|
138 | fN = n;
|
---|
139 |
|
---|
140 | if (fN == 0)
|
---|
141 | return;
|
---|
142 |
|
---|
143 | if (!fArray)
|
---|
144 | fArray = new Double_t[fN];
|
---|
145 |
|
---|
146 | memcpy(fArray, array, n*sizeof(Double_t));
|
---|
147 | }
|
---|
148 |
|
---|
149 | Double_t &operator[](UInt_t i)
|
---|
150 | {
|
---|
151 | return fArray[i];
|
---|
152 | }
|
---|
153 |
|
---|
154 | ClassDef(MArrayD, 1) //Array of Double_t
|
---|
155 | };
|
---|
156 |
|
---|
157 | #endif
|
---|