// size_thresholds.cc - Chargement de seuils de taille de palets. // buzz - Programme du robot Efrei Robotique I1-I2 2003 // Copyright (C) 2003 Nicolas Schodet #include "size_thresholds.h" #include // Constructeur. SizeThresholds::SizeThresholds (const char *filename) { FILE *fp; SizeThreshold **pt; int n; int type, wm, wM, hm, hM; // Ouvre le fichier. fp = fopen (filename, "r"); if (!fp) throw "SizeThresholds::SizeThresholds: fopen failled"; // Charge chaque lignes. pt = &m_thresholds; while (!feof (fp)) { n = fscanf (fp, "%d %d %d %d %d\n", &type, &wm, &wM, &hm, &hM); if (n != 5) { fclose (fp); throw "SizeThresholds::SizeThresholds: Bad format."; } // Ajoute un nouveaux seuil a la collection. *pt = new SizeThreshold; (*pt)->type = type; (*pt)->wm = wm; (*pt)->wM = wM; (*pt)->hm = hm; (*pt)->hM = hM; pt = &(*pt)->next; } // Ferme la liste de seuils. *pt = 0; // Ferme le fichier. fclose (fp); } // Destructeur. SizeThresholds::~SizeThresholds (void) { SizeThreshold *p, *p2; for (p = m_thresholds; p; p = p2) { p2 = p->next; delete p; } }