4#ifndef KalFitList_FLAG_
5#define KalFitList_FLAG_
80#ifdef KalFitList_NO_INLINE
84# define KalFitList_INLINE_DEFINE_HERE
87#ifdef KalFitList_INLINE_DEFINE_HERE
92 , _remain( length_to_alloc )
93 , _length_to_alloc( length_to_alloc )
94 , _obj( (T*)malloc( length_to_alloc * sizeof( T ) ) ) {}
98 : _length( src._length )
99 , _remain( src._remain )
100 , _length_to_alloc( src._length_to_alloc ) {
101 _obj = (T*)malloc( ( _length + _remain ) *
sizeof( T ) );
102 T* srcObj = src._obj;
103 for (
int i = 0; i < _length; i++ ) { *( _obj + i ) = *( srcObj + i ); }
111 _obj = (T*)realloc( _obj, ( _length + _length_to_alloc ) *
sizeof( T ) );
112 _remain = _length_to_alloc;
114 *( _obj + ( _length++ ) ) = src;
120 *( _obj + ( iterator-- ) ) = *( _obj + ( --_length ) );
126 *( _obj + iterator ) = *( _obj + ( --_length ) );
133 delete *( _obj + iterator );
134 *( _obj + ( iterator-- ) ) = *( _obj + ( --_length ) );
157 _obj = (T*)realloc( _obj, _length *
sizeof( T ) );
159 _length_to_alloc = _length;
163 return *( _obj + i );
167 return *( _obj + i );
175 return _obj + ( _length - 1 );
181 int srcLength = src._length;
182 T* srcObj = src._obj;
184 if ( _remain < srcLength )
186 _obj = (T*)realloc( _obj, ( _length_to_alloc + srcLength ) *
sizeof( T ) );
187 while ( i ^ srcLength ) *( _obj + ( _length++ ) ) = *( srcObj + ( i++ ) );
191 while ( i ^ srcLength ) *( _obj + ( _length++ ) ) = *( srcObj + ( i++ ) );
192 _remain -= srcLength;
199 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