BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitList< T > Class Template Reference

#include <KalFitList.h>

Public Member Functions

 KalFitList (int length_to_alloc=100)
 default constructor
 
 KalFitList (const KalFitList< T > &)
 copy constructor
 
 ~KalFitList ()
 destructor
 
int append (T x)
 append an object into the end of the list
 
int append (const KalFitList< T > &)
 append objects into the end of the list
 
int remove (int &)
 remove objects by index and returns decremented index and length
 
void remove2 (int)
 remove objects by index
 
void replace (int i, T src)
 replace index-th object by the object src
 
int deleteObj (int &)
 delete objects by index and returns decremented index and length
 
void removeLast (void)
 remove just last objects of the list
 
void clear (void)
 clear lists but the allocated memory remains same
 
void removeAll (void)
 clear lists and free memory
 
void deleteAll (void)
 delete all object and clear(allocated memory remains same)
 
void resize (void)
 re-allocate memory to reduce size
 
operator[] (unsigned i) const
 returns a object by index
 
T & operator() (unsigned i) const
 returns the reference of a object by index
 
first (void) const
 returns the first object in the list
 
T * firstPtr (void) const
 returns the pointer of first object
 
T * lastPtr (void) const
 returns the pointer of last object
 
int length (void) const
 returns the length of the list
 

Detailed Description

template<class T>
class KalFitList< T >

Definition at line 11 of file KalFitList.h.

Constructor & Destructor Documentation

◆ KalFitList() [1/2]

template<class T >
KalFitList< T >::KalFitList ( int  length_to_alloc = 100)
inline

default constructor

Definition at line 93 of file KalFitList.h.

94 : _length(0),
95 _remain(length_to_alloc),
96 _length_to_alloc(length_to_alloc),
97 _obj((T *) malloc(length_to_alloc * sizeof(T))){
98}

◆ KalFitList() [2/2]

template<class T >
KalFitList< T >::KalFitList ( const KalFitList< T > &  src)

copy constructor

Definition at line 101 of file KalFitList.h.

102 : _length(src._length),
103 _remain(src._remain),
104 _length_to_alloc(src._length_to_alloc)
105{
106 _obj = (T *) malloc((_length + _remain) * sizeof(T));
107 T * srcObj = src._obj;
108 for (int i = 0; i < _length; i++){
109 *(_obj+i) = *(srcObj+i);
110 }
111}

◆ ~KalFitList()

template<class T >
KalFitList< T >::~KalFitList
inline

destructor

Definition at line 115 of file KalFitList.h.

115 {
116 free(_obj);
117}

Member Function Documentation

◆ append() [1/2]

template<class T >
int KalFitList< T >::append ( const KalFitList< T > &  src)

append objects into the end of the list

Definition at line 245 of file KalFitList.h.

246{
247 int srcLength = src._length;
248 T * srcObj = src._obj;
249 int i = 0;
250 if (_remain < srcLength){
251 _obj = (T *) realloc(_obj,(_length_to_alloc + srcLength) * sizeof(T));
252 while(i^srcLength) *(_obj+(_length++)) = *(srcObj+(i++));
253 }else{
254 while(i^srcLength) *(_obj+(_length++)) = *(srcObj+(i++));
255 _remain -= srcLength;
256 }
257 return _length;
258}

◆ append() [2/2]

template<class T >
int KalFitList< T >::append ( x)
inline

append an object into the end of the list

Definition at line 122 of file KalFitList.h.

122 {
123 if (!_remain){
124 _obj = (T *) realloc(_obj,(_length+_length_to_alloc) * sizeof(T));
125 _remain = _length_to_alloc;
126 }
127 *(_obj+(_length++)) = src;
128 _remain--;
129 return _length;
130}

Referenced by KalFitSuper_Mdc::appendHit().

◆ clear()

template<class T >
void KalFitList< T >::clear ( void  )
inline

clear lists but the allocated memory remains same

Definition at line 177 of file KalFitList.h.

