summaryrefslogtreecommitdiff
path: root/i/chuck/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'i/chuck/src/utils')
-rw-r--r--i/chuck/src/utils/Makefile.defs11
-rw-r--r--i/chuck/src/utils/any.hh125
-rw-r--r--i/chuck/src/utils/any.tcc185
-rw-r--r--i/chuck/src/utils/bind.hh91
-rw-r--r--i/chuck/src/utils/callback.hh96
-rw-r--r--i/chuck/src/utils/callback.tcc140
-rw-r--r--i/chuck/src/utils/errno_exception.hh48
-rw-r--r--i/chuck/src/utils/fd_set.cc53
-rw-r--r--i/chuck/src/utils/fd_set.hh54
-rw-r--r--i/chuck/src/utils/hexa.cc113
-rw-r--r--i/chuck/src/utils/hexa.hh49
-rw-r--r--i/chuck/src/utils/list_ostream_output.hh62
-rw-r--r--i/chuck/src/utils/mathutil.hh57
-rw-r--r--i/chuck/src/utils/meta/Makefile.defs3
-rw-r--r--i/chuck/src/utils/meta/is_equal.hh44
-rw-r--r--i/chuck/src/utils/meta/is_string.hh45
-rw-r--r--i/chuck/src/utils/meta/remove_reference.hh44
-rw-r--r--i/chuck/src/utils/meta/test_meta.cc57
-rw-r--r--i/chuck/src/utils/non_copyable.hh41
-rw-r--r--i/chuck/src/utils/signalhandler.hh52
-rw-r--r--i/chuck/src/utils/signalhandler.tcc66
-rw-r--r--i/chuck/src/utils/test_any.cc50
-rw-r--r--i/chuck/src/utils/test_bind.cc57
-rw-r--r--i/chuck/src/utils/test_callback.cc84
-rw-r--r--i/chuck/src/utils/test_signalhandler.cc15
25 files changed, 1642 insertions, 0 deletions
diff --git a/i/chuck/src/utils/Makefile.defs b/i/chuck/src/utils/Makefile.defs
new file mode 100644
index 0000000..8eb0711
--- /dev/null
+++ b/i/chuck/src/utils/Makefile.defs
@@ -0,0 +1,11 @@
+PROGRAMS += test_any test_callback test_bind test_signalhandler
+
+utils_OBJECTS = fd_set.o hexa.o
+
+test_any_OBJECTS = test_any.o
+
+test_callback_OBJECTS = test_callback.o
+
+test_bind_OBJECTS = test_bind.o
+
+test_signalhandler_OBJECTS = test_signalhandler.o
diff --git a/i/chuck/src/utils/any.hh b/i/chuck/src/utils/any.hh
new file mode 100644
index 0000000..dc6204e
--- /dev/null
+++ b/i/chuck/src/utils/any.hh
@@ -0,0 +1,125 @@
+#ifndef any_hh
+#define any_hh
+// any.hh
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2003-2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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 <typeinfo>
+#include <exception>
+#include <iostream>
+
+/// This class can contain a data of almost any type. This very type must be
+/// CopyConstructible and OutputStreamable. The OutputStreamable restriction
+/// could be removed, but it is so convenient to output an any...
+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);
+ /// Swap content between two any objects.
+ any &swap (any &other);
+ /// Copy another any object.
+ any &operator= (const any &other);
+ /// Copy another object into this any.
+ template<typename T>
+ any &operator= (const T &value);
+ /// Test if the any object is empty.
+ bool empty (void) const;
+ /// Return the std::type_info of the contained object.
+ 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;
+ };
+};
+
+/// Return a pointer to the contained object or 0 on faillure.
+template<typename T>
+T *
+any_cast (any *rhs);
+
+/// Return a const pointer to the contained object or 0 on faillure.
+template<typename T>
+const T *
+any_cast (const any *rhs);
+
+/// Return a const reference to the contained object or throw a bad_any_cast
+/// on faillure.
+template<typename T>
+const T &
+any_cast (const any &rhs);
+
+/// Object throw if a any_cast returning a reference fail.
+class bad_any_cast : public std::bad_cast
+{
+ std::string what_;
+ public:
+ /// Constructor.
+ bad_any_cast (const std::type_info &to, const std::type_info &from);
+ /// Destructor which should throw nothing.
+ virtual ~bad_any_cast() throw()
+ { }
+ /// Get the error text.
+ virtual const char *what() const throw()
+ { return what_.c_str (); }
+};
+
+/// Print the contained object.
+std::ostream &
+operator<< (std::ostream &os, const any &rhs);
+
+#include "any.tcc"
+
+#endif // any_hh
diff --git a/i/chuck/src/utils/any.tcc b/i/chuck/src/utils/any.tcc
new file mode 100644
index 0000000..70d1084
--- /dev/null
+++ b/i/chuck/src/utils/any.tcc
@@ -0,0 +1,185 @@
+#ifndef any_tcc
+#define any_tcc
+// any.tcc
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2003-2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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 "list_ostream_output.hh"
+
+#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_;
+}
+
+/// Swap content between two any objects.
+inline
+any &
+any::swap (any &other)
+{
+ std::swap (holder_, other.holder_);
+ return *this;
+}
+
+/// Copy another any object.
+inline
+any &
+any::operator= (const any &other)
+{
+ any (other).swap (*this);
+ return *this;
+}
+
+/// Copy another object into this any.
+template<typename T>
+any &
+any::operator= (const T &value)
+{
+ any (value).swap (*this);
+ return *this;
+}
+
+/// Test if the any object is empty.
+inline
+bool
+any::empty (void) const
+{
+ return !holder_;
+}
+
+/// Return the std::type_info of the contained object.
+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_;
+}
+
+/// Return a pointer to the contained object or 0 on faillure.
+template<typename T>
+T *
+any_cast (any *rhs)
+{
+ return rhs && rhs->type () == typeid (T)
+ ? &static_cast<any::Holder<T> *> (rhs->holder_)->value_
+ : 0;
+}
+
+/// Return a const pointer to the contained object or 0 on faillure.
+template<typename T>
+const T *
+any_cast (const any *rhs)
+{
+ return any_cast<T> (const_cast<any *> (rhs));
+}
+
+/// Return a const reference to the contained object or throw a bad_any_cast
+/// on faillure.
+template<typename T>
+const T &
+any_cast (const any &rhs)
+{
+ const T *value = any_cast<T> (&rhs);
+ if (!value)
+ throw bad_any_cast (typeid (T), rhs.type ());
+ return *value;
+}
+
+/// Constructor.
+inline
+bad_any_cast::bad_any_cast (const std::type_info &to,
+ const std::type_info &from)
+{
+ what_ = "illegal conversion from \'";
+ what_ += from.name ();
+ what_ += "\' to \'";
+ what_ += to.name ();
+ what_ += "\'";
+}
+
+/// Print the contained object.
+inline
+std::ostream &
+operator<< (std::ostream &os, const any &rhs)
+{
+ return rhs.holder_->print (os);
+}
+
+#endif // any_tcc
diff --git a/i/chuck/src/utils/bind.hh b/i/chuck/src/utils/bind.hh
new file mode 100644
index 0000000..a5630fe
--- /dev/null
+++ b/i/chuck/src/utils/bind.hh
@@ -0,0 +1,91 @@
+#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>
+// }}}
+
+/// Class used to bind a function taking an argument to a functor taking no
+/// argument. This is not supposed to be used directly, but using the bind
+/// template function.
+template<typename R, typename F, typename A>
+class ArgBinder
+{
+ /// Original function.
+ F func_;
+ /// Stored argument reference.
+ const A &arg_;
+ public:
+ /// Return value.
+ typedef R result_type;
+ public:
+ ArgBinder (F func, const A &arg)
+ : func_ (func), arg_ (arg)
+ { }
+ result_type operator () (void)
+ {
+ return func_ (arg_);
+ }
+};
+
+/// Bind a function taking an argument to a functor taking no argument.
+/// Return value must be specified, other template arguments can be implied.
+template<typename R, typename F, typename A>
+ArgBinder<R, F, A>
+bind (F func, const A &arg)
+{
+ return ArgBinder<R, F, A> (func, arg);
+}
+
+/// Class used to bind a member function to a functor taking no argument.
+/// This is not supposed to be used directly, but using the bind template
+/// function.
+template<typename R, typename C>
+class ObjBinder
+{
+ /// Original member function.
+ R (C::*func_) (void);
+ /// Object pointer stored.
+ C *obj_;
+ public:
+ /// Return value.
+ typedef R result_type;
+ public:
+ ObjBinder (R (C::*func) (void), C *obj)
+ : func_ (func), obj_ (obj)
+ { }
+ result_type operator () (void)
+ {
+ (obj_->*func_) ();
+ }
+};
+
+/// Bind a member function to a functor taking no argument. All template
+/// parameters must be specified.
+template<typename R, typename C>
+ObjBinder<R, C>
+bind (R (C::*func) (void), C *obj)
+{
+ return ObjBinder<R, C> (func, obj);
+}
+
+#endif // bind_hh
diff --git a/i/chuck/src/utils/callback.hh b/i/chuck/src/utils/callback.hh
new file mode 100644
index 0000000..ab1311c
--- /dev/null
+++ b/i/chuck/src/utils/callback.hh
@@ -0,0 +1,96 @@
+#ifndef callback_hh
+#define callback_hh
+// callback.hh
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2003-2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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 <stdexcept>
+
+/// Class to store a callback. This callback can be of any type (function or
+/// fonctor).
+template<typename R>
+class Callback
+{
+ class AbstractHolder;
+ AbstractHolder *holder_;
+ public:
+ /// Return value.
+ typedef R result_type;
+ public:
+ /// Default constructor. Make an empty callback.
+ Callback (void);
+ /// Constructor.
+ template<typename T>
+ Callback (T callback);
+ /// Copy constructor.
+ Callback (const Callback &other);
+ /// Destructor.
+ ~Callback (void);
+ /// Assignement operator.
+ Callback &operator= (const Callback &rhs);
+ /// Call the contained callback.
+ R operator () (void);
+ /// Swap the callback content with another callback.
+ void swap (Callback &rhs);
+ /// Change the contained callback.
+ template<typename T>
+ Callback &operator= (T rhs);
+ /// Test if empty.
+ bool empty (void) const;
+ /// Test if not empty.
+ operator bool (void) const;
+ private:
+ /// Abstract container.
+ class AbstractHolder
+ {
+ public:
+ virtual ~AbstractHolder (void);
+ virtual R operator () (void) = 0;
+ virtual AbstractHolder *clone (void) = 0;
+ };
+ /// Templated container.
+ template<typename T>
+ class Holder : public AbstractHolder
+ {
+ private:
+ T callback_;
+ public:
+ Holder (T callback);
+ virtual R operator () (void);
+ virtual AbstractHolder *clone (void);
+ };
+};
+
+/// Exception thrown on call of an empty callback.
+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/i/chuck/src/utils/callback.tcc b/i/chuck/src/utils/callback.tcc
new file mode 100644
index 0000000..4e8bdd4
--- /dev/null
+++ b/i/chuck/src/utils/callback.tcc
@@ -0,0 +1,140 @@
+#ifndef callback_tcc
+#define callback_tcc
+// callback.tcc
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2003-2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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 <algorithm>
+
+/// Default constructor. Make an empty callback.
+template<typename R>
+Callback<R>::Callback (void)
+ : holder_ (0)
+{
+}
+
+/// Constructor.
+template<typename R>
+template<typename T>
+Callback<R>::Callback (T callback)
+ : holder_ (new Holder<T> (callback))
+{
+}
+
+/// Copy constructor.
+template<typename R>
+Callback<R>::Callback (const Callback<R> &other)
+ : holder_ (other.holder_ ? other.holder_->clone () : 0)
+{
+}
+
+/// Destructor.
+template<typename R>
+Callback<R>::~Callback (void)
+{
+ delete holder_;
+}
+
+/// Assignement operator.
+template<typename R>
+Callback<R> &
+Callback<R>::operator= (const Callback<R> &rhs)
+{
+ Callback<R> (rhs).swap (*this);
+ return *this;
+}
+
+/// Call the contained callback.
+template<typename R>
+R
+Callback<R>::operator () (void)
+{
+ if (!holder_)
+ throw bad_callback ();
+ else
+ return (*holder_) ();
+}
+
+/// Swap the callback content with another callback.
+template<typename R>
+void
+Callback<R>::swap (Callback<R> &rhs)
+{
+ std::swap (holder_, rhs.holder_);
+}
+
+/// Change the contained callback.
+template<typename R>
+template<typename T>
+Callback<R> &
+Callback<R>::operator= (T rhs)
+{
+ Callback<R> (rhs).swap (*this);
+ return *this;
+}
+
+/// Test if empty.
+template<typename R>
+bool
+Callback<R>::empty (void) const
+{
+ return !holder_;
+}
+
+/// Test if not empty.
+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_);
+}
+
+#endif // callback_tcc
diff --git a/i/chuck/src/utils/errno_exception.hh b/i/chuck/src/utils/errno_exception.hh
new file mode 100644
index 0000000..58a636e
--- /dev/null
+++ b/i/chuck/src/utils/errno_exception.hh
@@ -0,0 +1,48 @@
+#ifndef errno_exception_hh
+#define errno_exception_hh
+// errno_exception.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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>
+#include <exception>
+#include <cstring>
+#include <errno.h>
+
+/// Exception lancé lorsqu'une erreur est retournée par la libc.
+class errno_exception : public std::exception
+{
+ int errno_;
+ std::string what_;
+ public:
+ errno_exception (const std::string &desc, int errno__)
+ : errno_ (errno__), what_ (desc + ": " + strerror (errno__)) { }
+ errno_exception (int errno__)
+ : errno_ (errno__), what_ (strerror (errno__)) { }
+ ~errno_exception (void) throw () { }
+ virtual const char* what () const throw () { return what_.c_str (); }
+ int getErrno (void) const { return errno_; }
+};
+
+#endif // errno_exception_hh
diff --git a/i/chuck/src/utils/fd_set.cc b/i/chuck/src/utils/fd_set.cc
new file mode 100644
index 0000000..998f3f5
--- /dev/null
+++ b/i/chuck/src/utils/fd_set.cc
@@ -0,0 +1,53 @@
+// fd_set.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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 "fd_set.hh"
+#include "utils/errno_exception.hh"
+
+/// Wait for an read event or timeout in milliseconds, return true on read
+/// event.
+bool
+FdSet::wait (int timeout/*-1*/)
+{
+ int r;
+ if (timeout == -1)
+ {
+ // Without timeout.
+ r = select (FD_SETSIZE, get (), 0, 0, 0);
+ }
+ else
+ {
+ // With timeout.
+ struct timeval tv;
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ r = select (FD_SETSIZE, get (), 0, 0, &tv);
+ }
+ if (r == -1)
+ // Error.
+ throw errno_exception (errno);
+ else
+ return r != 0;
+}
+
diff --git a/i/chuck/src/utils/fd_set.hh b/i/chuck/src/utils/fd_set.hh
new file mode 100644
index 0000000..3d6d44c
--- /dev/null
+++ b/i/chuck/src/utils/fd_set.hh
@@ -0,0 +1,54 @@
+#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_; }
+ /// Wait for an read event or timeout in milliseconds, return true on read
+ /// event.
+ bool wait (int timeout = -1);
+};
+
+#endif // fd_set_hh
diff --git a/i/chuck/src/utils/hexa.cc b/i/chuck/src/utils/hexa.cc
new file mode 100644
index 0000000..102458e
--- /dev/null
+++ b/i/chuck/src/utils/hexa.cc
@@ -0,0 +1,113 @@
+// hexa.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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 "hexa.hh"
+
+// Table de conversion en hexa.
+static const char *digit2hexTbl_ = "0123456789abcdef";
+
+// Table de conversion depuis l'hexa.
+#define hI hexInvalid
+static const int hex2digitTbl_[] =
+{
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 0-15 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 16-31 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 32-47 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,hI,hI,hI,hI,hI,hI, /* 48-63 */
+ hI,10,11,12,13,14,15,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 64-79 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 80-95 */
+ hI,10,11,12,13,14,15,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 96-111 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 112-127 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 128-143 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 144-159 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 160-175 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 176-191 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 192-207 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 208-223 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 224-239 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 240-255 */
+};
+
+/// Converti un caractère hexa (0-9a-f) en chiffre (0-15).
+int
+hex2digit (char c)
+{
+ return hex2digitTbl_[static_cast<int> (c)];
+}
+
+/// Converti un chiffre (0-15) en hexa (0-9a-f).
+char
+digit2hex (int d)
+{
+ return digit2hexTbl_[d];
+}
+
+/// Décode un mot non-signé (1 octets).
+unsigned int
+hexUnsignedChar2int (const char *s)
+{
+ int h1 = hex2digit (s[0]);
+ int h0 = hex2digit (s[1]);
+ if (h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (unsigned char) (h1 << 4 | h0);
+}
+
+/// Décode un mot signé (1 octets).
+int
+hexSignedChar2int (const char *s)
+{
+ int h1 = hex2digit (s[0]);
+ int h0 = hex2digit (s[1]);
+ if (h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (signed char) (h1 << 4 | h0);
+}
+
+/// Décode un mot non-signé (2 octets).
+int
+hexUnsignedShort2int (const char *s)
+{
+ int h3 = hex2digit (s[0]);
+ int h2 = hex2digit (s[1]);
+ int h1 = hex2digit (s[2]);
+ int h0 = hex2digit (s[3]);
+ if (h3 == hexInvalid || h2 == hexInvalid || h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (unsigned short) (h3 << 12 | h2 << 8 | h1 << 4 | h0);
+}
+
+/// Décode un mot signé (2 octets).
+int
+hexSignedShort2int (const char *s)
+{
+ int h3 = hex2digit (s[0]);
+ int h2 = hex2digit (s[1]);
+ int h1 = hex2digit (s[2]);
+ int h0 = hex2digit (s[3]);
+ if (h3 == hexInvalid || h2 == hexInvalid || h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (short) (h3 << 12 | h2 << 8 | h1 << 4 | h0);
+}
+
diff --git a/i/chuck/src/utils/hexa.hh b/i/chuck/src/utils/hexa.hh
new file mode 100644
index 0000000..f7d3399
--- /dev/null
+++ b/i/chuck/src/utils/hexa.hh
@@ -0,0 +1,49 @@
+#ifndef hexa_hh
+#define hexa_hh
+// hexa.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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.
+//
+// }}}
+
+/// Constante retournée pour une valeur invalide.
+const int hexInvalid = 1 << 24;
+
+/// Converti un caractère hexa (0-9a-f) en chiffre (0-15).
+int hex2digit (char c);
+
+/// Converti un chiffre (0-15) en hexa (0-9a-f).
+char digit2hex (int d);
+
+/// Décode un mot non-signé (1 octets).
+unsigned int hexUnsignedChar2int (const char *s);
+
+/// Décode un mot signé (1 octets).
+int hexSignedChar2int (const char *s);
+
+/// Décode un mot non-signé (2 octets).
+int hexUnsignedShort2int (const char *s);
+
+/// Décode un mot signé (2 octets).
+int hexSignedShort2int (const char *s);
+
+#endif // hexa_hh
diff --git a/i/chuck/src/utils/list_ostream_output.hh b/i/chuck/src/utils/list_ostream_output.hh
new file mode 100644
index 0000000..3863a39
--- /dev/null
+++ b/i/chuck/src/utils/list_ostream_output.hh
@@ -0,0 +1,62 @@
+#ifndef list_ostream_output_hh
+#define list_ostream_output_hh
+// list_ostream_output.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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>
+#include <list>
+#include <vector>
+#include <algorithm>
+#include <iterator>
+
+/// Output any list.
+template<typename T>
+std::ostream &
+output_list (std::ostream &os, const T &list)
+{
+ os << "( ";
+ std::copy (list.begin (), list.end (),
+ std::ostream_iterator<typename T::value_type> (os, " "));
+ os << ')';
+ return os;
+}
+
+/// Output a list.
+template<typename T>
+std::ostream &
+operator<< (std::ostream &os, const std::list<T> &list)
+{
+ return output_list (os, list);
+}
+
+/// Output a vector.
+template<typename T>
+std::ostream &
+operator<< (std::ostream &os, const std::vector<T> &list)
+{
+ return output_list (os, list);
+}
+
+#endif // list_ostream_output_hh
diff --git a/i/chuck/src/utils/mathutil.hh b/i/chuck/src/utils/mathutil.hh
new file mode 100644
index 0000000..d58cec3
--- /dev/null
+++ b/i/chuck/src/utils/mathutil.hh
@@ -0,0 +1,57 @@
+#ifndef mathutil_hh
+#define mathutil_hh
+// mathutil.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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 <cmath>
+
+/// Normalise l'angle entre -pi et +pi.
+double
+angleNorm (double a);
+
+/// Converti en coordonnées polaires.
+void
+toPolar (double x, double y, double &r, double &a);
+
+/// Normalise l'angle en [-pi..+pi).
+inline double
+angleNorm (double a)
+{
+ while (a >= M_PI)
+ a -= 2.0 * M_PI;
+ while (a < -M_PI)
+ a += 2.0 * M_PI;
+ return a;
+}
+
+/// Converti en coordonnées polaires.
+inline void
+toPolar (double x, double y, double &r, double &a)
+{
+ // Rayon.
+ r = sqrt (x * x + y * y);
+ a = y > 0 ? acos (x / r) : -acos (x / r);
+}
+
+#endif // mathutil_hh
diff --git a/i/chuck/src/utils/meta/Makefile.defs b/i/chuck/src/utils/meta/Makefile.defs
new file mode 100644
index 0000000..8fa3a10
--- /dev/null
+++ b/i/chuck/src/utils/meta/Makefile.defs
@@ -0,0 +1,3 @@
+PROGRAMS += test_meta
+
+test_meta_OBJECTS = test_meta.o
diff --git a/i/chuck/src/utils/meta/is_equal.hh b/i/chuck/src/utils/meta/is_equal.hh
new file mode 100644
index 0000000..a67e8a6
--- /dev/null
+++ b/i/chuck/src/utils/meta/is_equal.hh
@@ -0,0 +1,44 @@
+#ifndef is_equal_hh
+#define is_equal_hh
+// is_equal.hh - test if two types equals.
+// {{{
+//
+// Copyright (C) 2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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.
+//
+// }}}
+
+namespace meta {
+
+template<typename T1, typename T2>
+struct isEqual
+{
+ static const bool value = false;
+};
+
+template<typename T>
+struct isEqual<T, T>
+{
+ static const bool value = true;
+};
+
+} // namespace meta
+
+#endif // is_equal_hh
diff --git a/i/chuck/src/utils/meta/is_string.hh b/i/chuck/src/utils/meta/is_string.hh
new file mode 100644
index 0000000..99782d2
--- /dev/null
+++ b/i/chuck/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/i/chuck/src/utils/meta/remove_reference.hh b/i/chuck/src/utils/meta/remove_reference.hh
new file mode 100644
index 0000000..f12422d
--- /dev/null
+++ b/i/chuck/src/utils/meta/remove_reference.hh
@@ -0,0 +1,44 @@
+#ifndef remove_reference_hh
+#define remove_reference_hh
+// remove_reference.hh - Remove reference from a type.
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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.
+//
+// }}}
+
+namespace meta {
+
+template<typename T>
+struct removeReference
+{
+ typedef T type;
+};
+
+template<typename T>
+struct removeReference<T &>
+{
+ typedef T type;
+};
+
+} // namespace meta
+
+#endif // remove_reference_hh
diff --git a/i/chuck/src/utils/meta/test_meta.cc b/i/chuck/src/utils/meta/test_meta.cc
new file mode 100644
index 0000000..7c973d2
--- /dev/null
+++ b/i/chuck/src/utils/meta/test_meta.cc
@@ -0,0 +1,57 @@
+// test_meta.cc
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2003-2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// 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 "is_string.hh"
+#include "is_equal.hh"
+#include "remove_reference.hh"
+
+#include <iostream>
+
+int
+main (void)
+{
+ // Test isString.
+ std::cout << "isString" << std::endl;
+ 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;
+ // Test isEqual.
+ std::cout << "isEqual" << std::endl;
+ std::cout << " int int " << meta::isEqual<int, int>::value << std::endl;
+ std::cout << " int& int " << meta::isEqual<int&, int>::value << std::endl;
+ std::cout << " int& int& " << meta::isEqual<int&, int&>::value << std::endl;
+ std::cout << " int double " << meta::isEqual<int, double>::value << std::endl;
+ // Test removeReference.
+ std::cout << "removeReference" << std::endl;
+ std::cout << " int "
+ << meta::isEqual<int, meta::removeReference<int>::type>::value
+ << std::endl;
+ std::cout << " int& "
+ << meta::isEqual<int, meta::removeReference<int &>::type>::value
+ << std::endl;
+ std::cout << " const int& "
+ << meta::isEqual<const int, meta::removeReference<const int &>::type>::value
+ << std::endl;
+ return 0;
+}
diff --git a/i/chuck/src/utils/non_copyable.hh b/i/chuck/src/utils/non_copyable.hh
new file mode 100644
index 0000000..e788365
--- /dev/null
+++ b/i/chuck/src/utils/non_copyable.hh
@@ -0,0 +1,41 @@
+#ifndef non_copyable_hh
+#define non_copyable_hh
+// non_copyable.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 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.
+//
+// }}}
+
+/// Toute classe qui hérite de NonCopyable ne peut pas être copiée. Cela est
+/// assuré par le fait que l'operator= et le constructeur de recopie sont
+/// privé.
+/// Idée originale : Boost.org.
+class NonCopyable
+{
+ public:
+ NonCopyable (void) { }
+ private:
+ NonCopyable (const NonCopyable &);
+ const NonCopyable &operator= (const NonCopyable &);
+};
+
+#endif // non_copyable_hh
diff --git a/i/chuck/src/utils/signalhandler.hh b/i/chuck/src/utils/signalhandler.hh
new file mode 100644
index 0000000..43e0f89
--- /dev/null
+++ b/i/chuck/src/utils/signalhandler.hh
@@ -0,0 +1,52 @@
+#ifndef signalhandler_hh
+#define signalhandler_hh
+// signalhandler.hh
+// // marvin - programme du robot 2006. {{{
+// //
+// // Copyright (C) 2003-2006 Sebastien beaufour
+// //
+// // Robot APB Team/Efrei 2006.
+// // 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 <stdio.h>
+#include <signal.h>
+#include <iostream>
+#include "callback.hh"
+
+template<int sig>
+class SignalHandler
+{
+ private:
+ struct sigaction action;
+ struct sigaction old;
+ static Callback<void> reset;
+ static void DefaultReset();
+ public:
+ static void trapsigint(int a);
+ void bind(Callback<void> r);
+ SignalHandler();
+ ~SignalHandler();
+};
+#include "signalhandler.tcc"
+
+#endif // end of signalhandler_hh
+
diff --git a/i/chuck/src/utils/signalhandler.tcc b/i/chuck/src/utils/signalhandler.tcc
new file mode 100644
index 0000000..04a1660
--- /dev/null
+++ b/i/chuck/src/utils/signalhandler.tcc
@@ -0,0 +1,66 @@
+// signalhandler.cc
+// // // marvin - programme du robot 2006. {{{
+// // //
+// // // Copyright (C) 2003-2006 Sebastien Beaufour
+// // //
+// // // Robot APB Team/Efrei 2006.
+// // // 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 "signalhandler.hh"
+
+/// reset NEED a default reset, so here is a default reset with nothing inside
+template<int sig> void SignalHandler<sig>::DefaultReset (void)
+{
+ // Nothing
+}
+
+// Now we can set the default value to reset
+template<int sig> Callback<void> SignalHandler<sig>::reset=SignalHandler::DefaultReset;
+
+///Static member which will be use by sigaction
+template<int sig> void SignalHandler<sig>::trapsigint(int a)
+{
+ std::cout << "Trap du crtl+c "<< std::endl;
+ reset();
+}
+
+///Function to bind to the function to be called when signal il caught
+template<int sig> void SignalHandler<sig>::bind(Callback<void> r)
+{
+ reset=r;
+ action.sa_handler = trapsigint;
+ action.sa_flags = SA_ONESHOT;
+ sigaction(sig,&action,NULL);
+}
+
+/// Constructor, nothing to do
+template<int sig> SignalHandler<sig>::SignalHandler()
+{
+ //nada
+}
+
+///Destructor, put the old sig handler back
+template<int sig> SignalHandler<sig>::~SignalHandler()
+{
+ sigaction(sig,&old,NULL);
+}
diff --git a/i/chuck/src/utils/test_any.cc b/i/chuck/src/utils/test_any.cc
new file mode 100644
index 0000000..85d2319
--- /dev/null
+++ b/i/chuck/src/utils/test_any.cc
@@ -0,0 +1,50 @@
+// 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
+ {
+ // Direct call to output operator.
+ std::cout << a << ' ' << b << ' ' << c << ' ' << d << std::endl;
+ // Here, it tries to extract the contained data.
+ 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/i/chuck/src/utils/test_bind.cc b/i/chuck/src/utils/test_bind.cc
new file mode 100644
index 0000000..b883cbe
--- /dev/null
+++ b/i/chuck/src/utils/test_bind.cc
@@ -0,0 +1,57 @@
+// 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;
+}
+
+class H
+{
+ public:
+ void f (void)
+ {
+ std::cout << "h" << std::endl;
+ }
+};
+
+int
+main (void)
+{
+ // Create the callback and execute it.
+ bind<void> (&f, 42) ();
+ bind<void> (&g, "hello world !") ();
+ H h;
+ bind<void, H> (&H::f, &h) ();
+}
diff --git a/i/chuck/src/utils/test_callback.cc b/i/chuck/src/utils/test_callback.cc
new file mode 100644
index 0000000..2a5b6f0
--- /dev/null
+++ b/i/chuck/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;
+}
diff --git a/i/chuck/src/utils/test_signalhandler.cc b/i/chuck/src/utils/test_signalhandler.cc
new file mode 100644
index 0000000..e25b1d2
--- /dev/null
+++ b/i/chuck/src/utils/test_signalhandler.cc
@@ -0,0 +1,15 @@
+#include <iostream>
+#include "signalhandler.hh"
+
+void res()
+{
+ std::cout << "RESET" << std::endl;
+}
+
+int main()
+{
+ SignalHandler<SIGINT> test;
+ test.bind(res);
+ while(1);
+ return 0;
+}