summaryrefslogtreecommitdiff
path: root/tmpl
diff options
context:
space:
mode:
authorJosh Blum2013-07-13 12:58:22 -0700
committerJosh Blum2013-07-13 12:58:22 -0700
commitfc98eaf2a00e000841cb16d962f83c118e4824c2 (patch)
tree1c3fc6f13d92e79942f2b050c189f44109e676ab /tmpl
parent92c8b4646d77d569480d7c3120a00df6a9645aba (diff)
downloadsandhi-fc98eaf2a00e000841cb16d962f83c118e4824c2.tar.gz
sandhi-fc98eaf2a00e000841cb16d962f83c118e4824c2.tar.bz2
sandhi-fc98eaf2a00e000841cb16d962f83c118e4824c2.zip
gras: added comments and renamed tmpl args
Diffstat (limited to 'tmpl')
-rw-r--r--tmpl/callable.tmpl.hpp16
-rw-r--r--tmpl/callable_detail.tmpl.hpp32
-rw-r--r--tmpl/factory.tmpl.hpp8
-rw-r--r--tmpl/factory_detail.tmpl.hpp16
-rwxr-xr-x[-rw-r--r--]tmpl/regen_all.sh9
5 files changed, 45 insertions, 36 deletions
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 <typename ClassType, typename ReturnType, $expand('typename Arg%d', $NARGS)>
- void register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const Arg%d &', $NARGS)));
+ template <typename ClassType, typename ReturnType, $expand('typename A%d', $NARGS)>
+ void register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const A%d &', $NARGS)));
- template <typename ClassType, $expand('typename Arg%d', $NARGS)>
- void register_call(const std::string &name, void(ClassType::*fcn)($expand('const Arg%d &', $NARGS)));
+ template <typename ClassType, $expand('typename A%d', $NARGS)>
+ 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 <typename ReturnType, $expand('typename Arg%d', $NARGS)>
- ReturnType x(const std::string &name, $expand('const Arg%d &', $NARGS));
+ template <typename ReturnType, $expand('typename A%d', $NARGS)>
+ 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 <typename ClassType, typename ReturnType, $expand('typename Arg%d', $NARGS)>
+template <typename ClassType, typename ReturnType, $expand('typename A%d', $NARGS)>
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<PMCList>();
if (a.size() < $NARGS) throw a;
- return PMC_M((_obj->*_fcn)($expand('a[%d].safe_as<Arg%d>()', $NARGS)));
+ return PMC_M((_obj->*_fcn)($expand('a[%d].safe_as<A%d>()', $NARGS)));
}
ClassType *_obj; Fcn _fcn;
};
-template <typename ClassType, typename ReturnType, $expand('typename Arg%d', $NARGS)>
-void Callable::register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const Arg%d &', $NARGS)))
+template <typename ClassType, typename ReturnType, $expand('typename A%d', $NARGS)>
+void Callable::register_call(const std::string &name, ReturnType(ClassType::*fcn)($expand('const A%d &', $NARGS)))
{
ClassType *obj = dynamic_cast<ClassType *>(this);
- void *fr = new CallableRegistryEntryImpl$(NARGS)<ClassType, ReturnType, $expand('Arg%d', $NARGS)>(obj, fcn);
+ void *fr = new CallableRegistryEntryImpl$(NARGS)<ClassType, ReturnType, $expand('A%d', $NARGS)>(obj, fcn);
_register_call(name, fr);
}
-template <typename ClassType, $expand('typename Arg%d', $NARGS)>
+template <typename ClassType, $expand('typename A%d', $NARGS)>
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<PMCList>();
if (a.size() < $NARGS) throw a;
- (_obj->*_fcn)($expand('a[%d].safe_as<Arg%d>()', $NARGS)); return PMCC();
+ (_obj->*_fcn)($expand('a[%d].safe_as<A%d>()', $NARGS)); return PMCC();
}
ClassType *_obj; Fcn _fcn;
};
-template <typename ClassType, $expand('typename Arg%d', $NARGS)>
-void Callable::register_call(const std::string &name, void(ClassType::*fcn)($expand('const Arg%d &', $NARGS)))
+template <typename ClassType, $expand('typename A%d', $NARGS)>
+void Callable::register_call(const std::string &name, void(ClassType::*fcn)($expand('const A%d &', $NARGS)))
{
ClassType *obj = dynamic_cast<ClassType *>(this);
- void *fr = new CallableRegistryEntryImplVoid$(NARGS)<ClassType, $expand('Arg%d', $NARGS)>(obj, fcn);
+ void *fr = new CallableRegistryEntryImplVoid$(NARGS)<ClassType, $expand('A%d', $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 <typename ReturnType, $expand('typename Arg%d', $NARGS)>
-ReturnType Callable::x(const std::string &name, $expand('const Arg%d &a%d', $NARGS))
+template <typename ReturnType, $expand('typename A%d', $NARGS)>
+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<ReturnType>();
}
-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 <typename ReturnType, $expand('typename Arg%d', $NARGS)>
- static void register_make(const std::string &name, ReturnType(*fcn)($expand('const Arg%d &', $NARGS)));
+ template <typename ReturnType, $expand('typename A%d', $NARGS)>
+ 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 <typename ReturnType, $expand('typename Arg%d', $NARGS)>
+template <typename ReturnType, $expand('typename A%d', $NARGS)>
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<PMCList>();
if (a.size() < $NARGS) throw a;
- return _fcn($expand('a[%d].safe_as<Arg%d>()', $NARGS));
+ return _fcn($expand('a[%d].safe_as<A%d>()', $NARGS));
}
Fcn _fcn;
};
-template <typename ReturnType, $expand('typename Arg%d', $NARGS)>
-void Factory::register_make(const std::string &name, ReturnType(*fcn)($expand('const Arg%d &', $NARGS)))
+template <typename ReturnType, $expand('typename A%d', $NARGS)>
+void Factory::register_make(const std::string &name, ReturnType(*fcn)($expand('const A%d &', $NARGS)))
{
- void *r = new FactoryRegistryEntryImpl$(NARGS)<ReturnType, $expand('Arg%d', $NARGS)>(fcn);
+ void *r = new FactoryRegistryEntryImpl$(NARGS)<ReturnType, $expand('A%d', $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
index f9f4c95..53886c9 100644..100755
--- 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