reseau_cellule_etats.h 2.32 KB
Newer Older
1
2
3
#pragma once
#include <iostream>
#include <array>
4
#include <QColor>
5
6

using namespace std;
7
8
9
10
11
12
13
14
15
16

class Cellule{
private:
    unsigned int indEtat;
    unsigned int abs;
    unsigned int ord;
    Cellule();
    //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;
Maxime Goret's avatar
Maxime Goret committed
17
18
19
    friend class RegleVoisinage;
    friend class RegleVoisinageNeumann;
    friend class RegleVoisinageMoore;
Boris Cazic's avatar
Boris Cazic committed
20
    friend class RegleVoisinageArbitraire;
Maxime Goret's avatar
Maxime Goret committed
21

22
23
public:
    inline unsigned int getIndEtat() const {return indEtat;}
24
    void incrementerEtat();
25
26
27
28
29
30
};

class Etat{
private:
    unsigned int indice;
    std::string label;
31
    QColor color;
32
    Etat(unsigned int ind, std::string lab, int r = 0, int g = 0, int b = 0):
Boris Cazic's avatar
Boris Cazic committed
33
    indice(ind),label(lab),color(r,g,b){}
34
    Etat(unsigned int ind, std::string lab, QColor col):
Boris Cazic's avatar
Boris Cazic committed
35
    indice(ind),label(lab),color(col){} //constructeur privé (l'utilisateur ne doit pas pouvoir créer un Etat par ce biais)
36
37
38
    friend class EnsembleEtat;

public:
39
40
    std::string getLabel(){return label;}
    QColor getColor(){return color;}
41
	unsigned int getIndice() const { return indice; }
42
43
44
45
46
47
48
49
50
51
52
53
};


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:
54
55
    EnsembleEtat();
    ~EnsembleEtat();
56
    void ajouterEtat(unsigned int ind, std::string lab,int r = 0, int g = 0, int b = 0);
57
58
    void supprimerEtat(const unsigned int ind);
    void initEtat(const Etat* init_etats = nullptr);//initialisation du tableau d'Etats à partir d'un tableau externe
59
60
    Etat& getEtat(const unsigned int &ind){return *ensEtats[ind];}
    unsigned int getNbEtats() const {return nbEtats;};
61
    void reset();
62
63
64
65
66
67
68
69
70
};

class Reseau{
private:
    unsigned int hauteur;
    unsigned int largeur;
    Cellule** reseau;

public:
71
72
73
74
    int getLargeur() const {return largeur;};
    int getHauteur() const {return hauteur;};
    Reseau& setAleatoire();
    Cellule** getReseau() const {return reseau;};
75
    Reseau(const unsigned int &h, const unsigned int &l);
76
    Reseau(const Reseau&);
77
78
    ~Reseau();
};