From fc98eaf2a00e000841cb16d962f83c118e4824c2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 13 Jul 2013 12:58:22 -0700 Subject: gras: added comments and renamed tmpl args --- tmpl/callable.tmpl.hpp | 16 ++++++++-------- tmpl/callable_detail.tmpl.hpp | 32 ++++++++++++++++---------------- tmpl/factory.tmpl.hpp | 8 ++++---- tmpl/factory_detail.tmpl.hpp | 16 ++++++++-------- tmpl/regen_all.sh | 9 +++++++++ 5 files changed, 45 insertions(+), 36 deletions(-) mode change 100644 => 100755 tmpl/regen_all.sh (limited to 'tmpl') diff --git a/tmpl/callable.tmpl.hpp b/tmpl/callable.tmpl.hpp index 1c73910..900bae4 100644 --- a/tmpl/callable.tmpl.hpp +++ b/tmpl/callable.tmpl.hpp @@ -57,11 +57,11 @@ protected: ******************************************************************/ protected: #for $NARGS in range($MAX_ARGS) - template - void register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const Arg%d &', $NARGS))); + template + void register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const A%d &', $NARGS))); - template - void register_call(const std::string &name, void(ClassType::*fcn)($expand('const Arg%d &', $NARGS))); + template + void register_call(const std::string &name, void(ClassType::*fcn)($expand('const A%d &', $NARGS))); #end for /******************************************************************* @@ -69,11 +69,11 @@ protected: ******************************************************************/ public: #for $NARGS in range($MAX_ARGS) - template - ReturnType x(const std::string &name, $expand('const Arg%d &', $NARGS)); + template + ReturnType x(const std::string &name, $expand('const A%d &', $NARGS)); - template <$expand('typename Arg%d', $NARGS)> - void x(const std::string &name, $expand('const Arg%d &', $NARGS)); + template <$expand('typename A%d', $NARGS)> + void x(const std::string &name, $expand('const A%d &', $NARGS)); #end for /******************************************************************* diff --git a/tmpl/callable_detail.tmpl.hpp b/tmpl/callable_detail.tmpl.hpp index ee11815..65750e7 100644 --- a/tmpl/callable_detail.tmpl.hpp +++ b/tmpl/callable_detail.tmpl.hpp @@ -22,49 +22,49 @@ struct GRAS_API CallableRegistryEntry /*********************************************************************** * Registration for return with $NARGS args **********************************************************************/ -template +template struct CallableRegistryEntryImpl$(NARGS) : CallableRegistryEntry { - typedef ReturnType(ClassType::*Fcn)($expand('const Arg%d &', $NARGS)); + typedef ReturnType(ClassType::*Fcn)($expand('const A%d &', $NARGS)); CallableRegistryEntryImpl$(NARGS)(ClassType *obj, Fcn fcn): _obj(obj), _fcn(fcn){} PMCC call(const PMCC &args) { const PMCList &a = args.as(); if (a.size() < $NARGS) throw a; - return PMC_M((_obj->*_fcn)($expand('a[%d].safe_as()', $NARGS))); + return PMC_M((_obj->*_fcn)($expand('a[%d].safe_as()', $NARGS))); } ClassType *_obj; Fcn _fcn; }; -template -void Callable::register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const Arg%d &', $NARGS))) +template +void Callable::register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const A%d &', $NARGS))) { ClassType *obj = dynamic_cast(this); - void *fr = new CallableRegistryEntryImpl$(NARGS)(obj, fcn); + void *fr = new CallableRegistryEntryImpl$(NARGS)(obj, fcn); _register_call(name, fr); } -template +template struct CallableRegistryEntryImplVoid$(NARGS) : CallableRegistryEntry { - typedef void(ClassType::*Fcn)($expand('const Arg%d &', $NARGS)); + typedef void(ClassType::*Fcn)($expand('const A%d &', $NARGS)); CallableRegistryEntryImplVoid$(NARGS)(ClassType *obj, Fcn fcn): _obj(obj), _fcn(fcn){} PMCC call(const PMCC &args) { const PMCList &a = args.as(); if (a.size() < $NARGS) throw a; - (_obj->*_fcn)($expand('a[%d].safe_as()', $NARGS)); return PMCC(); + (_obj->*_fcn)($expand('a[%d].safe_as()', $NARGS)); return PMCC(); } ClassType *_obj; Fcn _fcn; }; -template -void Callable::register_call(const std::string &name, void(ClassType::*fcn)($expand('const Arg%d &', $NARGS))) +template +void Callable::register_call(const std::string &name, void(ClassType::*fcn)($expand('const A%d &', $NARGS))) { ClassType *obj = dynamic_cast(this); - void *fr = new CallableRegistryEntryImplVoid$(NARGS)(obj, fcn); + void *fr = new CallableRegistryEntryImplVoid$(NARGS)(obj, fcn); _register_call(name, fr); } @@ -73,8 +73,8 @@ void Callable::register_call(const std::string &name, void(ClassType::*fcn)($exp /*********************************************************************** * Call implementations with $NARGS args **********************************************************************/ -template -ReturnType Callable::x(const std::string &name, $expand('const Arg%d &a%d', $NARGS)) +template +ReturnType Callable::x(const std::string &name, $expand('const A%d &a%d', $NARGS)) { PMCList args($NARGS); #for $i in range($NARGS): @@ -84,8 +84,8 @@ ReturnType Callable::x(const std::string &name, $expand('const Arg%d &a%d', $NAR return r.safe_as(); } -template <$expand('typename Arg%d', $NARGS)> -void Callable::x(const std::string &name, $expand('const Arg%d &a%d', $NARGS)) +template <$expand('typename A%d', $NARGS)> +void Callable::x(const std::string &name, $expand('const A%d &a%d', $NARGS)) { PMCList args($NARGS); #for $i in range($NARGS): diff --git a/tmpl/factory.tmpl.hpp b/tmpl/factory.tmpl.hpp index 66f3e3e..a9c9820 100644 --- a/tmpl/factory.tmpl.hpp +++ b/tmpl/factory.tmpl.hpp @@ -37,16 +37,16 @@ struct GRAS_API Factory * Register API - don't look here, template magic, not helpful ******************************************************************/ #for $NARGS in range($MAX_ARGS) - template - static void register_make(const std::string &name, ReturnType(*fcn)($expand('const Arg%d &', $NARGS))); + template + static void register_make(const std::string &name, ReturnType(*fcn)($expand('const A%d &', $NARGS))); #end for /******************************************************************* * Make API - don't look here, template magic, not helpful ******************************************************************/; #for $NARGS in range($MAX_ARGS) - template <$expand('typename Arg%d', $NARGS)> - static Element *make(const std::string &name, $expand('const Arg%d &', $NARGS)); + template <$expand('typename A%d', $NARGS)> + static Element *make(const std::string &name, $expand('const A%d &', $NARGS)); #end for /******************************************************************* diff --git a/tmpl/factory_detail.tmpl.hpp b/tmpl/factory_detail.tmpl.hpp index 1238c38..87a0756 100644 --- a/tmpl/factory_detail.tmpl.hpp +++ b/tmpl/factory_detail.tmpl.hpp @@ -22,24 +22,24 @@ struct GRAS_API FactoryRegistryEntry /*********************************************************************** * Templated registration - $NARGS args **********************************************************************/ -template +template struct FactoryRegistryEntryImpl$(NARGS) : FactoryRegistryEntry { - typedef ReturnType(*Fcn)($expand('const Arg%d &', $NARGS)); + typedef ReturnType(*Fcn)($expand('const A%d &', $NARGS)); FactoryRegistryEntryImpl$(NARGS)(Fcn fcn):_fcn(fcn){} Element *make(const PMCC &args) { const PMCList &a = args.as(); if (a.size() < $NARGS) throw a; - return _fcn($expand('a[%d].safe_as()', $NARGS)); + return _fcn($expand('a[%d].safe_as()', $NARGS)); } Fcn _fcn; }; -template -void Factory::register_make(const std::string &name, ReturnType(*fcn)($expand('const Arg%d &', $NARGS))) +template +void Factory::register_make(const std::string &name, ReturnType(*fcn)($expand('const A%d &', $NARGS))) { - void *r = new FactoryRegistryEntryImpl$(NARGS)(fcn); + void *r = new FactoryRegistryEntryImpl$(NARGS)(fcn); Factory::_register_make(name, r); } @@ -48,8 +48,8 @@ void Factory::register_make(const std::string &name, ReturnType(*fcn)($expand('c * Templated make implementations **********************************************************************/ #for $NARGS in range($MAX_ARGS) -template <$expand('typename Arg%d', $NARGS)> -Element *Factory::make(const std::string &name, $expand('const Arg%d &a%d', $NARGS)) +template <$expand('typename A%d', $NARGS)> +Element *Factory::make(const std::string &name, $expand('const A%d &a%d', $NARGS)) { PMCList args($NARGS); #for $i in range($NARGS): diff --git a/tmpl/regen_all.sh b/tmpl/regen_all.sh old mode 100644 new mode 100755 index f9f4c95..53886c9 --- a/tmpl/regen_all.sh +++ b/tmpl/regen_all.sh @@ -1,5 +1,14 @@ #!/bin/bash +# This script generates the multi-argument template code +# for the callable and factory interfaces. +# This is the magic that makes the API calls +# so natural to call into as a C++ client app. +# This script is manually run when the source tmpl files are changed. +# And the generated sources are checked in. +# This way, the build system does not generate public headers. +# And the build system does not depend on Cheetah templates. + SCRIPT="`readlink -e $0`" SCRIPTPATH="`dirname $SCRIPT`" DEST=${SCRIPTPATH}/../include/gras -- cgit