Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Romain De Laage De Bellefaye
LO21-projet
Commits
b61ed35a
Verified
Commit
b61ed35a
authored
Jun 12, 2021
by
Romain De Laage De Bellefaye
🌳
Browse files
Doc réseau, cellule et état
parent
c87c1566
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/reseau_cellule_etats.h
View file @
b61ed35a
...
...
@@ -5,77 +5,118 @@
using
namespace
std
;
/// Classe représentant la cellule
class
Cellule
{
private:
unsigned
int
indEtat
;
unsigned
int
abs
;
unsigned
int
ord
;
//inline Cellule():indEtat(0), abs(0), ord(0){};
void
initCellule
(
const
unsigned
int
ind
,
const
unsigned
int
&
x
,
const
unsigned
int
&
y
);
friend
class
Reseau
;
friend
class
RegleVoisinage
;
friend
class
RegleVoisinageNeumann
;
friend
class
RegleVoisinageMoore
;
friend
class
RegleVoisinageArbitraire
;
private:
unsigned
int
indEtat
;
unsigned
int
abs
;
unsigned
int
ord
;
//inline Cellule():indEtat(0), abs(0), ord(0){};
void
initCellule
(
const
unsigned
int
ind
,
const
unsigned
int
&
x
,
const
unsigned
int
&
y
);
friend
class
Reseau
;
friend
class
RegleVoisinage
;
friend
class
RegleVoisinageNeumann
;
friend
class
RegleVoisinageMoore
;
friend
class
RegleVoisinageArbitraire
;
public:
inline
unsigned
int
getIndEtat
()
const
{
return
indEtat
;}
void
incrementerEtat
();
Cellule
();
Cellule
(
const
Cellule
&
c
)
:
indEtat
(
c
.
indEtat
),
abs
(
c
.
abs
),
ord
(
c
.
ord
)
{}
public:
/// Obtenir l'indice de l'état correspondant à cette cellule
inline
unsigned
int
getIndEtat
()
const
{
return
indEtat
;}
/// Incrémenter l'état de la cellule
///
/// Retourne à 0 quand on a atteint l'état maximal
void
incrementerEtat
();
/// Construire une cellule
Cellule
();
/// Construire une cellule par recopie
Cellule
(
const
Cellule
&
c
)
:
indEtat
(
c
.
indEtat
),
abs
(
c
.
abs
),
ord
(
c
.
ord
)
{}
};
/// Classe représentant un état
class
Etat
{
private:
unsigned
int
indice
;
std
::
string
label
;
QColor
color
;
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
int
r
=
0
,
int
g
=
0
,
int
b
=
0
)
:
indice
(
ind
),
label
(
lab
),
color
(
r
,
g
,
b
){}
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
QColor
col
)
:
indice
(
ind
),
label
(
lab
),
color
(
col
){}
//constructeur privé (l'utilisateur ne doit pas pouvoir créer un Etat par ce biais)
friend
class
EnsembleEtat
;
private:
unsigned
int
indice
;
std
::
string
label
;
QColor
color
;
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
int
r
=
0
,
int
g
=
0
,
int
b
=
0
)
:
indice
(
ind
),
label
(
lab
),
color
(
r
,
g
,
b
){}
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
QColor
col
)
:
indice
(
ind
),
label
(
lab
),
color
(
col
){}
//constructeur privé (l'utilisateur ne doit pas pouvoir créer un Etat par ce biais)
friend
class
EnsembleEtat
;
public:
std
::
string
getLabel
(){
return
label
;}
QColor
getColor
(){
return
color
;}
unsigned
int
getIndice
()
const
{
return
indice
;
}
public:
/// Obtenir le label d'un état
std
::
string
getLabel
()
const
{
return
label
;
}
/// Obtenir la couleur d'un état
QColor
getColor
()
const
{
return
color
;
}
/// Obtenir l'indice correspondant à un état
unsigned
int
getIndice
()
const
{
return
indice
;
}
};
/// Regroupement cohérent d'états
class
EnsembleEtat
{
private:
size_t
nbEtats
=
0
;
static
const
size_t
nbEtatsMax
=
10
;
Etat
*
ensEtats
[
nbEtatsMax
];
EnsembleEtat
(
const
EnsembleEtat
&
)
=
delete
;
EnsembleEtat
operator
=
(
const
EnsembleEtat
&
)
=
delete
;
class
EnsembleEtat
{
//singleton qui regroupe l'ensemble des états
private:
//permet d'éviter que chaque cellule inclue une instance d'Etat
size_t
nbEtats
=
0
;
static
const
size_t
nbEtatsMax
=
10
;
Etat
*
ensEtats
[
nbEtatsMax
];
EnsembleEtat
(
const
EnsembleEtat
&
)
=
delete
;
EnsembleEtat
operator
=
(
const
EnsembleEtat
&
)
=
delete
;
public:
EnsembleEtat
();
~
EnsembleEtat
();
void
ajouterEtat
(
unsigned
int
ind
,
std
::
string
lab
,
int
r
=
0
,
int
g
=
0
,
int
b
=
0
);
void
supprimerEtat
(
const
unsigned
int
ind
);
void
initEtat
(
const
Etat
*
init_etats
=
nullptr
);
//initialisation du tableau d'Etats à partir d'un tableau externe
Etat
&
getEtat
(
const
unsigned
int
&
ind
){
return
*
ensEtats
[
ind
];}
unsigned
int
getNbEtats
()
const
{
return
nbEtats
;};
void
reset
();
public:
EnsembleEtat
();
~
EnsembleEtat
();
/// Ajouter un état à l'ensemble
/// @param[in] ind indice correspondant à l'état
/// @param[in] lab label correspondant à l'état
/// @param[in] r niveau de rouge de la couleur de l'état
/// @param[in] g niveau de vert de la couleur de l'état
/// @param[in] b niveau de bleu de la couleur de l'état
void
ajouterEtat
(
unsigned
int
ind
,
std
::
string
lab
,
int
r
=
0
,
int
g
=
0
,
int
b
=
0
);
/// Supprimer un état par son indice
/// @param[in] ind indice de l'état à supprimer
void
supprimerEtat
(
const
unsigned
int
ind
);
/// Initialisation du tableau d'Etats à partir d'un tableau externe
/// @param[in] init_etats tableau d'Etat
void
initEtat
(
const
Etat
*
init_etats
=
nullptr
);
/// obtenir une référence vers un état par son indice
/// @param[in] ind indice de l'état à obtenir
Etat
&
getEtat
(
const
unsigned
int
&
ind
)
{
return
*
ensEtats
[
ind
];
}
/// Obtenir le nombre d'état disponibles
unsigned
int
getNbEtats
()
const
{
return
nbEtats
;
}
/// Remettre à l'état vide l'ensemble
void
reset
();
};
/// Classe correspondant à un réseau d'une simulation
///
/// Un ensemble fini de cellules en 2 dimensions
class
Reseau
{
private:
unsigned
int
hauteur
;
unsigned
int
largeur
;
Cellule
**
reseau
;
private:
unsigned
int
hauteur
;
unsigned
int
largeur
;
Cellule
**
reseau
;
public:
int
getLargeur
()
const
{
return
largeur
;};
int
getHauteur
()
const
{
return
hauteur
;};
Reseau
&
setAleatoire
();
Cellule
**
getReseau
()
const
{
return
reseau
;};
Reseau
(
const
unsigned
int
&
h
,
const
unsigned
int
&
l
);
Reseau
(
const
Reseau
&
);
~
Reseau
();
Reseau
&
operator
=
(
const
Reseau
&
r
);
bool
operator
==
(
const
Reseau
&
r
);
public:
/// Obtenir la largeur du réseau
int
getLargeur
()
const
{
return
largeur
;
}
/// Obtenir la hauteur du réseau
int
getHauteur
()
const
{
return
hauteur
;
}
/// Remplir aléatoirement un réseau
Reseau
&
setAleatoire
();
/// Obtenir le tableau de cellules du réseau
Cellule
**
getReseau
()
const
{
return
reseau
;
}
/// Construire un réseau
/// @param[in] h Hauteur du réseau
/// @param[in] l Largeur du réseau
Reseau
(
const
unsigned
int
&
h
,
const
unsigned
int
&
l
);
/// Construire un réseau par recopie d'un autre
/// @param[in] r Réseau à recopier
Reseau
(
const
Reseau
&
r
);
~
Reseau
();
/// copier un réseau dans un autre existant
/// @param[in] r Réseau à recopier
Reseau
&
operator
=
(
const
Reseau
&
r
);
/// Comparer deux réseaux pour vérifier une égalité
/// @param[in] r Réseau à comparer
bool
operator
==
(
const
Reseau
&
r
);
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment