source: trunk/MagicSoft/Mars/mbase/MArrayF.h@ 5054

Last change on this file since 5054 was 4958, checked in by gaug, 20 years ago
*** empty log message ***
File size: 3.1 KB
Line 
1#ifndef MARS_MArrayF
2#define MARS_MArrayF
3
4#ifndef MARS_MArray
5#include "MArray.h"
6#endif
7
8#include <string.h>
9
10class TArrayF;
11class MArrayF : public MArray
12{
13private:
14 Float_t *fArray; //[fN] Array of fN chars
15
16public:
17
18 MArrayF()
19 {
20 fN = 0;
21 fArray = NULL;
22 }
23
24 MArrayF(UInt_t n)
25 {
26 fN = 0;
27 fArray = NULL;
28 Set(n);
29 }
30
31 MArrayF(UInt_t n, Float_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 MArrayF(const MArrayF &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 MArrayF &operator=(const MArrayF &rhs)
52 {
53 // TArrayC assignment operator.
54 if (this != &rhs)
55 Set(rhs.fN, rhs.fArray);
56 return *this;
57 }
58
59 virtual ~MArrayF()
60 {
61 // Delete TArrayC object.
62 delete [] fArray;
63 fArray = NULL;
64 }
65
66 void Adopt(UInt_t n, Float_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(Float_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 Float_t At(UInt_t i) const
84 {
85 return fArray[i];
86 }
87
88 Float_t *GetArray() const
89 {
90 return fArray;
91 }
92
93 void Reset()
94 {
95 memset(fArray, 0, fN*sizeof(Float_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 Float_t *temp = fArray;
108 if (n == 0)
109 fArray = NULL;
110 else
111 {
112 fArray = new Float_t[n];
113 if (n < fN)
114 memcpy(fArray, temp, n*sizeof(Float_t));
115 else
116 {
117 memcpy(fArray, temp, fN*sizeof(Float_t));
118 memset(&fArray[fN], 0, (n-fN)*sizeof(Float_t));
119 }
120 }
121
122 if (fN)
123 delete [] temp;
124
125 fN = n;
126 }
127
128 void Set(UInt_t n, Float_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 Float_t[fN];
146
147 memcpy(fArray, array, n*sizeof(Float_t));
148 }
149
150 Float_t &operator[](UInt_t i)
151 {
152 return fArray[i];
153 }
154 const Float_t &operator[](UInt_t i) const
155 {
156 return fArray[i];
157 }
158
159 static void StripZeros(TArrayF &arr);
160 void StripZeros();
161
162 ClassDef(MArrayF, 1) //Array of Float_t
163};
164
165#endif
Note: See TracBrowser for help on using the repository browser.