From fcfd616f76345787a8eb1318e482ab1076d50039 Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 13 Mar 2005 20:26:23 +0000 Subject: Ajout de commentaires. Ajout de l'ObjectBinder. --- 2005/i/robert/src/utils/callback.hh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to '2005/i/robert/src/utils/callback.hh') diff --git a/2005/i/robert/src/utils/callback.hh b/2005/i/robert/src/utils/callback.hh index f9eff8f..c5dc229 100644 --- a/2005/i/robert/src/utils/callback.hh +++ b/2005/i/robert/src/utils/callback.hh @@ -26,27 +26,41 @@ #include +/// Class to store a callback. This callback can be of any type (function or +/// fonctor). template class Callback { class AbstractHolder; AbstractHolder *holder_; public: + /// Return value. typedef R result_type; public: + /// Default constructor. Make an empty callback. Callback (void); + /// Constructor. template 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); - Callback &operator= (const Callback &rhs); + /// Change the contained callback. template 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: @@ -54,6 +68,7 @@ class Callback virtual R operator () (void) = 0; virtual AbstractHolder *clone (void) = 0; }; + /// Templated container. template class Holder : public AbstractHolder { @@ -66,6 +81,7 @@ class Callback }; }; +/// Exception thrown on call of an empty callback. class bad_callback : public std::runtime_error { public: -- cgit v1.2.3