source: trunk/MagicSoft/Mars/mbase/MArrayD.h@ 6724

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