From 080f4918a072c8677c52d33eda2c32d087889209 Mon Sep 17 00:00:00 2001 From: haller Date: Sun, 21 May 2006 20:14:02 +0000 Subject: * Ajout d'une fonction exists dans Interpreter (Ni) * Patch de InterpreterParser::call, vérifie que la fonction _postcall existe avant d'essayer de la lancer * Refonte de test_proto en utilisant un AnyList dans TestProto::send --- i/marvin/src/interpreter/interpreter.cc | 9 +++++++++ i/marvin/src/interpreter/interpreter.hh | 2 ++ i/marvin/src/interpreter/interpreter_parser.cc | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'i/marvin/src/interpreter') diff --git a/i/marvin/src/interpreter/interpreter.cc b/i/marvin/src/interpreter/interpreter.cc index a160002..bbf4767 100644 --- a/i/marvin/src/interpreter/interpreter.cc +++ b/i/marvin/src/interpreter/interpreter.cc @@ -54,6 +54,15 @@ Interpreter::add (const std::string &s, Func *f) add (s, f, ""); } +/// Test if a function is defined. +bool +Interpreter::exists (const std::string &s) const +{ + Funcs::const_iterator i; + i = funcs_.find (s); + return i != funcs_.end (); +} + /// Call a function by name. void Interpreter::call (const std::string &s, const Args &a, diff --git a/i/marvin/src/interpreter/interpreter.hh b/i/marvin/src/interpreter/interpreter.hh index 1f6e688..3341ea1 100644 --- a/i/marvin/src/interpreter/interpreter.hh +++ b/i/marvin/src/interpreter/interpreter.hh @@ -69,6 +69,8 @@ class Interpreter void add (const std::string &s, Func *f, const std::string &desc); /// Add a function without description, Interpreter owns f. void add (const std::string &s, Func *f); + /// Test if a function is defined. + bool exists (const std::string &s) const; /// Call a function by name. void call (const std::string &s, const Args &a, bool dryrun = false) const; diff --git a/i/marvin/src/interpreter/interpreter_parser.cc b/i/marvin/src/interpreter/interpreter_parser.cc index 2a3f54b..f10e8ec 100644 --- a/i/marvin/src/interpreter/interpreter_parser.cc +++ b/i/marvin/src/interpreter/interpreter_parser.cc @@ -37,6 +37,7 @@ void InterpreterParser::call (const std::string &id, AnyList &args) { interpreter_.call (id, args, dryrun_); - interpreter_.call ("_postcall", AnyList (), dryrun_); + if (interpreter_.exists ("_postcall")) + interpreter_.call ("_postcall", AnyList (), dryrun_); } -- cgit v1.2.3