summaryrefslogtreecommitdiff
path: root/i/marvin/src/interpreter/interpreter.tcc
diff options
context:
space:
mode:
authorschodet2006-04-02 17:23:53 +0000
committerschodet2006-04-02 17:23:53 +0000
commitc425ae7693b604c190d3904e7ef965f93d34edee (patch)
tree4ce709554b2c0d2e872a0da6c903de77765ee02c /i/marvin/src/interpreter/interpreter.tcc
parentc927f32a735e1600cf6b50a315d204963cf5877e (diff)
Support des fonctions qui ne retournent pas de bool.
Support du dry run.
Diffstat (limited to 'i/marvin/src/interpreter/interpreter.tcc')
-rw-r--r--i/marvin/src/interpreter/interpreter.tcc53
1 files changed, 29 insertions, 24 deletions
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 T>
-class Interpreter::MemFunc<T, bool (T::*) (const Interpreter::Args &)> : public Func
+class Interpreter::MemFunc<T, void (T::*) (const Interpreter::Args &, bool)>
+: 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 T>
-class Interpreter::MemFunc<T, bool (T::*) (void)> : public Func
+template<class T, typename R>
+class Interpreter::MemFunc<T, R (T::*) (void)> : 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 T, typename A1>
-class Interpreter::MemFunc<T, bool (T::*) (A1)> : public Func
+template<class T, typename A1, typename R>
+class Interpreter::MemFunc<T, R (T::*) (A1)> : 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<typename meta::removeReference<A1>::type> (*i);
- return (i_.*f_) (a1);
+ if (!dryrun)
+ (i_.*f_) (a1);
}
};
/// Partially specialised for members functions taking two arguments.
-template<class T, typename A1, typename A2>
-class Interpreter::MemFunc<T, bool (T::*) (A1, A2)> : public Func
+template<class T, typename A1, typename A2, typename R>
+class Interpreter::MemFunc<T, R (T::*) (A1, A2)> : 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<typename meta::removeReference<A1>::type> (*i);
A2 a2 = any_cast<typename meta::removeReference<A2>::type> (*++i);
- return (i_.*f_) (a1, a2);
+ if (!dryrun)
+ (i_.*f_) (a1, a2);
}
};
/// Partially specialised for members functions taking three arguments.
-template<class T, typename A1, typename A2, typename A3>
-class Interpreter::MemFunc<T, bool (T::*) (A1, A2, A3)> : public Func
+template<class T, typename A1, typename A2, typename A3, typename R>
+class Interpreter::MemFunc<T, R (T::*) (A1, A2, A3)> : 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<T, bool (T::*) (A1, A2, A3)> : public Func
A1 a1 = any_cast<typename meta::removeReference<A1>::type> (*i);
A2 a2 = any_cast<typename meta::removeReference<A2>::type> (*++i);
A3 a3 = any_cast<typename meta::removeReference<A3>::type> (*++i);
- return (i_.*f_) (a1, a2, a3);
+ if (!dryrun)
+ (i_.*f_) (a1, a2, a3);
}
};