177 {
178 _remain += _length;
179 _length = 0;
180}

Referenced by KalFitSuper_Mdc::clear().

◆ deleteAll()

template<class T >
void KalFitList< T >::deleteAll ( void  )

delete all object and clear(allocated memory remains same)

Definition at line 261 of file KalFitList.h.

262{
263 int i = _length;
264 while (i) delete *(_obj + (--i));
265 clear();
266}
void clear(void)
clear lists but the allocated memory remains same
Definition: KalFitList.h:177

◆ deleteObj()

template<class T >
int KalFitList< T >::deleteObj ( int &  iterator)
inline

delete objects by index and returns decremented index and length

Definition at line 159 of file KalFitList.h.

159 {
160 delete *(_obj+iterator);
161 *(_obj+(iterator--)) = *(_obj+(--_length));
162 _remain++;
163 return _length;
164}

◆ first()

template<class T >
T KalFitList< T >::first ( void  ) const
inline

returns the first object in the list

Definition at line 219 of file KalFitList.h.

219 {
220 return *_obj;
221}

◆ firstPtr()

template<class T >
T * KalFitList< T >::firstPtr ( void  ) const
inline

returns the pointer of first object

Definition at line 226 of file KalFitList.h.

226 {
227 return _obj;
228}

Referenced by KalFitSuper_Mdc::clear().

◆ lastPtr()

template<class T >
T * KalFitList< T >::lastPtr ( void  ) const
inline

returns the pointer of last object

Definition at line 233 of file KalFitList.h.

233 {
234 return _obj + (_length - 1);
235}

Referenced by KalFitSuper_Mdc::clear().

◆ length()

template<class T >
int KalFitList< T >::length ( void  ) const
inline

returns the length of the list

Definition at line 240 of file KalFitList.h.

240 {
241 return _length;
242}

Referenced by KalFitSuper_Mdc::clear().

◆ operator()()

template<class T >
T & KalFitList< T >::operator() ( unsigned  i) const
inline

returns the reference of a object by index

Definition at line 212 of file KalFitList.h.

212 {
213 return *(_obj+i);
214}

◆ operator[]()

template<class T >
T KalFitList< T >::operator[] ( unsigned  i) const
inline

returns a object by index

Definition at line 205 of file KalFitList.h.

205 {
206 return *(_obj+i);
207}

◆ remove()

template<class T >
int KalFitList< T >::remove ( int &  iterator)
inline

remove objects by index and returns decremented index and length

Definition at line 135 of file KalFitList.h.

135 {
136 *(_obj+(iterator--)) = *(_obj+(--_length));
137 _remain++;
138 return _length;
139}

◆ remove2()

template<class T >
void KalFitList< T >::remove2 ( int  iterator)
inline

remove objects by index

Definition at line 144 of file KalFitList.h.

144 {
145 *(_obj+iterator) = *(_obj+(--_length));
146 _remain++;
147}

◆ removeAll()

template<class T >
void KalFitList< T >::removeAll ( void  )
inline

clear lists and free memory

Definition at line 185 of file KalFitList.h.

185 {
186 free(_obj);
187 _remain = 0;
188 _length = 0;
189 _obj = NULL;
190}

◆ removeLast()

template<class T >
void KalFitList< T >::removeLast ( void  )
inline

remove just last objects of the list

Definition at line 169 of file KalFitList.h.

169 {
170 _length--;
171 _remain++;
172}

◆ replace()

template<class T >
void KalFitList< T >::replace ( int  i,
src 
)
inline

replace index-th object by the object src

Definition at line 152 of file KalFitList.h.

152 {
153 *(_obj+i) = src;
154}

◆ resize()

template<class T >
void KalFitList< T >::resize ( void  )
inline

re-allocate memory to reduce size

Definition at line 196 of file KalFitList.h.

196 {
197 _obj = (T *) realloc(_obj,_length * sizeof(T));
198 _remain = 0;
199 _length_to_alloc = _length;
200}

The documentation for this class was generated from the following file: