TableauDyn< T > Class Template Reference

Classe Template d'un tableau dynamique. More...

#include <TableauDyn.h>

Inheritance diagram for TableauDyn< T >:

Inheritance graph
[legend]
Collaboration diagram for TableauDyn< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TableauDyn ()
 Constructeur par défaut.
 TableauDyn (int nb)
 Construction d'un tablea de nb éléments.
 TableauDyn (const TableauDyn< T > &l)
 Constructeur par recopie.
 ~TableauDyn ()
TableauDyn< T > & Cons (T val, int pos)
 Ajout de val à la position pos.
TableauDyn< T > & ConsTete (T val)
 Ajout de val en tête.
TableauDyn< T > & ConsQueue (T val)
 Ajout de val en queue.
void Modifier (int pos, T elt)
 Modification de l'élément en pos par T.
void SetTaille (unsigned int nb)
 Définir la taille du tableau (si connue)
Evite les réalocations multiples.
TableauDyn< T > & Detruit (unsigned int i)
 Destruction de l'élément i.
TableauDyn< T > & DetruitVirtuel (unsigned int pos)
 Destruction virtuel, ne fait que décrémenter le cardinal du tableau
A n'utiliser qu'en des cas très précis !.
unsigned int Card () const
 Retourne le nombre d'élément du tableau.
Tete () const
 Accéder à la tête de la liste.
Valeur (int i) const
 Accesseur de la ième valeur.
operator[] (int i) const
 Surcharge de [].
void Afficher () const
 Affichage du tableau.
const TableauDyn< T > & operator= (const TableauDyn< T > &l)
 Surcharge de =.

Protected Attributes

T * mTab
 Tableau dynamique.
int mCard
 Nombre de valeurs alloués.

Detailed Description

template<class T>
class TableauDyn< T >

Classe Template d'un tableau dynamique.

Definition at line 14 of file TableauDyn.h.


Constructor & Destructor Documentation

template<class T>
TableauDyn< T >::TableauDyn (  ) 

Constructeur par défaut.

Returns:

Definition at line 146 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00146                                            {
00147         mCard=0;
00148         mTab=NULL;
00149 }

template<class T>
TableauDyn< T >::TableauDyn ( int  nb  ) 

Construction d'un tablea de nb éléments.

Parameters:
nb Nombre d'éléments du tableau
Returns:

Definition at line 151 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00151                                                  {
00152         mCard=nb;
00153         mTab=new T [nb];
00154 }

template<class T>
TableauDyn< T >::TableauDyn ( const TableauDyn< T > &  l  ) 

Constructeur par recopie.

Parameters:
l TableauDyn de base
Returns:

Definition at line 156 of file TableauDyn.h.

References TableauDyn< T >::Card(), TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00156                                                                  {
00157         delete [] mTab;
00158         mCard=l.Card();
00159         mTab=new T [mCard];
00160         for(unsigned int i=0; i<l.Card(); i++){
00161                 mTab[i]=l[i];
00162         }
00163 }

Here is the call graph for this function:

template<class T>
TableauDyn< T >::~TableauDyn (  ) 

Definition at line 166 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00166                                             {
00167         delete [] mTab;
00168         mCard=0; 
00169 }


Member Function Documentation

template<class T>
TableauDyn< T > & TableauDyn< T >::Cons ( val,
int  pos 
)

Ajout de val à la position pos.

