Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

idList Class Template Reference

#include <util_list.h>

Inheritance diagram for idList:

Inheritance graph
[legend]

template<class type>
class idList< type >


Public Types

typedef int cmp_t (const void *, const void *)
typedef int cmp_t (const void *, const void *)

Public Member Functions

int AddUnique (type const &obj)
int AddUnique (type const &obj)
int Append (type const &obj)
int Append (type const &obj)
void Clear (void)
void Clear (void)
void Condense (void)
void Condense (void)
typeFind (type const &obj, int *index=NULL)
typeFind (type const &obj, int *index=NULL)
 idList (int granularity=16)
 idList (int granularity=16)
int Num (void)
int Num (void)
typeoperator[] (int index)
type operator[] (int index) const
typeoperator[] (int index)
type operator[] (int index) const
bool Remove (type const &obj)
bool Remove (type const &obj)
bool RemoveIndex (int index)
bool RemoveIndex (int index)
void Resize (int size)
void Resize (int size)
void SetGranularity (int granularity)
void SetGranularity (int granularity)
void SetNum (int num)
void SetNum (int num)
int Size (void)
int Size (void)
void Sort (cmp_t *compare)
void Sort (cmp_t *compare)
 ~idList ()
 ~idList ()

Private Attributes

int m_granularity
typem_list
typem_list
int m_num
int m_size

Member Typedef Documentation

typedef int cmp_t(const void *, const void *)
 

Definition at line 53 of file util_list.h.

typedef int cmp_t(const void *, const void *)
 

Definition at line 53 of file util_list.h.

Referenced by Sort().


Constructor & Destructor Documentation

idList int  granularity = 16  )  [inline]
 

Definition at line 63 of file util_list.h.

References assert, Clear(), m_granularity, and m_list.

00063                                              {
00064     assert( granularity > 0 );
00065 
00066     m_list          = NULL;
00067     m_granularity   = granularity;
00068     Clear();
00069 }

Here is the call graph for this function:

~idList  )  [inline]
 

Definition at line 77 of file util_list.h.

References Clear().

00077                              {
00078     Clear();
00079 }

Here is the call graph for this function:

idList int  granularity = 16  ) 
 

~idList  ) 
 


Member Function Documentation

int AddUnique type const &  obj  ) 
 

int AddUnique type const &  obj  )  [inline]
 

Definition at line 257 of file util_list.h.

References Append(), and Find().

00257                                                      {
00258     int index;
00259 
00260     if ( !Find( obj, &index ) ) {
00261         index = Append( obj );
00262     }
00263 
00264     return index;
00265 }

Here is the call graph for this function:

int Append type const &  obj  ) 
 

int Append type const &  obj  )  [inline]
 

Definition at line 236 of file util_list.h.

References m_granularity, m_list, m_num, m_size, and Resize().

Referenced by idCameraDef::addEvent(), idCameraDef::addTarget(), AddUnique(), idCameraPosition::addVelocity(), idCameraDef::buildCamera(), idSplineList::buildSpline(), idSplineList::initPosition(), and idCameraDef::parse().

00236                                                   {
00237     if ( !m_list ) {
00238         Resize( m_granularity );
00239     }
00240 
00241     if ( m_num == m_size ) {
00242         Resize( m_size + m_granularity );
00243     }
00244 
00245     m_list[ m_num ] = obj;
00246     m_num++;
00247 
00248     return m_num - 1;
00249 }

Here is the call graph for this function:

void Clear void   ) 
 

void Clear void   )  [inline]
 

Definition at line 87 of file util_list.h.

References m_list, m_num, and m_size.

Referenced by idCameraPosition::clear(), Condense(), idList(), idSplineList::initPosition(), Resize(), and ~idList().

00087                                       {
00088     if ( m_list ) {
00089         delete[] m_list;
00090     }
00091 
00092     m_list  = NULL;
00093     m_num   = 0;
00094     m_size  = 0;
00095 }

void Condense void   ) 
 

void Condense void   )  [inline]
 

Definition at line 151 of file util_list.h.

References Clear(), m_num, and Resize().

00151                                          {
00152     if ( m_list ) {
00153         if ( m_num ) {
00154             Resize( m_num );
00155         } else {
00156             Clear();
00157         }
00158     }
00159 }

Here is the call graph for this function:

type* Find type const &  obj,
int *  index = NULL
 

type * Find type const &  obj,
int *  index = NULL
[inline]
 

Definition at line 273 of file util_list.h.

References i, and m_list.

Referenced by AddUnique(), and Remove().

00273                                                               {
00274     int i;
00275 
00276     for( i = 0; i < m_num; i++ ) {
00277         if ( m_list[ i ] == obj ) {
00278             if ( index ) {
00279                 *index = i;
00280             }
00281             return &m_list[ i ];
00282         }
00283     }
00284 
00285     return NULL;
00286 }

int Num void   ) 
 

int Num void   )  [inline]
 

Definition at line 103 of file util_list.h.

Referenced by idSplineList::addToRenderer(), idCameraDef::buildCamera(), idSplineList::buildSpline(), idCameraPosition::clear(), idSplineList::draw(), idCameraDef::getCameraInfo(), idSplineList::getPosition(), idCameraPosition::getVelocity(), idSplineList::initPosition(), idCameraDef::save(), idSplineList::setSelectedPoint(), idSplineList::totalDistance(), idCameraPosition::write(), and idSplineList::write().

