summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/vision/size_thresholds.cc
blob: 3a65d4c6a44a41218e206cbaa93fd5bcd8cf7185 (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
// 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 <stdio.h>

// 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;
      }
}