Parameters:
val Valeur à ajouter
pos Indice d'insertion
Returns:
Le nouveau tableau (pour l'appel récursif au besoin)

Definition at line 172 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

Referenced by TableauDyn< T >::ConsQueue(), and TableauDyn< T >::ConsTete().

00172                                                                     {
00173         //Allocation du tableau temporaire
00174         T *tab=new T[mCard+1];
00175         //Recopie jusqu pos
00176         for(int i=0; i<pos; i++){
00177                 tab[i]=mTab[i];
00178         }
00179         //Construction en pos de la valeur
00180         tab[pos]=val;
00181         //Recopie du reste
00182         for(int i=pos; i<mCard; i++){
00183                 tab[i+1]=mTab[i];
00184         }
00185         //Desctruction de l'ancien tableau
00186         delete[] mTab;
00187         //Nouvelle allocation
00188         mTab=new T[mCard+1];
00189         //Recopie
00190         for(int i=0; i<mCard+1; i++){
00191                 mTab[i]=tab[i];
00192         }
00193         mCard++;
00194         //Destruction du tableau temporaire
00195         delete[] tab;
00196         return (*this);
00197 }

template<class T>
TableauDyn< T > & TableauDyn< T >::ConsTete ( val  ) 

Ajout de val en tête.

Parameters:
val Valeur à ajouter
Returns:
Le nouveau tableau (pour l'appel récursif au besoin)

Definition at line 199 of file TableauDyn.h.

References TableauDyn< T >::Cons().

00199                                                                {
00200         Cons(val,0);
00201         return (*this);
00202 }

Here is the call graph for this function:

template<class T>
TableauDyn< T > & TableauDyn< T >::ConsQueue ( val  ) 

Ajout de val en queue.

Parameters:
val Valeur à ajouter
Returns:
Le nouveau tableau (pour l'appel récursif au besoin)

Definition at line 204 of file TableauDyn.h.

References TableauDyn< T >::Cons(), and TableauDyn< T >::mCard.

Referenced by Partie::AjouterPartie(), BdD::AjouterUtilisateur(), ServeurPrincipal::AttendreClient(), and BdD::Charger().

00204                                                                 {
00205         Cons(val,mCard);
00206         return (*this);
00207 }

Here is the call graph for this function:

template<class T>
void TableauDyn< T >::Modifier ( int  pos,
elt 
)

Modification de l'élément en pos par T.

Parameters:
pos Indice de l'élément à modifier
elt Nouvel élément

Definition at line 209 of file TableauDyn.h.

References TableauDyn< T >::mTab.

Referenced by Partie::SetLoginF(), Partie::SetLoginPacman(), Partie::SetNbFantomeAuto(), BdD::SetScore(), Partie::SetScoreF(), and Partie::SetScorePacman().

00209                                                             {
00210         mTab[pos]=elt;
00211 }

template<class T>
void TableauDyn< T >::SetTaille ( unsigned int  nb  ) 

Définir la taille du tableau (si connue)
Evite les réalocations multiples.

Parameters:
nb Taille du tableau

Definition at line 213 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00213                                                               {
00214         delete[] mTab;
00215         mCard=nb;
00216         mTab=new T [nb];
00217 }

template<class T>
TableauDyn< T > & TableauDyn< T >::Detruit ( unsigned int  i  ) 

Destruction de l'élément i.

Parameters:
i Elément à détruire
Returns:
Le nouveau tableau (pour l'appel récursif au besoin)

Definition at line 225 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

Referenced by Partie::SupprimerPartie(), and BdD::SupprimerUtilisateur().

00225                                                                         {
00226         T *tab=new T[mCard-1];
00227         //on recopie tout sauf pos
00228         int k=0;
00229         for(int i=0; i<mCard; i++){
00230                 if(i!=pos){
00231                         tab[k]=mTab[i];
00232                         k++;
00233                 }
00234         }
00235         //on supprime mTab
00236         delete[] mTab;
00237         mTab=new T[mCard-1];
00238         for(int i=0; i<mCard-1; i++){
00239                 mTab[i]=tab[i];
00240         }
00241         //on supprime tab
00242         delete[] tab;
00243         if(mCard>0) mCard--;
00244         return (*this);
00245 }

template<class T>
TableauDyn< T > & TableauDyn< T >::DetruitVirtuel ( unsigned int  pos  ) 

Destruction virtuel, ne fait que décrémenter le cardinal du tableau
A n'utiliser qu'en des cas très précis !.

Parameters:
pos 
Returns:
Le nouveau tableau (pour l'appel récursif au besoin)

Definition at line 220 of file TableauDyn.h.

References TableauDyn< T >::mCard.

00220                                                                                {
00221         mCard--;
00222         return (*this);
00223 }

template<class T>
unsigned int TableauDyn< T >::Card (  )  const

Retourne le nombre d'élément du tableau.

Returns:
Cardinal du tableau

Definition at line 247 of file TableauDyn.h.

References TableauDyn< T >::mCard.

Referenced by Partie::Afficher(), BdD::Afficher(), BdD::ListeScore(), TableauDyn< T >::operator=(), Partie::Rechercher(), BdD::Rechercher(), BdD::Sauvegarder(), TableauDyn< T >::TableauDyn(), and Partie::ToString().

00247                                                         {
00248         return mCard;
00249 }

template<class T>
T TableauDyn< T >::Tete (  )  const

Accéder à la tête de la liste.

Returns:
Tête de liste

Definition at line 250 of file TableauDyn.h.

References TableauDyn< T >::mTab.

00250                                              {
00251         return mTab[0];
00252 }

template<class T>
T TableauDyn< T >::Valeur ( int  i  )  const

Accesseur de la ième valeur.

Parameters:
i Valeur à retourner
Returns:
Iième valeur

Definition at line 253 of file TableauDyn.h.

References TableauDyn< T >::mTab.

00253                                                     {
00254         return mTab[i];
00255 }

template<class T>
T TableauDyn< T >::operator[] ( int  i  )  const

Surcharge de [].

Parameters:
i Valeur à retourner
Returns:
Iième valeur

Definition at line 256 of file TableauDyn.h.

References TableauDyn< T >::mTab.

00256                                                         {
00257         return mTab[i];
00258 }

template<class T>
void TableauDyn< T >::Afficher (  )  const

Affichage du tableau.

Definition at line 259 of file TableauDyn.h.

References TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00259                                                     {
00260         for(int i=0; i<mCard; i++){
00261                 cout<<mTab[i]<<" ";
00262         }
00263 }

template<class T>
const TableauDyn< T > & TableauDyn< T >::operator= ( const TableauDyn< T > &  l  ) 

Surcharge de =.

Parameters:
l Tableau de base
Returns:
Le nouveau tableau (pour l'appel récursif au besoin)

Definition at line 265 of file TableauDyn.h.

References TableauDyn< T >::Card(), TableauDyn< T >::mCard, and TableauDyn< T >::mTab.

00265                                                                                      {
00266         delete [] mTab;
00267         mCard=l.Card();
00268         mTab=new T [mCard];
00269         for(unsigned int i=0; i<l.Card(); i++){
00270                 mTab[i]=l[i];
00271         }
00272         return (*this);
00273 }

Here is the call graph for this function:


Member Data Documentation

template<class T>
T* TableauDyn< T >::mTab [protected]

Tableau dynamique.

Definition at line 136 of file TableauDyn.h.

Referenced by TableauDyn< T >::Afficher(), TableauDyn< T >::Cons(), TableauDyn< T >::Detruit(), TableauDyn< T >::Modifier(), TableauDyn< T >::operator=(), TableauDyn< T >::operator[](), TableauDyn< T >::SetTaille(), TableauDyn< T >::TableauDyn(), TableauDyn< T >::Tete(), TableauDyn< T >::Valeur(), and TableauDyn< T >::~TableauDyn().

template<class T>
int TableauDyn< T >::mCard [protected]

Nombre de valeurs alloués.

Definition at line 141 of file TableauDyn.h.

Referenced by TableauDyn< T >::Afficher(), TableauDyn< T >::Card(), TableauDyn< T >::Cons(), TableauDyn< T >::ConsQueue(), TableauDyn< T >::Detruit(), TableauDyn< T >::DetruitVirtuel(), TableauDyn< T >::operator=(), TableauDyn< T >::SetTaille(), TableauDyn< T >::TableauDyn(), and TableauDyn< T >::~TableauDyn().


The documentation for this class was generated from the following file:
Generated on Wed Jan 2 14:02:15 2008 for Pacman by  doxygen 1.5.1