From c425ae7693b604c190d3904e7ef965f93d34edee Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 2 Apr 2006 17:23:53 +0000 Subject: Support des fonctions qui ne retournent pas de bool. Support du dry run. --- i/marvin/src/interpreter/interpreter.tcc | 53 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'i/marvin/src/interpreter/interpreter.tcc') diff --git a/i/marvin/src/interpreter/interpreter.tcc b/i/marvin/src/interpreter/interpreter.tcc index 0e4fcf9..5af0e0a 100644 --- a/i/marvin/src/interpreter/interpreter.tcc +++ b/i/marvin/src/interpreter/interpreter.tcc @@ -36,85 +36,89 @@ class Interpreter::MemFunc /// Partially specialised for member functions taking an arguments list. template -class Interpreter::MemFunc : public Func +class Interpreter::MemFunc +: public Func { T &i_; - typedef bool (T::*F) (const Interpreter::Args &); + typedef void (T::*F) (const Interpreter::Args &, bool); F f_; public: MemFunc (T &i, F f) : i_ (i), f_ (f) { } - bool operator() (const Args &a) + void operator() (const Args &a, bool dryrun) { - return (i_.*f_) (a); + (i_.*f_) (a, dryrun); } }; /// Partially specialised for members functions taking no argument. -template -class Interpreter::MemFunc : public Func +template +class Interpreter::MemFunc : public Func { T &i_; - typedef bool (T::*F) (void); + typedef R (T::*F) (void); F f_; public: MemFunc (T &i, F f) : i_ (i), f_ (f) { } - bool operator() (const Args &a) + void operator() (const Args &a, bool dryrun) { if (!a.empty ()) throw std::runtime_error ("no argument expected"); - return (i_.*f_) (); + if (!dryrun) + (i_.*f_) (); } }; /// Partially specialised for members functions taking one argument. -template -class Interpreter::MemFunc : public Func +template +class Interpreter::MemFunc : public Func { T &i_; - typedef bool (T::*F) (A1); + typedef R (T::*F) (A1); F f_; public: MemFunc (T &i, F f) : i_ (i), f_ (f) { } - bool operator() (const Args &a) + void operator() (const Args &a, bool dryrun) { Args::const_iterator i = a.begin (); if (a.size () != 1) throw std::runtime_error ("one argument expected"); A1 a1 = any_cast::type> (*i); - return (i_.*f_) (a1); + if (!dryrun) + (i_.*f_) (a1); } }; /// Partially specialised for members functions taking two arguments. -template -class Interpreter::MemFunc : public Func +template +class Interpreter::MemFunc : public Func { T &i_; - typedef bool (T::*F) (A1, A2); + typedef R (T::*F) (A1, A2); F f_; public: MemFunc (T &i, F f) : i_ (i), f_ (f) { } - bool operator() (const Args &a) + void operator() (const Args &a, bool dryrun) { Args::const_iterator i = a.begin (); if (a.size () != 2) throw std::runtime_error ("two arguments expected"); A1 a1 = any_cast::type> (*i); A2 a2 = any_cast::type> (*++i); - return (i_.*f_) (a1, a2); + if (!dryrun) + (i_.*f_) (a1, a2); } }; /// Partially specialised for members functions taking three arguments. -template -class Interpreter::MemFunc : public Func +template +class Interpreter::MemFunc : public Func { T &i_; - typedef bool (T::*F) (A1, A2, A3); + typedef R (T::*F) (A1, A2, A3); F f_; public: MemFunc (T &i, F f) : i_ (i), f_ (f) { } - bool operator() (const Args &a) + void operator() (const Args &a, bool dryrun) { Args::const_iterator i = a.begin (); if (a.size () != 3) @@ -122,7 +126,8 @@ class Interpreter::MemFunc : public Func A1 a1 = any_cast::type> (*i); A2 a2 = any_cast::type> (*++i); A3 a3 = any_cast::type> (*++i); - return (i_.*f_) (a1, a2, a3); + if (!dryrun) + (i_.*f_) (a1, a2, a3); } }; -- cgit v1.2.3