summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/vision/thresholds.cc
blob: 23c37e5e8f1562e47d92781d66a6d7373b5fbc9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Classe Thresholds - Chargement de seuils
// buzz - Programme du robot Efrei Robotique I1-I2 2003
// Copyright (C) 2003 Nicolas Schodet
#include "thresholds.h"

#include <stdio.h>

// Constructeur.
Thresholds::Thresholds (const char *filename)
{
    FILE *fp;
    Threshold **pt;
    int n;
    int zone, ym, yM, um, uM, vm, vM;
    // Ouvre le fichier.
    fp = fopen (filename, "r");
    if (!fp) throw "Thresholds::Thresholds: fopen failled";
    // Charge chaque lignes.
    pt = &m_thresholds;
    while (!feof (fp))
      {
	n = fscanf (fp, "%d %d %d %d %d %d %d\n", &zone, &ym, &yM, &um,
		    &uM, &vm, &vM);
	if (n != 7) 
	  {
	    fclose (fp);
	    throw "Thresholds::Thresholds: Bad format.";
	  }
	// Ajoute un nouveaux seuil a la collection.
	*pt = new Threshold;
	(*pt)->zone = zone;
	(*pt)->ym = ym;
	(*pt)->yM = yM;
	(*pt)->um = um;
	(*pt)->uM = uM;
	(*pt)->vm = vm;
	(*pt)->vM = vM;
	pt = &(*pt)->next;
      }
    // Ferme la liste de seuils.
    *pt = 0;
    // Ferme le fichier.
    fclose (fp);
}

// Destructeur.
Thresholds::~Thresholds (void)
{
    Threshold *p, *p2;
    for (p = m_thresholds; p; p = p2)
      {
	p2 = p->next;
	delete p;
      }
}