From 1f76a63936157c455356760b6288dbe8e4a10579 Mon Sep 17 00:00:00 2001 From: schodet Date: Mon, 26 May 2003 08:58:16 +0000 Subject: Ajout de config --- 2003/i/buzz/src/config/config.cc | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 2003/i/buzz/src/config/config.cc (limited to '2003/i/buzz/src/config/config.cc') diff --git a/2003/i/buzz/src/config/config.cc b/2003/i/buzz/src/config/config.cc new file mode 100644 index 0000000..3e764ae --- /dev/null +++ b/2003/i/buzz/src/config/config.cc @@ -0,0 +1,97 @@ +// config.cc +// buzz - Programme du robot Efrei Robotique I1-I2 2003 +// Copyright (C) 2003 Nicolas Schodet +// +#include "config.h" +#include "config_lex.h" +#include "erreur/erreur.h" + +#include + +// Constructeur. +Config::Config (const char *filename) +{ + m_filename = filename; + config_yyopen (filename); + m_type = -1; +} + +// Destructeur. +Config::~Config (void) +{ + config_yyclose (); +} + +// Attend un token, sinon, jette une exception. +int +Config::getNum (void) +{ + if (m_type == -1) m_type = config_yylex (); + if (m_type != NUM) + throw ErreurConfig (m_filename, "Nombre attendu.\n"); + m_type = -1; + return config_yylval.num; +} + +const char * +Config::getId (void) +{ + if (m_type == -1) m_type = config_yylex (); + if (m_type != ID) + throw ErreurConfig (m_filename, "Identificateur attendu.\n"); + m_type = -1; + return config_yylval.id; +} + +bool +Config::getBool (void) +{ + if (m_type == -1) m_type = config_yylex (); + if (m_type != BOOL) + throw ErreurConfig (m_filename, "Booléen attendu.\n"); + m_type = -1; + return config_yylval.boolean; +} + +double +Config::getFloat (void) +{ + if (m_type == -1) m_type = config_yylex (); + if (m_type != FLOAT) + throw ErreurConfig (m_filename, "Flotant attendu.\n"); + m_type = -1; + return config_yylval.fl; +} + +void +Config::getEof (void) +{ + if (m_type == -1) m_type = config_yylex (); + if (m_type) + throw ErreurConfig (m_filename, "Fin de fichier attendue.\n"); +} + +// Retourne true si à la fin du fichier. +bool +Config::eof (void) +{ + if (m_type == -1) m_type = config_yylex (); + return m_type == 0; +} + +// Vérifie si le prochain token est... +bool +Config::isId (const char *s) +{ + if (m_type == -1) m_type = config_yylex (); + if (m_type != ID) + throw ErreurConfig (m_filename, "Identificateur attendu.\n"); + return strcmp (config_yylval.id, s) == 0; +} + +// Lance une erreur, on a pas trouvé ce qu'on voulais. +void +Config::noId (void) +{ + throw ErreurConfig (m_filename, "Identificateur inconnu.\n"); +} -- cgit v1.2.3