From a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Jul 2013 19:20:35 -0700 Subject: gras: added arg check with nice warning to callable and factory --- tmpl/callable_detail.tmpl.hpp | 5 +++-- tmpl/factory_detail.tmpl.hpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'tmpl') diff --git a/tmpl/callable_detail.tmpl.hpp b/tmpl/callable_detail.tmpl.hpp index 65750e7..656b695 100644 --- a/tmpl/callable_detail.tmpl.hpp +++ b/tmpl/callable_detail.tmpl.hpp @@ -16,6 +16,7 @@ struct GRAS_API CallableRegistryEntry CallableRegistryEntry(void); virtual ~CallableRegistryEntry(void); virtual PMCC call(const PMCC &args) = 0; + void arg_check(const PMCList &args, const size_t nargs); }; #for $NARGS in range($MAX_ARGS) @@ -31,7 +32,7 @@ struct CallableRegistryEntryImpl$(NARGS) : CallableRegistryEntry PMCC call(const PMCC &args) { const PMCList &a = args.as(); - if (a.size() < $NARGS) throw a; + this->arg_check(a, $NARGS); return PMC_M((_obj->*_fcn)($expand('a[%d].safe_as()', $NARGS))); } ClassType *_obj; Fcn _fcn; @@ -54,7 +55,7 @@ struct CallableRegistryEntryImplVoid$(NARGS) : CallableRegistryEntry PMCC call(const PMCC &args) { const PMCList &a = args.as(); - if (a.size() < $NARGS) throw a; + this->arg_check(a, $NARGS); (_obj->*_fcn)($expand('a[%d].safe_as()', $NARGS)); return PMCC(); } ClassType *_obj; Fcn _fcn; diff --git a/tmpl/factory_detail.tmpl.hpp b/tmpl/factory_detail.tmpl.hpp index 87a0756..ea30235 100644 --- a/tmpl/factory_detail.tmpl.hpp +++ b/tmpl/factory_detail.tmpl.hpp @@ -16,6 +16,7 @@ struct GRAS_API FactoryRegistryEntry FactoryRegistryEntry(void); virtual ~FactoryRegistryEntry(void); virtual Element *make(const PMCC &args) = 0; + void arg_check(const PMCList &args, const size_t nargs); }; #for $NARGS in range($MAX_ARGS) @@ -30,7 +31,7 @@ struct FactoryRegistryEntryImpl$(NARGS) : FactoryRegistryEntry Element *make(const PMCC &args) { const PMCList &a = args.as(); - if (a.size() < $NARGS) throw a; + this->arg_check(a, $NARGS); return _fcn($expand('a[%d].safe_as()', $NARGS)); } Fcn _fcn; -- cgit