summaryrefslogtreecommitdiff
path: root/i/marvin
diff options
context:
space:
mode:
authorschodet2006-04-02 17:23:53 +0000
committerschodet2006-04-02 17:23:53 +0000
commitc425ae7693b604c190d3904e7ef965f93d34edee (patch)
tree4ce709554b2c0d2e872a0da6c903de77765ee02c /i/marvin
parentc927f32a735e1600cf6b50a315d204963cf5877e (diff)
Support des fonctions qui ne retournent pas de bool.
Support du dry run.
Diffstat (limited to 'i/marvin')
-rw-r--r--i/marvin/src/interpreter/interpreter.cc7
-rw-r--r--i/marvin/src/interpreter/interpreter.hh5
-rw-r--r--i/marvin/src/interpreter/interpreter.tcc53
-rw-r--r--i/marvin/src/interpreter/test_interpreter.cc16
4 files changed, 43 insertions, 38 deletions
diff --git a/i/marvin/src/interpreter/interpreter.cc b/i/marvin/src/interpreter/interpreter.cc
index 4b034e3..a7f905c 100644
--- a/i/marvin/src/interpreter/interpreter.cc
+++ b/i/marvin/src/interpreter/interpreter.cc
@@ -47,8 +47,9 @@ Interpreter::add (const std::string &s, Func *f)
}
/// Call a function by name.
-bool
-Interpreter::call (const std::string &s, const Args &a) const
+void
+Interpreter::call (const std::string &s, const Args &a,
+ bool dryrun/*false*/) const
{
Funcs::const_iterator i;
i = funcs_.find (s);
@@ -56,7 +57,7 @@ Interpreter::call (const std::string &s, const Args &a) const
throw std::runtime_error ("function \'" + s + "\' does not exist");
try
{
- return (*i->second) (a);
+ (*i->second) (a, dryrun);
}
catch (const std::exception &e)
{
diff --git a/i/marvin/src/interpreter/interpreter.hh b/i/marvin/src/interpreter/interpreter.hh
index 729f321..169e0f2 100644
--- a/i/marvin/src/interpreter/interpreter.hh
+++ b/i/marvin/src/interpreter/interpreter.hh
@@ -44,7 +44,7 @@ class Interpreter
{ }
/// Called on function invocation, getting the argument list and
/// returning true on success.
- virtual bool operator() (const Args &) = 0;
+ virtual void operator() (const Args &, bool dryrun) = 0;
};
private:
/// Func class construction helper.
@@ -61,7 +61,8 @@ class Interpreter
/// Add a function, Interpreter owns f.
void add (const std::string &s, Func *f);
/// Call a function by name.
- bool call (const std::string &s, const Args &a) const;
+ void call (const std::string &s, const Args &a,
+ bool dryrun = false) const;
/// Take all the template sophistications out of the programmer hands.
template<class T, typename F>
static Func *memFunc (T &i, F f);
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);
}
};
diff --git a/i/marvin/src/interpreter/test_interpreter.cc b/i/marvin/src/interpreter/test_interpreter.cc
index 99a9ad9..8c2eb88 100644
--- a/i/marvin/src/interpreter/test_interpreter.cc
+++ b/i/marvin/src/interpreter/test_interpreter.cc
@@ -32,30 +32,28 @@ class TestInterpreter
{
Interpreter t;
public:
- bool funcA (const Interpreter::Args &a)
+ void funcA (const Interpreter::Args &a, bool dryrun)
{
- std::cout << " a " << a << std::endl;
- return true;
+ if (!dryrun)
+ std::cout << " a " << a << std::endl;
}
bool funcB (void)
{
std::cout << " b ( )" << std::endl;
return true;
}
- bool funcC (int i)
+ int funcC (int i)
{
std::cout << " c ( " << i << " )" << std::endl;
- return true;
+ return 0;
}
- bool funcD (const std::string &s)
+ void funcD (const std::string &s)
{
std::cout << " d ( " << s << " )" << std::endl;
- return true;
}
- bool funcE (int i, const std::string &s, double d)
+ void funcE (int i, const std::string &s, double d)
{
std::cout << " e ( " << i << ' ' << s << ' ' << d << " )" << std::endl;
- return true;
}
void call (const std::string &s, const Interpreter::Args &a)
{