KalFitList< T > Class Template Reference

#include <KalFitList.h>

List of all members.

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

Private Attributes

int _length
int _remain
int _length_to_alloc
T * _obj


Detailed Description

template<class T>
class KalFitList< T >

Definition at line 11 of file KalFitList.h.


Constructor & Destructor Documentation

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

default constructor

Definition at line 93 of file KalFitList.h.

00094   : _length(0),
00095     _remain(length_to_alloc),
00096     _length_to_alloc(length_to_alloc),
00097     _obj((T *) malloc(length_to_alloc * sizeof(T))){
00098 }

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

copy constructor

Definition at line 101 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_obj, KalFitList< T >::_remain, genRecEmupikp::i, and T.

00102   : _length(src._length),
00103     _remain(src._remain),
00104     _length_to_alloc(src._length_to_alloc)
00105 {
00106   _obj = (T *) malloc((_length + _remain) * sizeof(T));
00107   T * srcObj = src._obj;
00108   for (int i = 0; i < _length; i++){
00109     *(_obj+i) = *(srcObj+i);
00110   }
00111 }

template<class T>
KalFitList< T >::~KalFitList (  )  [inline]

destructor

Definition at line 115 of file KalFitList.h.

References KalFitList< T >::_obj.

00115                           {
00116   free(_obj);
00117 }


Member Function Documentation

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

append objects into the end of the list

Definition at line 245 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_length_to_alloc, KalFitList< T >::_obj, KalFitList< T >::_remain, genRecEmupikp::i, and T.

00246 {
00247   int srcLength = src._length;
00248   T * srcObj = src._obj;
00249   int i = 0;
00250   if (_remain < srcLength){
00251     _obj = (T *) realloc(_obj,(_length_to_alloc + srcLength) * sizeof(T));
00252     while(i^srcLength) *(_obj+(_length++)) = *(srcObj+(i++));
00253   }else{
00254     while(i^srcLength) *(_obj+(_length++)) = *(srcObj+(i++));
00255     _remain -= srcLength;
00256   }
00257   return _length;
00258 }

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.

References KalFitList< T >::_length, KalFitList< T >::_length_to_alloc, KalFitList< T >::_obj, KalFitList< T >::_remain, and T.

Referenced by KalFitSuper_Mdc::appendHit().

00122                           {
00123   if (!_remain){
00124     _obj = (T *) realloc(_obj,(_length+_length_to_alloc) * sizeof(T));
00125     _remain = _length_to_alloc;
00126   }
00127   *(_obj+(_length++)) = src;
00128   _remain--;
00129   return _length;
00130 }

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.

References KalFitList< T >::_length, and KalFitList< T >::_remain.

Referenced by KalFitSuper_Mdc::clear(), and KalFitList< T >::deleteAll().

00177                         {
00178   _remain += _length;
00179   _length = 0;
00180 }

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.

References KalFitList< T >::_length, KalFitList< T >::_obj, KalFitList< T >::clear(), and genRecEmupikp::i.

00262 {
00263   int i = _length;
00264   while (i) delete *(_obj + (--i));
00265   clear();
00266 }

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

delete objects by index and returns decremented index and length

Definition at line 159 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_obj, and KalFitList< T >::_remain.

00159                                       {
00160   delete *(_obj+iterator);
00161   *(_obj+(iterator--)) = *(_obj+(--_length));
00162   _remain++;
00163   return _length;
00164 }

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.

References KalFitList< T >::_obj.

00219                               {
00220   return *_obj;
00221 }

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

returns the pointer of first object

Definition at line 226 of file KalFitList.h.

References KalFitList< T >::_obj.

Referenced by KalFitSuper_Mdc::clear().

00226                                  {
00227   return _obj;
00228 }

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

returns the pointer of last object

Definition at line 233 of file KalFitList.h.

References KalFitList< T >::_length, and KalFitList< T >::_obj.

Referenced by KalFitSuper_Mdc::clear().

