4#ifndef KalFitList_FLAG_
5#define KalFitList_FLAG_
82#ifdef KalFitList_NO_INLINE
86#define KalFitList_INLINE_DEFINE_HERE
89#ifdef KalFitList_INLINE_DEFINE_HERE
95 _remain(length_to_alloc),
96 _length_to_alloc(length_to_alloc),
97 _obj((T *) malloc(length_to_alloc * sizeof(T))){
102 : _length(src._length),
103 _remain(src._remain),
104 _length_to_alloc(src._length_to_alloc)
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);
124 _obj = (T *) realloc(_obj,(_length+_length_to_alloc) *
sizeof(T));
125 _remain = _length_to_alloc;
127 *(_obj+(_length++)) = src;
136 *(_obj+(iterator--)) = *(_obj+(--_length));
145 *(_obj+iterator) = *(_obj+(--_length));
160 delete *(_obj+iterator);
161 *(_obj+(iterator--)) = *(_obj+(--_length));
197 _obj = (T *) realloc(_obj,_length *
sizeof(T));
199 _length_to_alloc = _length;
234 return _obj + (_length - 1);
247 int srcLength = src._length;
248 T * srcObj = src._obj;
250 if (_remain < srcLength){
251 _obj = (T *) realloc(_obj,(_length_to_alloc + srcLength) *
sizeof(T));
252 while(i^srcLength) *(_obj+(_length++)) = *(srcObj+(i++));
254 while(i^srcLength) *(_obj+(_length++)) = *(srcObj+(i++));
255 _remain -= srcLength;
264 while (i)
delete *(_obj + (--i));
KalFitList(const KalFitList< T > &)
copy constructor
int append(T x)
append an object into the end of the list
T * lastPtr(void) const
returns the pointer of last object
int length(void) const
returns the length of the list
int remove(int &)
remove objects by index and returns decremented index and length
void remove2(int)
remove objects by index
int append(const KalFitList< T > &)
append objects into the end of the list
T * firstPtr(void) const
returns the pointer of first object
T & operator()(unsigned i) const
returns the reference of a object by index
void clear(void)
clear lists but the allocated memory remains same
void replace(int i, T src)
replace index-th object by the object src
T first(void) const
returns the first object in the list
void deleteAll(void)
delete all object and clear(allocated memory remains same)
void resize(void)
re-allocate memory to reduce size
KalFitList(int length_to_alloc=100)
default constructor
void removeAll(void)
clear lists and free memory
T operator[](unsigned i) const
returns a object by index
int deleteObj(int &)
delete objects by index and returns decremented index and length
void removeLast(void)
remove just last objects of the list