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