summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/log
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/log')
-rw-r--r--2005/i/robert/src/log/Makefile.defs6
-rw-r--r--2005/i/robert/src/log/log.cc120
-rw-r--r--2005/i/robert/src/log/log.hh70
-rw-r--r--2005/i/robert/src/log/log_message.cc74
-rw-r--r--2005/i/robert/src/log/log_message.hh52
-rw-r--r--2005/i/robert/src/log/log_message.tcc36
-rw-r--r--2005/i/robert/src/log/test_log.cc34
7 files changed, 392 insertions, 0 deletions
diff --git a/2005/i/robert/src/log/Makefile.defs b/2005/i/robert/src/log/Makefile.defs
new file mode 100644
index 0000000..b895d5c
--- /dev/null
+++ b/2005/i/robert/src/log/Makefile.defs
@@ -0,0 +1,6 @@
+PROGRAMS += test_log
+
+test_log_OBJECTS = \
+ test_log.o log.o log_message.o
+
+test_log: $(test_log_OBJECTS)
diff --git a/2005/i/robert/src/log/log.cc b/2005/i/robert/src/log/log.cc
new file mode 100644
index 0000000..7f65efa
--- /dev/null
+++ b/2005/i/robert/src/log/log.cc
@@ -0,0 +1,120 @@
+// log.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "log.hh"
+
+/// Constructeur.
+Log::Log (const char *module)
+ : module_ (module), instance_ (0)
+{
+}
+
+/// Constructeur.
+Log::Log (const char *module, const char *instance)
+ : module_ (module), instance_ (instance)
+{
+}
+
+/// Crée un nouveau LogMessage.
+LogMessage
+Log::operator() (const char *msg, Level level/*info*/) const
+{
+ return LogMessage (*this, msg, level);
+}
+
+/// Traduit le niveau de log.
+void
+Log::toString (Level level, std::string &s)
+{
+ switch (level)
+ {
+ case none:
+ s = "none"; break;
+ case fatal:
+ s = "fatal"; break;
+ case error:
+ s = "error"; break;
+ case warning:
+ s = "warning"; break;
+ case info:
+ s = "info"; break;
+ case debug:
+ s = "debug"; break;
+ case verydebug:
+ s = "verydebug"; break;
+ default:
+ s = "logunknown"; break;
+ }
+}
+
+/// Traduit le niveau de log.
+Log::Level
+Log::toLevel (const std::string &level)
+{
+ switch (level[0])
+ {
+ case 'n':
+ return none;
+ case 'f':
+ return fatal;
+ case 'e':
+ return error;
+ case 'w':
+ return warning;
+ case 'i':
+ return info;
+ case 'd':
+ return debug;
+ case 'v':
+ return verydebug;
+ default:
+ return levelReserved;
+ }
+}
+
+/// Traduit le masque de niveau de log.
+Log::Level
+Log::toLevelMask (const std::string &level)
+{
+ switch (level[0])
+ {
+ case 'n':
+ return static_cast<Level> (none);
+ case 'f':
+ return static_cast<Level> (fatal);
+ case 'e':
+ return static_cast<Level> (error | fatal);
+ case 'w':
+ return static_cast<Level> (warning | error | fatal);
+ case 'i':
+ return static_cast<Level> (info | warning | error | fatal);
+ case 'd':
+ return static_cast<Level> (debug | info | warning | error | fatal);
+ case 'v':
+ return static_cast<Level> (verydebug | debug | info | warning | error | fatal);
+ default:
+ return toLevel (level);
+ }
+}
+
diff --git a/2005/i/robert/src/log/log.hh b/2005/i/robert/src/log/log.hh
new file mode 100644
index 0000000..026b1f0
--- /dev/null
+++ b/2005/i/robert/src/log/log.hh
@@ -0,0 +1,70 @@
+#ifndef log_hh
+#define log_hh
+// log.h
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include <string>
+
+class LogMessage;
+
+/// Classe de log. Permet de construire des LogMessage.
+class Log
+{
+ public:
+ enum Level
+ {
+ none = 0x00,
+ fatal = 0x01,
+ error = 0x02,
+ warning = 0x04,
+ info = 0x08,
+ debug = 0x10,
+ verydebug = 0x20,
+ levelReserved = 0xffff
+ };
+ private:
+ const char *module_;
+ const char *instance_;
+ public:
+ /// Constructeur.
+ Log (const char *module);
+ /// Constructeur.
+ Log (const char *module, const char *instance);
+ /// Crée un nouveau LogMessage.
+ LogMessage operator() (const char *msg, Level level = info) const;
+ /// Récupère le module.
+ const char *getModule (void) const { return module_; }
+ /// Récupère l'instance.
+ const char *getInstance (void) const { return instance_; }
+ /// Traduit le niveau de log.
+ static void toString (Level level, std::string &s);
+ /// Traduit le niveau de log.
+ static Level toLevel (const std::string &level);
+ /// Traduit le masque de niveau de log.
+ static Level toLevelMask (const std::string &level);
+};
+
+#include "log_message.hh"
+
+#endif // log_hh
diff --git a/2005/i/robert/src/log/log_message.cc b/2005/i/robert/src/log/log_message.cc
new file mode 100644
index 0000000..68568c1
--- /dev/null
+++ b/2005/i/robert/src/log/log_message.cc
@@ -0,0 +1,74 @@
+// log_message.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "log_message.hh"
+
+#include <iostream>
+
+/// Constructeur.
+LogMessage::LogMessage (const Log &log, const char *msg, Log::Level level)
+{
+ std::cout << log.getModule () << ':';
+ if (log.getInstance ())
+ std::cout << ' ' << log.getInstance () << ':';
+}
+
+/// Destructeur.
+LogMessage::~LogMessage (void)
+{
+ std::cout << std::endl;
+}
+
+/// Output a string or a variable name.
+LogMessage &
+LogMessage::operator<< (const char *s)
+{
+ std::cout << ' ' << s;
+ return *this;
+}
+
+/// Output a string or a variable name.
+LogMessage &
+LogMessage::operator<< (const std::string &s)
+{
+ std::cout << ' ' << s;
+ return *this;
+}
+
+/// Output a integer.
+LogMessage &
+LogMessage::operator<< (int i)
+{
+ std::cout << ' ' << i;
+ return *this;
+}
+
+/// Output a double.
+LogMessage &
+LogMessage::operator<< (double d)
+{
+ std::cout << ' ' << d;
+ return *this;
+}
+
diff --git a/2005/i/robert/src/log/log_message.hh b/2005/i/robert/src/log/log_message.hh
new file mode 100644
index 0000000..e5a9e20
--- /dev/null
+++ b/2005/i/robert/src/log/log_message.hh
@@ -0,0 +1,52 @@
+#ifndef log_message_hh
+#define log_message_hh
+// log_message.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include "log.hh"
+
+class LogMessage
+{
+ public:
+ /// Constructeur.
+ LogMessage (const Log &log, const char *msg, Log::Level level);
+ /// Destructeur.
+ ~LogMessage (void);
+ /// Output a string or a variable name.
+ LogMessage &operator<< (const char *s);
+ /// Output a string or a variable name.
+ LogMessage &operator<< (const std::string &s);
+ /// Output a integer.
+ LogMessage &operator<< (int i);
+ /// Output a double.
+ LogMessage &operator<< (double d);
+ /// Output a OutputStreamable as a string.
+ template<typename OutputStreamable>
+ LogMessage &operator<< (const OutputStreamable &o);
+};
+
+#include "log_message.tcc"
+
+#endif // log_message_hh
diff --git a/2005/i/robert/src/log/log_message.tcc b/2005/i/robert/src/log/log_message.tcc
new file mode 100644
index 0000000..ecf4970
--- /dev/null
+++ b/2005/i/robert/src/log/log_message.tcc
@@ -0,0 +1,36 @@
+// log_message.tcc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include <iostream>
+
+/// Output a OutputStreamable as a string.
+template<typename OutputStreamable>
+LogMessage &
+LogMessage::operator<< (const OutputStreamable &o)
+{
+ std::cout << o;
+ return *this;
+}
+
diff --git a/2005/i/robert/src/log/test_log.cc b/2005/i/robert/src/log/test_log.cc
new file mode 100644
index 0000000..0cd7d42
--- /dev/null
+++ b/2005/i/robert/src/log/test_log.cc
@@ -0,0 +1,34 @@
+// test_log.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "log.hh"
+
+int
+main (void)
+{
+ Log log ("main");
+ log ("foo") << "bar" << 4 << "foobar" << 5.6;
+ log ("bar", Log::error) << "foo" << 5;
+ return 0;
+}