summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/config/config.cc
diff options
context:
space:
mode:
authorschodet2003-05-26 08:58:16 +0000
committerschodet2003-05-26 08:58:16 +0000
commit1f76a63936157c455356760b6288dbe8e4a10579 (patch)
treeb1a827d6a6e1c04885b28c4243ea5789e0aa2122 /2003/i/buzz/src/config/config.cc
parent349546cd507e0a1d3259c7a92aa2c89bb36736e0 (diff)
Ajout de config
Diffstat (limited to '2003/i/buzz/src/config/config.cc')
-rw-r--r--2003/i/buzz/src/config/config.cc97
1 files changed, 97 insertions, 0 deletions
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 <cstring>
+
+// 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");
+}