summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/utils/callback.hh
diff options
context:
space:
mode:
authorschodet2005-03-13 20:26:23 +0000
committerschodet2005-03-13 20:26:23 +0000
commitfcfd616f76345787a8eb1318e482ab1076d50039 (patch)
treeadb7200c223de2cd3839bf9c922894f48f377dae /2005/i/robert/src/utils/callback.hh
parenta5ccb9a2944290075e032a8a18102a046841e808 (diff)
Ajout de commentaires.
Ajout de l'ObjectBinder.
Diffstat (limited to '2005/i/robert/src/utils/callback.hh')
-rw-r--r--2005/i/robert/src/utils/callback.hh18
1 files changed, 17 insertions, 1 deletions
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 <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);
- Callback &operator= (const 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:
@@ -54,6 +68,7 @@ class Callback
virtual R operator () (void) = 0;
virtual AbstractHolder *clone (void) = 0;
};
+ /// Templated container.
template<typename T>
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: