Skip to content
Snippets Groups Projects
Commit 867ab833 authored by Yann Boucher's avatar Yann Boucher
Browse files

Implémentation de la fonction retournant une structure à partir d'un Grid : Fixed #36

parent 270164c5
No related branches found
No related tags found
No related merge requests found
Pipeline #77933 passed
...@@ -21,6 +21,8 @@ using namespace std; ...@@ -21,6 +21,8 @@ using namespace std;
// TODO : documenter // TODO : documenter
class Structure;
class Grid{ class Grid{
int nb_rows; int nb_rows;
int nb_col; int nb_col;
...@@ -43,6 +45,9 @@ public: ...@@ -43,6 +45,9 @@ public:
+((j%nb_col+nb_col)%nb_col)]; +((j%nb_col+nb_col)%nb_col)];
} }
Grid& operator=(const Grid& g); Grid& operator=(const Grid& g);
//! \brief Retourne une structure représentant le contenu non-nul de la Grid (les cellules d'état != 0), pour un enregistrement dans un fichier par exemple.
Structure to_structure() const;
}; };
ostream& operator<<(ostream& f, const Grid& g); ostream& operator<<(ostream& f, const Grid& g);
......
...@@ -11,6 +11,8 @@ Cette classe représente un réseau de cellules. ...@@ -11,6 +11,8 @@ Cette classe représente un réseau de cellules.
#include "grid.h" #include "grid.h"
#include "structure.hpp"
Grid::Grid(size_t l,size_t c):nb_rows(l),nb_col(c){ Grid::Grid(size_t l,size_t c):nb_rows(l),nb_col(c){
this->matrix.resize(l*c); this->matrix.resize(l*c);
} }
...@@ -41,3 +43,14 @@ Grid& Grid::operator=(const Grid& g){ ...@@ -41,3 +43,14 @@ Grid& Grid::operator=(const Grid& g){
this->matrix = g.matrix; this->matrix = g.matrix;
return *this; return *this;
} }
Structure Grid::to_structure() const
{
std::vector<std::pair<Coord, unsigned>> data;
for (size_t i = 0; i < get_rows(); ++i)
for (size_t j = 0; j < get_col(); ++j)
data.push_back(std::make_pair(Coord{(int)j, (int)i}, get_state(i, j)));
return Structure{data.begin(), data.end()};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment