reseau_cellule_etats.h 2.51 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
20
    friend class RegleVoisinage;
    friend class RegleVoisinageNeumann;
    friend class RegleVoisinageMoore;

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

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

public:
38
39
    std::string getLabel(){return label;}
    QColor getColor(){return color;}
40
    unsigned int getIndice() { return indice; }
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
};


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];
    struct Handler {
        EnsembleEtat* instance=nullptr;
        ~Handler() { delete instance; }
    };
    static Handler handler;
    friend struct Handler;
    EnsembleEtat();
    ~EnsembleEtat();
    EnsembleEtat(const EnsembleEtat&) = delete;
    EnsembleEtat operator=(const EnsembleEtat&) = delete;

public:
61
    void ajouterEtat(unsigned int ind, std::string lab,int r = 0, int g = 0, int b = 0);
62
63
64
65
    void supprimerEtat(const unsigned int ind);
    static EnsembleEtat& getInstance();
    static void libererInstance();
    void initEtat(const Etat* init_etats = nullptr);//initialisation du tableau d'Etats à partir d'un tableau externe
66
67
    Etat& getEtat(const unsigned int &ind){return *ensEtats[ind];}
    unsigned int getNbEtats() const {return nbEtats;};
68
69
70
71
72
73
74
75
76
};

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

public:
77
78
79
80
    int getLargeur() const {return largeur;};
    int getHauteur() const {return hauteur;};
    Reseau& setAleatoire();
    Cellule** getReseau() const {return reseau;};
81
    Reseau(const unsigned int &h, const unsigned int &l);
82
    Reseau(const Reseau&);
83
84
85
    ~Reseau();
    void affiche();
};