summaryrefslogtreecommitdiff
path: root/2005/i/robert
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert')
-rw-r--r--2005/i/robert/build/Makefile2
-rw-r--r--2005/i/robert/src/Makefile.defs29
-rw-r--r--2005/i/robert/src/README1
-rw-r--r--2005/i/robert/src/geometry/vector.hh67
-rw-r--r--2005/i/robert/src/geometry/vector.tcc163
-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
-rw-r--r--2005/i/robert/src/scheduler/Makefile.defs6
-rw-r--r--2005/i/robert/src/scheduler/schedulable.hh49
-rw-r--r--2005/i/robert/src/scheduler/schedulable_alarm.cc56
-rw-r--r--2005/i/robert/src/scheduler/schedulable_alarm.hh53
-rw-r--r--2005/i/robert/src/scheduler/schedulable_read_fd.cc51
-rw-r--r--2005/i/robert/src/scheduler/schedulable_read_fd.hh52
-rw-r--r--2005/i/robert/src/scheduler/scheduler.cc96
-rw-r--r--2005/i/robert/src/scheduler/scheduler.hh53
-rw-r--r--2005/i/robert/src/scheduler/test_scheduler.cc68
-rw-r--r--2005/i/robert/src/utils/Makefile.defs13
-rw-r--r--2005/i/robert/src/utils/any.hh106
-rw-r--r--2005/i/robert/src/utils/any.tcc158
-rw-r--r--2005/i/robert/src/utils/bind.hh55
-rw-r--r--2005/i/robert/src/utils/callback.hh79
-rw-r--r--2005/i/robert/src/utils/callback.tcc126
-rw-r--r--2005/i/robert/src/utils/fd_set.hh51
-rw-r--r--2005/i/robert/src/utils/meta/Makefile.defs5
-rw-r--r--2005/i/robert/src/utils/meta/is_string.hh45
-rw-r--r--2005/i/robert/src/utils/meta/test_is_string.cc35
-rw-r--r--2005/i/robert/src/utils/test_any.cc48
-rw-r--r--2005/i/robert/src/utils/test_bind.cc45
-rw-r--r--2005/i/robert/src/utils/test_callback.cc84
34 files changed, 1988 insertions, 0 deletions
diff --git a/2005/i/robert/build/Makefile b/2005/i/robert/build/Makefile
new file mode 100644
index 0000000..0ab6550
--- /dev/null
+++ b/2005/i/robert/build/Makefile
@@ -0,0 +1,2 @@
+SRCDIR = ../src
+include $(SRCDIR)/Makefile.defs
diff --git a/2005/i/robert/src/Makefile.defs b/2005/i/robert/src/Makefile.defs
new file mode 100644
index 0000000..6b69819
--- /dev/null
+++ b/2005/i/robert/src/Makefile.defs
@@ -0,0 +1,29 @@
+CXXFLAGS = -O2 -Wall -g
+CPPFLAGS = -MMD $(INCLUDES)
+INCLUDES = -I$(SRCDIR)
+
+SUBDIRS = log scheduler utils utils/meta
+
+LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
+VPATH = $(SUBDIRS:%=$(SRCDIR)/%)
+
+PROGRAMS =
+LIBS =
+
+all: build-all
+
+# Inclus les autres répertoires.
+include $(SUBDIRS:%=$(SRCDIR)/%/Makefile.defs)
+
+OBJECTS = $(filter %.o,$(foreach PROGRAM,$(PROGRAMS),$($(PROGRAM)_OBJECTS)))
+
+build-all: $(PROGRAMS)
+
+# Dépendances.
+-include $(OBJECTS:%.o=%.d)
+
+# Ménage.
+clean:
+ rm -f *.o *.d $(PROGRAMS)
+
+.PHONY: all build-all clean
diff --git a/2005/i/robert/src/README b/2005/i/robert/src/README
new file mode 100644
index 0000000..dce641a
--- /dev/null
+++ b/2005/i/robert/src/README
@@ -0,0 +1 @@
+robert - programme du robot 2005.
diff --git a/2005/i/robert/src/geometry/vector.hh b/2005/i/robert/src/geometry/vector.hh
new file mode 100644
index 0000000..a54de2a
--- /dev/null
+++ b/2005/i/robert/src/geometry/vector.hh
@@ -0,0 +1,67 @@
+#ifndef vector_hh
+#define vector_hh
+// vector.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include <cmath>
+
+namespace geometry {
+
+/// Vecteur 2d en coordonées carthésiennes.
+template<typename T>
+struct VectorT
+{
+ T x, y;
+ VectorT (void) { }
+ VectorT (T x_, T y_) { x = x_; y = y_; }
+ VectorT (T v) { x = v; y = v; }
+ VectorT (const VectorT<T> &v) { x = v.x; y = v.y; }
+ VectorT<T> &operator= (const VectorT<T> &v);
+ VectorT<T> &operator+= (const VectorT<T> &v);
+ VectorT<T> &operator-= (const VectorT<T> &v);
+ VectorT<T> &operator*= (T scalar);
+ VectorT<T> &operator/= (T scalar);
+ VectorT<T> operator+ (const VectorT<T> &v) const;
+ VectorT<T> operator- (const VectorT<T> &v) const;
+ VectorT<T> operator* (T scalar) const;
+ T operator* (const VectorT<T> &v) const;
+ VectorT<T> operator/ (T scalar) const;
+ VectorT<T> &normalize (void);
+ VectorT<T> &rotate (void);
+ VectorT<T> &rotate (T angle);
+};
+
+template<typename T>
+VectorT<T>
+operator* (T scalar, const VectorT<T> &v);
+
+template<typename T>
+std::ostream &operator<< (std::ostream &os, const VectorT<T> &v);
+
+typedef VectorT<double> Vector;
+
+} // namespace geometry
+
+#include "vector.tcc"
+
+#endif // vector_hh
diff --git a/2005/i/robert/src/geometry/vector.tcc b/2005/i/robert/src/geometry/vector.tcc
new file mode 100644
index 0000000..ddcafd2
--- /dev/null
+++ b/2005/i/robert/src/geometry/vector.tcc
@@ -0,0 +1,163 @@
+// vector.tcc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+namespace geometry {
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::operator= (const VectorT<T> &v)
+{
+ x = v.x;
+ y = v.y;
+ return *this;
+}
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::operator+= (const VectorT<T> &v)
+{
+ x += v.x;
+ y += v.y;
+ return *this;
+}
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::operator-= (const VectorT<T> &v)
+{
+ x -= v.x;
+ y -= v.y;
+ return *this;
+}
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::operator*= (T scalar)
+{
+ x *= scalar;
+ y *= scalar;
+ return *this;
+}
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::operator/= (T scalar)
+{
+ x /= scalar;
+ y /= scalar;
+ return *this;
+}
+
+template<typename T>
+VectorT<T>
+VectorT<T>::operator+ (const VectorT<T> &v) const
+{
+ VectorT<T> r (*this);
+ r += v;
+ return r;
+}
+
+template<typename T>
+VectorT<T>
+VectorT<T>::operator- (const VectorT<T> &v) const
+{
+ VectorT<T> r (*this);
+ r -= v;
+ return r;
+}
+
+template<typename T>
+VectorT<T>
+VectorT<T>::operator/ (T scalar) const
+{
+ VectorT<T> r (*this);
+ r /= scalar;
+ return r;
+}
+
+template<typename T>
+VectorT<T>
+VectorT<T>::operator* (T scalar) const
+{
+ VectorT<T> r (*this);
+ r *= scalar;
+ return r;
+}
+
+template<typename T>
+VectorT<T>
+operator* (T scalar, const VectorT<T> &v)
+{
+ VectorT<T> r (v);
+ r *= scalar;
+ return r;
+}
+
+template<typename T>
+T
+VectorT<T>::operator* (const VectorT<T> &v) const
+{
+ return x * v.x + y * v.y;
+}
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::normalize (void)
+{
+ T norm = sqrt (x * x + y * y);
+ x /= norm;
+ y /= norm;
+ return *this;
+}
+
+/// Rotate by PI/2.
+template<typename T>
+VectorT<T> &
+VectorT<T>::rotate (void)
+{
+ T tx = x;
+ x = -y;
+ y = tx;
+ return *this;
+}
+
+template<typename T>
+VectorT<T> &
+VectorT<T>::rotate (T angle)
+{
+ T tx = x;
+ T c, s;
+ sincos (angle, *s, *c);
+ x = tx * c - y * s;
+ y = tx * s + y * c;
+}
+
+template<typename T>
+std::ostream &operator<< (std::ostream &os, const VectorT<T> &v)
+{
+ os << v.x << ' ' << v.y;
+ return os;
+}
+
+} // namespace geometry
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;
+}
diff --git a/2005/i/robert/src/scheduler/Makefile.defs b/2005/i/robert/src/scheduler/Makefile.defs
new file mode 100644
index 0000000..73b5da9
--- /dev/null
+++ b/2005/i/robert/src/scheduler/Makefile.defs
@@ -0,0 +1,6 @@
+PROGRAMS += test_scheduler
+
+test_scheduler_OBJECTS = \
+ test_scheduler.o scheduler.o schedulable_read_fd.o schedulable_alarm.o
+
+test_scheduler: $(test_scheduler_OBJECTS)
diff --git a/2005/i/robert/src/scheduler/schedulable.hh b/2005/i/robert/src/scheduler/schedulable.hh
new file mode 100644
index 0000000..bfe6de3
--- /dev/null
+++ b/2005/i/robert/src/scheduler/schedulable.hh
@@ -0,0 +1,49 @@
+#ifndef schedulable_hh
+#define schedulable_hh
+// schedulable.hh
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+class FdSet;
+
+namespace scheduler {
+
+class Scheduler;
+
+/// Classe abstraite pour un objet utilisable par le Scheduler.
+class Schedulable
+{
+ public:
+ /// Destructeur.
+ virtual ~Schedulable (void) {}
+ /// Paramètre le Scheduler.
+ virtual void setup (Scheduler &scheduler, int time, FdSet &readSet, int &timeout) =
+ 0;
+ /// Appelé aprés l'attente du Scheduler, renvois true si un événement a
+ /// été traité.
+ virtual bool run (Scheduler &scheduler, int time, const FdSet &readSet) = 0;
+};
+
+} // namespace scheduler
+
+#endif // schedulable_hh
diff --git a/2005/i/robert/src/scheduler/schedulable_alarm.cc b/2005/i/robert/src/scheduler/schedulable_alarm.cc
new file mode 100644
index 0000000..c55832e
--- /dev/null
+++ b/2005/i/robert/src/scheduler/schedulable_alarm.cc
@@ -0,0 +1,56 @@
+// schedulable_alarm.cc
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "schedulable_alarm.hh"
+
+namespace scheduler {
+
+/// Paramètre le Scheduler.
+void
+SchedulableAlarm::setup (Scheduler &scheduler, int time, FdSet &readSet, int
+ &timeout)
+{
+ if (start_ != -1)
+ {
+ int to = start_ + step_ - time;
+ timeout = to > 0 ? to : 0;
+ }
+}
+
+/// Appelé aprés l'attente du Scheduler, renvois true si un événement a
+/// été traité.
+bool
+SchedulableAlarm::run (Scheduler &scheduler, int time, const FdSet &readSet)
+{
+ if (time > start_ + step_)
+ {
+ start_ = periodic_ ? start_ + step_ : -1;
+ callback_ ();
+ return true;
+ }
+ else
+ return false;
+}
+
+} // namespace scheduler
+
diff --git a/2005/i/robert/src/scheduler/schedulable_alarm.hh b/2005/i/robert/src/scheduler/schedulable_alarm.hh
new file mode 100644
index 0000000..f416d12
--- /dev/null
+++ b/2005/i/robert/src/scheduler/schedulable_alarm.hh
@@ -0,0 +1,53 @@
+#ifndef schedulable_alarm_hh
+#define schedulable_alarm_hh
+// schedulable_alarm.hh
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "schedulable.hh"
+#include "utils/callback.hh"
+
+namespace scheduler {
+
+/// Execute un callback à un instant donné.
+class SchedulableAlarm : public Schedulable
+{
+ Callback<void> callback_;
+ int start_, step_;
+ bool periodic_;
+ public:
+ /// Constructeur.
+ template<typename T>
+ SchedulableAlarm (T callback, int start, int step, bool periodic = true)
+ : callback_ (callback),
+ start_ (start), step_ (step), periodic_ (periodic)
+ { }
+ /// Paramètre le Scheduler.
+ void setup (Scheduler &scheduler, int time, FdSet &readSet, int &timeout);
+ /// Appelé aprés l'attente du Scheduler, renvois true si un événement a
+ /// été traité.
+ bool run (Scheduler &scheduler, int time, const FdSet &readSet);
+};
+
+} // namespace scheduler
+
+#endif // schedulable_alarm_hh
diff --git a/2005/i/robert/src/scheduler/schedulable_read_fd.cc b/2005/i/robert/src/scheduler/schedulable_read_fd.cc
new file mode 100644
index 0000000..3c84c9b
--- /dev/null
+++ b/2005/i/robert/src/scheduler/schedulable_read_fd.cc
@@ -0,0 +1,51 @@
+// schedulable_read_fd.cc
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "schedulable_read_fd.hh"
+#include "utils/fd_set.hh"
+
+namespace scheduler {
+
+/// Paramètre le Scheduler.
+void
+SchedulableReadFd::setup (Scheduler &scheduler, int time, FdSet &readSet, int &timeout)
+{
+ readSet.set (fd_);
+}
+
+/// Appelé aprés l'attente du Scheduler, renvois true si un événement a
+/// été traité.
+bool
+SchedulableReadFd::run (Scheduler &scheduler, int time, const FdSet &readSet)
+{
+ if (readSet.isSet (fd_))
+ {
+ callback_ ();
+ return true;
+ }
+ else
+ return false;
+}
+
+} // namespace scheduler
+
diff --git a/2005/i/robert/src/scheduler/schedulable_read_fd.hh b/2005/i/robert/src/scheduler/schedulable_read_fd.hh
new file mode 100644
index 0000000..01d7b26
--- /dev/null
+++ b/2005/i/robert/src/scheduler/schedulable_read_fd.hh
@@ -0,0 +1,52 @@
+#ifndef schedulable_read_fd_hh
+#define schedulable_read_fd_hh
+// schedulable_read_fd.hh
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "schedulable.hh"
+#include "utils/callback.hh"
+
+namespace scheduler {
+
+/// Execute un callback sur une lecture possible sur un descripteur de
+/// fichier.
+class SchedulableReadFd : public Schedulable
+{
+ Callback<void> callback_;
+ int fd_;
+ public:
+ /// Constructeur.
+ template<typename T>
+ SchedulableReadFd (T callback, int fd)
+ : callback_ (callback), fd_ (fd)
+ { }
+ /// Paramètre le Scheduler.
+ void setup (Scheduler &scheduler, int time, FdSet &readSet, int &timeout);
+ /// Appelé aprés l'attente du Scheduler, renvois true si un événement a
+ /// été traité.
+ bool run (Scheduler &scheduler, int time, const FdSet &readSet);
+};
+
+} // namespace scheduler
+
+#endif // schedulable_read_fd_hh
diff --git a/2005/i/robert/src/scheduler/scheduler.cc b/2005/i/robert/src/scheduler/scheduler.cc
new file mode 100644
index 0000000..e37504f
--- /dev/null
+++ b/2005/i/robert/src/scheduler/scheduler.cc
@@ -0,0 +1,96 @@
+// scheduler.cc
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "scheduler.hh"
+#include "utils/fd_set.hh"
+
+#include <stdlib.h> //XXX
+#include <sys/types.h>
+#include <sys/time.h>
+
+namespace scheduler {
+
+/// Destructeur.
+Scheduler::~Scheduler (void)
+{
+ // TODO: Test for schedulables_ empty ?
+}
+
+/// Ajoute un élément schedulable.
+void
+Scheduler::insert (Schedulable &schedulable)
+{
+ schedulables_.insert (&schedulable);
+}
+
+/// Enlève un élément schedulable.
+void
+Scheduler::erase (Schedulable &schedulable)
+{
+ schedulables_.erase (&schedulable);
+}
+
+/// Lance le scheduler. Si timeout est différent de -1, c'est le temps
+/// maximal que prend le scheduler avant de rendre la main. Si
+/// returnOnEvent est true, le premier évenement arrète le scheduler.
+/// Renvois true si au moins un événement a été traité.
+bool
+Scheduler::schedule (int timeout/*-1*/, bool returnOnEvent/*false*/)
+{
+ bool event = false;
+ int t = time (0) * 1000; //XXX
+ int start = t;
+ do
+ {
+ // Prépare le select.
+ int to = timeout == -1 ? -1 : start + timeout - t;
+ FdSet readFds;
+ for (Schedulables::const_iterator i = schedulables_.begin ();
+ i != schedulables_.end ();
+ ++i)
+ {
+ int top = -1;
+ (*i)->setup (*this, t, readFds, top);
+ if (to == -1 || top != -1 && top < to)
+ {
+ to = top;
+ }
+ }
+ // Select.
+ timeval tv;
+ tv.tv_sec = to / 1000;
+ tv.tv_usec = to % 1000 * 1000;
+ select (FD_SETSIZE, readFds.get (), 0, 0, &tv);
+ // Run.
+ t = time (0) * 1000; //XXX
+ for (Schedulables::const_iterator i = schedulables_.begin ();
+ i != schedulables_.end ();
+ ++i)
+ event |= (*i)->run (*this, t, readFds);
+ t = time (0) * 1000; //XXX
+ } while (!(returnOnEvent && event) && start + timeout > t); //XXX
+ return event;
+}
+
+} // namespace scheduler
+
diff --git a/2005/i/robert/src/scheduler/scheduler.hh b/2005/i/robert/src/scheduler/scheduler.hh
new file mode 100644
index 0000000..3bd885b
--- /dev/null
+++ b/2005/i/robert/src/scheduler/scheduler.hh
@@ -0,0 +1,53 @@
+#ifndef scheduler_hh
+#define scheduler_hh
+// scheduler.hh
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "schedulable.hh"
+
+#include <set>
+
+namespace scheduler {
+
+/// Scheduler, répartie le travail en fonction des événements.
+class Scheduler
+{
+ typedef std::set<Schedulable *> Schedulables;
+ Schedulables schedulables_;
+ public:
+ /// Destructeur.
+ ~Scheduler (void);
+ /// Ajoute un élément schedulable.
+ void insert (Schedulable &schedulable);
+ /// Enlève un élément schedulable.
+ void erase (Schedulable &schedulable);
+ /// Lance le scheduler. Si timeout est différent de -1, c'est le temps
+ /// maximal que prend le scheduler avant de rendre la main. Si
+ /// returnOnEvent est true, le premier évenement arrète le scheduler.
+ /// Renvois true si au moins un événement a été traité.
+ bool schedule (int timeout = -1, bool returnOnEvent = false);
+};
+
+} // namespace scheduler
+
+#endif // scheduler_hh
diff --git a/2005/i/robert/src/scheduler/test_scheduler.cc b/2005/i/robert/src/scheduler/test_scheduler.cc
new file mode 100644
index 0000000..e16ecb1
--- /dev/null
+++ b/2005/i/robert/src/scheduler/test_scheduler.cc
@@ -0,0 +1,68 @@
+// test_scheduler.cc
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "scheduler.hh"
+#include "schedulable_read_fd.hh"
+#include "schedulable_alarm.hh"
+#include "utils/bind.hh"
+
+#include <iostream>
+#include <unistd.h>
+#include <time.h>
+
+void
+ev (void)
+{
+ std::cout << "event received" << std::endl;
+ char buf[1024];
+ read (0, buf, 1024);
+}
+
+void
+to (const char *msg)
+{
+ std::cout << "timeout received " << msg << " at " << time (0) * 1000 <<
+ std::endl;
+}
+
+int
+main (void)
+{
+ using namespace scheduler;
+ try
+ {
+ Scheduler s;
+ SchedulableReadFd srf (ev, 0);
+ s.insert (srf);
+ std::cout << "start at " << time (0) * 1000 << std::endl;
+ SchedulableAlarm sa1 (utils::bind<void> (to, "3s"), time (0) * 1000, 1000);
+ s.insert (sa1);
+ s.schedule (10000);
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what () << std::endl;
+ return 1;
+ }
+ return 0;
+}
diff --git a/2005/i/robert/src/utils/Makefile.defs b/2005/i/robert/src/utils/Makefile.defs
new file mode 100644
index 0000000..a06d61c
--- /dev/null
+++ b/2005/i/robert/src/utils/Makefile.defs
@@ -0,0 +1,13 @@
+PROGRAMS += test_any test_callback test_bind
+
+test_any_OBJECTS = test_any.o
+
+test_callback_OBJECTS = test_callback.o
+
+test_bind_OBJECTS = test_bind.o
+
+test_any: $(test_any_OBJECTS)
+
+test_callback: $(test_callback_OBJECTS)
+
+test_bind: $(test_bind_OBJECTS)
diff --git a/2005/i/robert/src/utils/any.hh b/2005/i/robert/src/utils/any.hh
new file mode 100644
index 0000000..1c36875
--- /dev/null
+++ b/2005/i/robert/src/utils/any.hh
@@ -0,0 +1,106 @@
+#ifndef any_hh
+#define any_hh
+// any.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+#include <typeinfo>
+#include <exception>
+#include <iostream>
+
+/// Class containing anything.
+class any
+{
+ class AbstractHolder;
+ AbstractHolder *holder_;
+ public:
+ /// Default constructor.
+ any (void);
+ /// Constructor.
+ template<typename T>
+ any (const T &value);
+ /// Copy constructor.
+ any (const any &other);
+ /// Destructor.
+ ~any (void);
+ any &swap (any &other);
+ any &operator= (const any &other);
+ template<typename T>
+ any &operator= (const T &value);
+ bool empty (void) const;
+ const std::type_info &type (void) const;
+ private:
+ template<typename T>
+ friend T *any_cast (any *rhs);
+ friend std::ostream &operator<< (std::ostream &os, const any &rhs);
+ /// Abstract holder class.
+ class AbstractHolder
+ {
+ public:
+ /// Destructor.
+ virtual ~AbstractHolder (void);
+ virtual const std::type_info &type (void) const = 0;
+ virtual AbstractHolder *clone (void) const = 0;
+ virtual std::ostream &print (std::ostream &os) const = 0;
+ };
+ /// Holder class, templated.
+ template<typename T>
+ class Holder : public AbstractHolder
+ {
+ public:
+ T value_;
+ public:
+ Holder (const T &value);
+ virtual const std::type_info &type (void) const;
+ virtual AbstractHolder *clone (void) const;
+ virtual std::ostream &print (std::ostream &os) const;
+ };
+};
+
+class bad_any_cast : public std::bad_cast
+{
+ public:
+ virtual const char * what() const throw()
+ {
+ return "bad_any_cast: illegal conversion";
+ }
+};
+
+template<typename T>
+T *
+any_cast (any *rhs);
+
+template<typename T>
+const T *
+any_cast (const any *rhs);
+
+template<typename T>
+T
+any_cast (const any &rhs);
+
+std::ostream &
+operator<< (std::ostream &os, const any &rhs);
+
+#include "any.tcc"
+
+#endif // any_hh
diff --git a/2005/i/robert/src/utils/any.tcc b/2005/i/robert/src/utils/any.tcc
new file mode 100644
index 0000000..c7fd4a0
--- /dev/null
+++ b/2005/i/robert/src/utils/any.tcc
@@ -0,0 +1,158 @@
+// any.tcc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+#include <algorithm>
+
+/// Default constructor.
+inline
+any::any (void)
+ : holder_ (0)
+{
+}
+
+/// Constructor.
+template<typename T>
+any::any (const T &value)
+ : holder_ (new Holder<T> (value))
+{
+}
+
+/// Copy constructor.
+inline
+any::any (const any &other)
+ : holder_ (other.holder_ ? other.holder_->clone () : 0)
+{
+}
+
+/// Destructor.
+inline
+any::~any (void)
+{
+ delete holder_;
+}
+
+inline
+any &
+any::swap (any &other)
+{
+ std::swap (holder_, other.holder_);
+ return *this;
+}
+
+inline
+any &
+any::operator= (const any &other)
+{
+ any (other).swap (*this);
+ return *this;
+}
+
+template<typename T>
+any &
+any::operator= (const T &value)
+{
+ any (value).swap (*this);
+ return *this;
+}
+
+inline
+bool
+any::empty (void) const
+{
+ return !holder_;
+}
+
+inline
+const std::type_info &
+any::type (void) const
+{
+ return holder_ ? holder_->type () : typeid (void);
+}
+
+/// Destructor.
+inline
+any::AbstractHolder::~AbstractHolder (void)
+{
+}
+
+template<typename T>
+any::Holder<T>::Holder (const T &value)
+ : value_ (value)
+{
+}
+
+template<typename T>
+const std::type_info &
+any::Holder<T>::type (void) const
+{
+ return typeid (T);
+}
+
+template<typename T>
+any::AbstractHolder *
+any::Holder<T>::clone (void) const
+{
+ return new Holder (value_);
+}
+
+template<typename T>
+std::ostream &
+any::Holder<T>::print (std::ostream &os) const
+{
+ return os << value_;
+}
+
+template<typename T>
+T *
+any_cast (any *rhs)
+{
+ return rhs && rhs->type () == typeid (T)
+ ? &static_cast<any::Holder<T> *> (rhs->holder_)->value_
+ : 0;
+}
+
+template<typename T>
+const T *
+any_cast (const any *rhs)
+{
+ return any_cast<T> (const_cast<any *> (rhs));
+}
+
+template<typename T>
+T
+any_cast (const any &rhs)
+{
+ const T *value = any_cast<T> (&rhs);
+ if (!value)
+ throw bad_any_cast ();
+ return *value;
+}
+
+inline
+std::ostream &
+operator<< (std::ostream &os, const any &rhs)
+{
+ return rhs.holder_->print (os);
+}
+
diff --git a/2005/i/robert/src/utils/bind.hh b/2005/i/robert/src/utils/bind.hh
new file mode 100644
index 0000000..2a92c78
--- /dev/null
+++ b/2005/i/robert/src/utils/bind.hh
@@ -0,0 +1,55 @@
+#ifndef bind_hh
+#define bind_hh
+// bind.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+namespace utils {
+
+template<typename R, typename F, typename A>
+class binder
+{
+ F func_;
+ const A &arg_;
+ public:
+ typedef R result_type;
+ public:
+ binder (F func, const A &arg)
+ : func_ (func), arg_ (arg)
+ { }
+ result_type operator () (void)
+ {
+ return func_ (arg_);
+ }
+};
+
+template<typename R, typename F, typename A>
+binder<R, F, A>
+bind (F func, const A &arg)
+{
+ return binder<R, F, A> (func, arg);
+}
+
+} // namespace utils
+
+#endif // bind_hh
diff --git a/2005/i/robert/src/utils/callback.hh b/2005/i/robert/src/utils/callback.hh
new file mode 100644
index 0000000..f9eff8f
--- /dev/null
+++ b/2005/i/robert/src/utils/callback.hh
@@ -0,0 +1,79 @@
+#ifndef callback_hh
+#define callback_hh
+// callback.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+#include <stdexcept>
+
+template<typename R>
+class Callback
+{
+ class AbstractHolder;
+ AbstractHolder *holder_;
+ public:
+ typedef R result_type;
+ public:
+ Callback (void);
+ template<typename T>
+ Callback (T callback);
+ Callback (const Callback &other);
+ ~Callback (void);
+ R operator () (void);
+ void swap (Callback &rhs);
+ Callback &operator= (const Callback &rhs);
+ template<typename T>
+ Callback &operator= (T rhs);
+ bool empty (void) const;
+ operator bool (void) const;
+ private:
+ class AbstractHolder
+ {
+ public:
+ virtual ~AbstractHolder (void);
+ virtual R operator () (void) = 0;
+ virtual AbstractHolder *clone (void) = 0;
+ };
+ template<typename T>
+ class Holder : public AbstractHolder
+ {
+ private:
+ T callback_;
+ public:
+ Holder (T callback);
+ virtual R operator () (void);
+ virtual AbstractHolder *clone (void);
+ };
+};
+
+class bad_callback : public std::runtime_error
+{
+ public:
+ bad_callback (void) : std::runtime_error ("bad_callback: empty callback call")
+ {
+ }
+};
+
+#include "callback.tcc"
+
+#endif // callback_hh
diff --git a/2005/i/robert/src/utils/callback.tcc b/2005/i/robert/src/utils/callback.tcc
new file mode 100644
index 0000000..36d97a7
--- /dev/null
+++ b/2005/i/robert/src/utils/callback.tcc
@@ -0,0 +1,126 @@
+// callback.tcc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+#include <algorithm>
+
+template<typename R>
+Callback<R>::Callback (void)
+ : holder_ (0)
+{
+}
+
+template<typename R>
+template<typename T>
+Callback<R>::Callback (T callback)
+ : holder_ (new Holder<T> (callback))
+{
+}
+
+template<typename R>
+Callback<R>::Callback (const Callback<R> &other)
+ : holder_ (other.holder_ ? other.holder_->clone () : 0)
+{
+}
+
+template<typename R>
+Callback<R>::~Callback (void)
+{
+ delete holder_;
+}
+
+template<typename R>
+R
+Callback<R>::operator () (void)
+{
+ if (!holder_)
+ throw bad_callback ();
+ else
+ return (*holder_) ();
+}
+
+template<typename R>
+void
+Callback<R>::swap (Callback<R> &rhs)
+{
+ std::swap (holder_, rhs.holder_);
+}
+
+template<typename R>
+Callback<R> &
+Callback<R>::operator= (const Callback<R> &rhs)
+{
+ Callback<R> (rhs).swap (*this);
+ return *this;
+}
+
+template<typename R>
+template<typename T>
+Callback<R> &
+Callback<R>::operator= (T rhs)
+{
+ Callback<R> (rhs).swap (*this);
+ return *this;
+}
+
+template<typename R>
+bool
+Callback<R>::empty (void) const
+{
+ return !holder_;
+}
+
+template<typename R>
+Callback<R>::operator bool (void) const
+{
+ return !empty ();
+}
+
+template<typename R>
+Callback<R>::AbstractHolder::~AbstractHolder (void)
+{
+}
+
+template<typename R>
+template<typename T>
+Callback<R>::Holder<T>::Holder (T callback)
+ : callback_ (callback)
+{
+}
+
+template<typename R>
+template<typename T>
+R
+Callback<R>::Holder<T>::operator () (void)
+{
+ return callback_ ();
+}
+
+template<typename R>
+template<typename T>
+typename Callback<R>::AbstractHolder *
+Callback<R>::Holder<T>::clone (void)
+{
+ return new Holder<T> (callback_);
+}
+
diff --git a/2005/i/robert/src/utils/fd_set.hh b/2005/i/robert/src/utils/fd_set.hh
new file mode 100644
index 0000000..7cc53e5
--- /dev/null
+++ b/2005/i/robert/src/utils/fd_set.hh
@@ -0,0 +1,51 @@
+#ifndef fd_set_hh
+#define fd_set_hh
+// fd_set.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+#include <sys/types.h>
+
+/// Wrapper over libc fd_set.
+class FdSet
+{
+ fd_set set_;
+ public:
+ /// Default constructor.
+ FdSet (void)
+ { FD_ZERO (&set_); }
+ /// Set a fd.
+ void set (int fd)
+ { FD_SET (fd, &set_); }
+ /// Clear a fd.
+ void clear (int fd)
+ { FD_CLR (fd, &set_); }
+ /// Test if a fd is set.
+ bool isSet (int fd) const
+ { return FD_ISSET (fd, &set_); }
+ /// Get pointer to internal fd_set.
+ fd_set *get (void)
+ { return &set_; }
+};
+
+#endif // fd_set_hh
diff --git a/2005/i/robert/src/utils/meta/Makefile.defs b/2005/i/robert/src/utils/meta/Makefile.defs
new file mode 100644
index 0000000..5650f40
--- /dev/null
+++ b/2005/i/robert/src/utils/meta/Makefile.defs
@@ -0,0 +1,5 @@
+PROGRAMS += test_is_string
+
+test_is_string_OBJECTS = test_is_string.o
+
+test_is_string: $(test_is_string_OBJECTS)
diff --git a/2005/i/robert/src/utils/meta/is_string.hh b/2005/i/robert/src/utils/meta/is_string.hh
new file mode 100644
index 0000000..99782d2
--- /dev/null
+++ b/2005/i/robert/src/utils/meta/is_string.hh
@@ -0,0 +1,45 @@
+#ifndef is_string_hh
+#define is_string_hh
+// is_string.hh
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+
+#include <string>
+
+namespace meta {
+
+template<typename T>
+struct isString
+{
+ static const bool value = false;
+};
+
+template<>
+struct isString<std::string>
+{
+ static const bool value = true;
+};
+
+} // namespace meta
+
+#endif // is_string_hh
diff --git a/2005/i/robert/src/utils/meta/test_is_string.cc b/2005/i/robert/src/utils/meta/test_is_string.cc
new file mode 100644
index 0000000..c61483a
--- /dev/null
+++ b/2005/i/robert/src/utils/meta/test_is_string.cc
@@ -0,0 +1,35 @@
+// test_is_string.cc
+// {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "is_string.hh"
+
+#include <iostream>
+
+int
+main (void)
+{
+ std::cout << "std::string " << meta::isString<std::string>::value << std::endl;
+ std::cout << "int " << meta::isString<int>::value << std::endl;
+ std::cout << "char * " << meta::isString<char *>::value << std::endl;
+ return 0;
+}
diff --git a/2005/i/robert/src/utils/test_any.cc b/2005/i/robert/src/utils/test_any.cc
new file mode 100644
index 0000000..e8af644
--- /dev/null
+++ b/2005/i/robert/src/utils/test_any.cc
@@ -0,0 +1,48 @@
+// test_any.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "any.hh"
+
+#include <exception>
+#include <iostream>
+#include <string>
+
+int
+main (int argc, char **argv)
+{
+ any a (45), b (std::string ("toto")), c (5.4), d (std::string ("5"));
+ try
+ {
+ std::cout << a << ' ' << b << ' ' << c << ' ' << d << std::endl;
+ std::cout << any_cast<int> (a) << std::endl;
+ std::cout << any_cast<std::string> (b) << std::endl;
+ std::cout << any_cast<double> (c) << std::endl;
+ std::cout << any_cast<int> (d) << std::endl;
+ }
+ catch (const std::exception &e)
+ {
+ std::cout << e.what () << std::endl;
+ return 1;
+ }
+ return 0;
+}
diff --git a/2005/i/robert/src/utils/test_bind.cc b/2005/i/robert/src/utils/test_bind.cc
new file mode 100644
index 0000000..9ebdc4e
--- /dev/null
+++ b/2005/i/robert/src/utils/test_bind.cc
@@ -0,0 +1,45 @@
+// test_bind.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "bind.hh"
+
+#include <iostream>
+
+void
+f (int i)
+{
+ std::cout << "f " << i << std::endl;
+}
+
+void
+g (const char *s)
+{
+ std::cout << "g " << s << std::endl;
+}
+
+int
+main (void)
+{
+ utils::bind<void> (&f, 42) ();
+ utils::bind<void> (&g, "hello world !") ();
+}
diff --git a/2005/i/robert/src/utils/test_callback.cc b/2005/i/robert/src/utils/test_callback.cc
new file mode 100644
index 0000000..2a5b6f0
--- /dev/null
+++ b/2005/i/robert/src/utils/test_callback.cc
@@ -0,0 +1,84 @@
+// test_callback.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// Contact :
+// Web: http://perso.efrei.fr/~schodet/
+// Email: <contact@ni.fr.eu.org>
+// }}}
+#include "callback.hh"
+
+#include <iostream>
+
+void
+f (void)
+{
+ std::cout << " f ()" << std::endl;
+}
+
+int
+i (void)
+{
+ static int v = 42;
+ std::cout << " i () = " << v << std::endl;
+ return v++;
+}
+
+struct G
+{
+ void operator () (void)
+ {
+ std::cout << " g ()" << std::endl;
+ }
+};
+
+int
+main (void)
+{
+ G g;
+ Callback<void> cf (f);
+ Callback<void> cg (g);
+ Callback<void> ch;
+ Callback<int> ci (i);
+ try
+ {
+ std::cout << "cf" << std::endl;
+ cf ();
+ std::cout << "cg" << std::endl;
+ cg ();
+ cf = cg;
+ cg = f;
+ std::cout << "cf" << std::endl;
+ cf ();
+ std::cout << "cg" << std::endl;
+ cg ();
+ std::cout << "cf " << (cf ? "not " : "") << "empty" << std::endl;
+ std::cout << "ch " << (ch ? "not " : "") << "empty" << std::endl;
+ std::cout << "ci" << std::endl;
+ int r = ci ();
+ std::cout << "ci = " << r << std::endl;
+ std::cout << "ch" << std::endl;
+ ch ();
+ }
+ catch (const std::exception &e)
+ {
+ std::cout << e.what () << std::endl;
+ return 1;
+ }
+ return 0;
+}