00233                                 {
00234   return _obj + (_length - 1);
00235 }

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

returns the length of the list

Definition at line 240 of file KalFitList.h.

References KalFitList< T >::_length.

Referenced by KalFitSuper_Mdc::clear().

00240                                {
00241   return _length;
00242 }

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.

References KalFitList< T >::_obj.

00212                                           {
00213   return *(_obj+i);
00214 }

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

returns a object by index

Definition at line 205 of file KalFitList.h.

References KalFitList< T >::_obj.

00205                                           {
00206   return *(_obj+i);
00207 }

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

remove objects by index and returns decremented index and length

Definition at line 135 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_obj, and KalFitList< T >::_remain.

00135                                    {
00136   *(_obj+(iterator--)) = *(_obj+(--_length));
00137   _remain++;
00138   return _length;
00139 }

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

remove objects by index

Definition at line 144 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_obj, and KalFitList< T >::_remain.

00144                                   {
00145   *(_obj+iterator) = *(_obj+(--_length));
00146   _remain++;
00147 }

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

clear lists and free memory

Definition at line 185 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_obj, and KalFitList< T >::_remain.

00185                             {
00186   free(_obj);
00187   _remain = 0;
00188   _length = 0;
00189   _obj = NULL;
00190 }

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

remove just last objects of the list

Definition at line 169 of file KalFitList.h.

References KalFitList< T >::_length, and KalFitList< T >::_remain.

00169                              {
00170   _length--;
00171   _remain++;
00172 }

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.

References KalFitList< T >::_obj.

00152                                   {
00153   *(_obj+i) = src;
00154 }

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

re-allocate memory to reduce size

Definition at line 196 of file KalFitList.h.

References KalFitList< T >::_length, KalFitList< T >::_length_to_alloc, KalFitList< T >::_obj, KalFitList< T >::_remain, and T.

00196                          {
00197   _obj = (T *) realloc(_obj,_length * sizeof(T));
00198   _remain = 0;
00199   _length_to_alloc = _length;
00200 }


Member Data Documentation

template<class T>
int KalFitList< T >::_length [private]

Definition at line 75 of file KalFitList.h.

Referenced by KalFitList< T >::append(), KalFitList< T >::clear(), KalFitList< T >::deleteAll(), KalFitList< T >::deleteObj(), KalFitList< T >::KalFitList(), KalFitList< T >::lastPtr(), KalFitList< T >::length(), KalFitList< T >::remove(), KalFitList< T >::remove2(), KalFitList< T >::removeAll(), KalFitList< T >::removeLast(), and KalFitList< T >::resize().

template<class T>
int KalFitList< T >::_length_to_alloc [private]

Definition at line 77 of file KalFitList.h.

Referenced by KalFitList< T >::append(), and KalFitList< T >::resize().

template<class T>
T* KalFitList< T >::_obj [private]

Definition at line 78 of file KalFitList.h.

Referenced by KalFitList< T >::append(), KalFitList< T >::deleteAll(), KalFitList< T >::deleteObj(), KalFitList< T >::first(), KalFitList< T >::firstPtr(), KalFitList< T >::KalFitList(), KalFitList< T >::lastPtr(), KalFitList< T >::operator()(), KalFitList< T >::operator[](), KalFitList< T >::remove(), KalFitList< T >::remove2(), KalFitList< T >::removeAll(), KalFitList< T >::replace(), KalFitList< T >::resize(), and KalFitList< T >::~KalFitList().

template<class T>
int KalFitList< T >::_remain [private]

Definition at line 76 of file KalFitList.h.

Referenced by KalFitList< T >::append(), KalFitList< T >::clear(), KalFitList< T >::deleteObj(), KalFitList< T >::KalFitList(), KalFitList< T >::remove(), KalFitList< T >::remove2(), KalFitList< T >::removeAll(), KalFitList< T >::removeLast(), and KalFitList< T >::resize().


Generated on Tue Nov 29 23:19:55 2016 for BOSS_7.0.2 by  doxygen 1.4.7