00103                                    {
00104     return m_num;
00105 }

type& operator[] int  index  ) 
 

type operator[] int  index  )  const
 

type & operator[] int  index  )  [inline]
 

Definition at line 223 of file util_list.h.

References assert, m_list, and m_num.

00223                                                  {
00224     assert( index >= 0 );
00225     assert( index < m_num );
00226 
00227     return m_list[ index ];
00228 }

type operator[] int  index  )  const [inline]
 

Definition at line 210 of file util_list.h.

References assert, m_list, and m_num.

00210                                                       {
00211     assert( index >= 0 );
00212     assert( index < m_num );
00213 
00214     return m_list[ index ];
00215 }

bool Remove type const &  obj  ) 
 

bool Remove type const &  obj  )  [inline]
 

Definition at line 322 of file util_list.h.

References Find(), and RemoveIndex().

00322                                                    {
00323     int index;
00324 
00325     if ( Find( obj, &index ) ) {
00326         return RemoveIndex( index );
00327     }
00328     
00329     return false;
00330 }

Here is the call graph for this function:

bool RemoveIndex int  index  ) 
 

bool RemoveIndex int  index  )  [inline]
 

Definition at line 294 of file util_list.h.

References assert, i, m_list, and m_num.

Referenced by Remove().

00294                                                  {
00295     int i;
00296 
00297     if ( !m_list || !m_num ) {
00298         return false;
00299     }
00300 
00301     assert( index >= 0 );
00302     assert( index < m_num );
00303 
00304     if ( ( index < 0 ) || ( index >= m_num ) ) {
00305         return false;
00306     }
00307 
00308     m_num--;
00309     for( i = index; i < m_num; i++ ) {
00310         m_list[ i ] = m_list[ i + 1 ];
00311     }
00312 
00313     return true;
00314 }

void Resize int  size  ) 
 

void Resize int  size  )  [inline]
 

Definition at line 177 of file util_list.h.

References assert, Clear(), i, m_list, m_num, and m_size.

Referenced by Append(), Condense(), SetGranularity(), and SetNum().

00177                                            {
00178     type    *temp;
00179     int     i;
00180 
00181     assert( size > 0 );
00182 
00183     if ( size <= 0 ) {
00184         Clear();
00185         return;
00186     }
00187 
00188     temp    = m_list;
00189     m_size  = size;
00190     if ( m_size < m_num ) {
00191         m_num = m_size;
00192     }
00193 
00194     m_list = new type[ m_size ];
00195     for( i = 0; i < m_num; i++ ) {
00196         m_list[ i ] = temp[ i ];
00197     }
00198 
00199     if ( temp ) {
00200         delete[] temp;
00201     }
00202 }

Here is the call graph for this function:

void SetGranularity int  granularity  ) 
 

void SetGranularity int  granularity  )  [inline]
 

Definition at line 128 of file util_list.h.

References assert, m_granularity, m_num, newsize, and Resize().

00128                                                           {
00129     int newsize;
00130 
00131     assert( granularity > 0 );
00132     m_granularity = granularity;
00133 
00134     if ( m_list ) {
00135         // resize it to the closest level of granularity
00136         newsize = ( ( m_num + m_granularity - 1 ) / m_granularity ) * m_granularity;
00137         if ( newsize != m_size ) {
00138             Resize( newsize );
00139         }
00140     }
00141 }

Here is the call graph for this function:

void SetNum int  num  ) 
 

void SetNum int  num  )  [inline]
 

Definition at line 113 of file util_list.h.

References assert, m_granularity, m_num, and Resize().

00113                                           {
00114     assert( num >= 0 );
00115     if ( num > m_size ) {
00116         // resize it up to the closest level of granularity
00117         Resize( ( ( num + m_granularity - 1 ) / m_granularity ) * m_granularity );
00118     }
00119     m_num = num;
00120 }

Here is the call graph for this function:

int Size void   ) 
 

int Size void   )  [inline]
 

Definition at line 167 of file util_list.h.

00167                                     {
00168     return m_size;
00169 }

void Sort cmp_t compare  ) 
 

void Sort cmp_t compare  )  [inline]
 

Definition at line 338 of file util_list.h.

References cmp_t, m_list, m_num, qsort(), and size_t.

00338                                                {
00339     if ( !m_list ) {
00340         return;
00341     }
00342 
00343     qsort( ( void * )m_list, ( size_t )m_num, sizeof( type ), compare );
00344 }

Here is the call graph for this function:


Field Documentation

int m_granularity [private]
 

Definition at line 33 of file util_list.h.

Referenced by Append(), idList(), SetGranularity(), and SetNum().

type* m_list [private]
 

Definition at line 34 of file util_list.h.

type* m_list [private]
 

Definition at line 34 of file util_list.h.

Referenced by Append(), Clear(), Find(), idList(), operator[](), RemoveIndex(), Resize(), and Sort().

int m_num [private]
 

Definition at line 31 of file util_list.h.

Referenced by Append(), Clear(), Condense(), operator[](), RemoveIndex(), Resize(), SetGranularity(), SetNum(), and Sort().

int m_size [private]
 

Definition at line 32 of file util_list.h.

Referenced by Append(), Clear(), and Resize().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 19:54:03 2005 for Quake III Arena by  doxygen 1.3.9.1