diff options
author | Josh Blum | 2013-07-30 20:59:41 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-30 20:59:41 -0700 |
commit | 17d636eec0ee0da346173066dd4f400a64e96c44 (patch) | |
tree | 719ec814b166e4d9c8fcb4f36413d95ba7070296 | |
parent | 3782b3a9a844d32a277adbbfad98bf64b4cb227c (diff) | |
download | sandhi-17d636eec0ee0da346173066dd4f400a64e96c44.tar.gz sandhi-17d636eec0ee0da346173066dd4f400a64e96c44.tar.bz2 sandhi-17d636eec0ee0da346173066dd4f400a64e96c44.zip |
gras: rename some factory functions
-rw-r--r-- | include/gras/detail/factory.hpp | 88 | ||||
-rw-r--r-- | include/gras/factory.hpp | 96 | ||||
-rw-r--r-- | lib/factory.cpp | 16 | ||||
-rw-r--r-- | python/gras/GRAS_Factory.i | 12 | ||||
-rw-r--r-- | python/gras/__init__.py | 2 | ||||
-rw-r--r-- | tests/example_module.py | 2 | ||||
-rw-r--r-- | tmpl/factory.tmpl.hpp | 16 | ||||
-rw-r--r-- | tmpl/factory_detail.tmpl.hpp | 8 |
8 files changed, 120 insertions, 120 deletions
diff --git a/include/gras/detail/factory.hpp b/include/gras/detail/factory.hpp index d1edf81..551ba9e 100644 --- a/include/gras/detail/factory.hpp +++ b/include/gras/detail/factory.hpp @@ -37,10 +37,10 @@ struct FactoryRegistryEntryImpl0 : FactoryRegistryEntry }; template <typename ReturnType> -void register_make(const std::string &name, ReturnType(*fcn)()) +void register_factory(const std::string &path, ReturnType(*fcn)()) { void *r = new FactoryRegistryEntryImpl0<ReturnType>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -61,10 +61,10 @@ struct FactoryRegistryEntryImpl1 : FactoryRegistryEntry }; template <typename ReturnType, typename A0> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &)) { void *r = new FactoryRegistryEntryImpl1<ReturnType, A0>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -85,10 +85,10 @@ struct FactoryRegistryEntryImpl2 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &)) { void *r = new FactoryRegistryEntryImpl2<ReturnType, A0, A1>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -109,10 +109,10 @@ struct FactoryRegistryEntryImpl3 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)) { void *r = new FactoryRegistryEntryImpl3<ReturnType, A0, A1, A2>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -133,10 +133,10 @@ struct FactoryRegistryEntryImpl4 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &)) { void *r = new FactoryRegistryEntryImpl4<ReturnType, A0, A1, A2, A3>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -157,10 +157,10 @@ struct FactoryRegistryEntryImpl5 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &)) { void *r = new FactoryRegistryEntryImpl5<ReturnType, A0, A1, A2, A3, A4>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -181,10 +181,10 @@ struct FactoryRegistryEntryImpl6 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)) { void *r = new FactoryRegistryEntryImpl6<ReturnType, A0, A1, A2, A3, A4, A5>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -205,10 +205,10 @@ struct FactoryRegistryEntryImpl7 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)) { void *r = new FactoryRegistryEntryImpl7<ReturnType, A0, A1, A2, A3, A4, A5, A6>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -229,10 +229,10 @@ struct FactoryRegistryEntryImpl8 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)) { void *r = new FactoryRegistryEntryImpl8<ReturnType, A0, A1, A2, A3, A4, A5, A6, A7>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -253,10 +253,10 @@ struct FactoryRegistryEntryImpl9 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &)) { void *r = new FactoryRegistryEntryImpl9<ReturnType, A0, A1, A2, A3, A4, A5, A6, A7, A8>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** @@ -277,62 +277,62 @@ struct FactoryRegistryEntryImpl10 : FactoryRegistryEntry }; template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> -void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &)) +void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &)) { void *r = new FactoryRegistryEntryImpl10<ReturnType, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } /*********************************************************************** * Templated make implementations **********************************************************************/ inline -Element *make(const std::string &name) +Element *make(const std::string &path) { PMCList args(0); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0> -Element *make(const std::string &name, const A0 &a0) +Element *make(const std::string &path, const A0 &a0) { PMCList args(1); args[0] = PMC_M(a0); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1> -Element *make(const std::string &name, const A0 &a0, const A1 &a1) +Element *make(const std::string &path, const A0 &a0, const A1 &a1) { PMCList args(2); args[0] = PMC_M(a0); args[1] = PMC_M(a1); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2) { PMCList args(3); args[0] = PMC_M(a0); args[1] = PMC_M(a1); args[2] = PMC_M(a2); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3) { PMCList args(4); args[0] = PMC_M(a0); args[1] = PMC_M(a1); args[2] = PMC_M(a2); args[3] = PMC_M(a3); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) { PMCList args(5); args[0] = PMC_M(a0); @@ -340,11 +340,11 @@ Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, args[2] = PMC_M(a2); args[3] = PMC_M(a3); args[4] = PMC_M(a4); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) { PMCList args(6); args[0] = PMC_M(a0); @@ -353,11 +353,11 @@ Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, args[3] = PMC_M(a3); args[4] = PMC_M(a4); args[5] = PMC_M(a5); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) { PMCList args(7); args[0] = PMC_M(a0); @@ -367,11 +367,11 @@ Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, args[4] = PMC_M(a4); args[5] = PMC_M(a5); args[6] = PMC_M(a6); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) { PMCList args(8); args[0] = PMC_M(a0); @@ -382,11 +382,11 @@ Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, args[5] = PMC_M(a5); args[6] = PMC_M(a6); args[7] = PMC_M(a7); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) { PMCList args(9); args[0] = PMC_M(a0); @@ -398,11 +398,11 @@ Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, args[6] = PMC_M(a6); args[7] = PMC_M(a7); args[8] = PMC_M(a8); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> -Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) +Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) { PMCList args(10); args[0] = PMC_M(a0); @@ -415,7 +415,7 @@ Element *make(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, args[7] = PMC_M(a7); args[8] = PMC_M(a8); args[9] = PMC_M(a9); - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } } diff --git a/include/gras/factory.hpp b/include/gras/factory.hpp index 9600586..f9403fa 100644 --- a/include/gras/factory.hpp +++ b/include/gras/factory.hpp @@ -17,7 +17,7 @@ namespace gras * - Call make() to create element from global factory. * * Example register a factory function: - * gras::Factory::register_make("/proj/my_block", &make_my_block); + * gras::Factory::register_factory("/proj/my_block", &make_my_block); * * Example call into the factory: * gras::Element *my_block = gras::Factory::make("/proj/my_block", arg0, arg1); @@ -27,7 +27,7 @@ struct GRAS_API Factory /******************************************************************* * Private registration hooks ******************************************************************/ - static void _register_make(const std::string &, void *); + static void _register_factory(const std::string &, void *); static Element *_handle_make(const std::string &, const PMCC &); }; @@ -35,73 +35,73 @@ struct GRAS_API Factory * Register API - don't look here, template magic, not helpful **********************************************************************/ template <typename ReturnType> -static void register_make(const std::string &name, ReturnType(*fcn)()); +static void register_factory(const std::string &path, ReturnType(*fcn)()); template <typename ReturnType, typename A0> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &)); template <typename ReturnType, typename A0, typename A1> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &)); template <typename ReturnType, typename A0, typename A1, typename A2> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &)); template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> -static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &)); +static void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &)); /*********************************************************************** * Make API - don't look here, template magic, not helpful **********************************************************************/ inline -static Element *make(const std::string &name); +static Element *make(const std::string &path); template <typename A0> -static Element *make(const std::string &name, const A0 &); +static Element *make(const std::string &path, const A0 &); template <typename A0, typename A1> -static Element *make(const std::string &name, const A0 &, const A1 &); +static Element *make(const std::string &path, const A0 &, const A1 &); template <typename A0, typename A1, typename A2> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &); template <typename A0, typename A1, typename A2, typename A3> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &); template <typename A0, typename A1, typename A2, typename A3, typename A4> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &); template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &); template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &); template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &); template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &); template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> -static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &); +static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &); } @@ -110,9 +110,9 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY(name, fcn) \ +#define GRAS_REGISTER_FACTORY(path, fcn) \ GRAS_STATIC_BLOCK(fcn) \ - {gras::register_make(name, &fcn);} + {gras::register_factory(path, &fcn);} /*! * Register a block's constructor into the factory: @@ -121,10 +121,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY0(name, type) \ +#define GRAS_REGISTER_FACTORY0(path, type) \ static gras::Element *make_ ## type() \ { return new type(); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -133,10 +133,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY1(name, type, A0) \ +#define GRAS_REGISTER_FACTORY1(path, type, A0) \ static gras::Element *make_ ## type(const A0 &a0) \ { return new type(a0); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -145,10 +145,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY2(name, type, A0, A1) \ +#define GRAS_REGISTER_FACTORY2(path, type, A0, A1) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1) \ { return new type(a0, a1); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -157,10 +157,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY3(name, type, A0, A1, A2) \ +#define GRAS_REGISTER_FACTORY3(path, type, A0, A1, A2) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2) \ { return new type(a0, a1, a2); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -169,10 +169,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY4(name, type, A0, A1, A2, A3) \ +#define GRAS_REGISTER_FACTORY4(path, type, A0, A1, A2, A3) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3) \ { return new type(a0, a1, a2, a3); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -181,10 +181,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY5(name, type, A0, A1, A2, A3, A4) \ +#define GRAS_REGISTER_FACTORY5(path, type, A0, A1, A2, A3, A4) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) \ { return new type(a0, a1, a2, a3, a4); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -193,10 +193,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY6(name, type, A0, A1, A2, A3, A4, A5) \ +#define GRAS_REGISTER_FACTORY6(path, type, A0, A1, A2, A3, A4, A5) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) \ { return new type(a0, a1, a2, a3, a4, a5); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -205,10 +205,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY7(name, type, A0, A1, A2, A3, A4, A5, A6) \ +#define GRAS_REGISTER_FACTORY7(path, type, A0, A1, A2, A3, A4, A5, A6) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) \ { return new type(a0, a1, a2, a3, a4, a5, a6); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -217,10 +217,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY8(name, type, A0, A1, A2, A3, A4, A5, A6, A7) \ +#define GRAS_REGISTER_FACTORY8(path, type, A0, A1, A2, A3, A4, A5, A6, A7) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) \ { return new type(a0, a1, a2, a3, a4, a5, a6, a7); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -229,10 +229,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY9(name, type, A0, A1, A2, A3, A4, A5, A6, A7, A8) \ +#define GRAS_REGISTER_FACTORY9(path, type, A0, A1, A2, A3, A4, A5, A6, A7, A8) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) \ { return new type(a0, a1, a2, a3, a4, a5, a6, a7, a8); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) /*! * Register a block's constructor into the factory: @@ -241,10 +241,10 @@ static Element *make(const std::string &name, const A0 &, const A1 &, const A2 & * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY10(name, type, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) \ +#define GRAS_REGISTER_FACTORY10(path, type, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) \ static gras::Element *make_ ## type(const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) \ { return new type(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); } \ - GRAS_REGISTER_FACTORY(name, make_##type) + GRAS_REGISTER_FACTORY(path, make_##type) #include <gras/detail/factory.hpp> diff --git a/lib/factory.cpp b/lib/factory.cpp index 6d9fe2c..7115197 100644 --- a/lib/factory.cpp +++ b/lib/factory.cpp @@ -36,22 +36,22 @@ static FactoryRegistryType &get_factory_registry(void) static boost::mutex mutex; -void Factory::_register_make(const std::string &name, void *entry) +void Factory::_register_factory(const std::string &path, void *entry) { boost::mutex::scoped_lock l(mutex); - if (get_factory_registry().count(name) != 0) + if (get_factory_registry().count(path) != 0) { - std::cerr << "Warning: Factory - function already registered for name: " + name << std::endl; + std::cerr << "Warning: Factory - function already registered for path: " + path << std::endl; } - get_factory_registry()[name].reset(reinterpret_cast<FactoryRegistryEntry *>(entry)); + get_factory_registry()[path].reset(reinterpret_cast<FactoryRegistryEntry *>(entry)); } -Element *Factory::_handle_make(const std::string &name, const PMCC &args) +Element *Factory::_handle_make(const std::string &path, const PMCC &args) { boost::mutex::scoped_lock l(mutex); - if (get_factory_registry().count(name) == 0) + if (get_factory_registry().count(path) == 0) { - throw std::invalid_argument("Factory - no function registered for name: " + name); + throw std::invalid_argument("Factory - no function registered for path: " + path); } - return get_factory_registry()[name]->make(args); + return get_factory_registry()[path]->make(args); } diff --git a/python/gras/GRAS_Factory.i b/python/gras/GRAS_Factory.i index eca9d2e..2740b39 100644 --- a/python/gras/GRAS_Factory.i +++ b/python/gras/GRAS_Factory.i @@ -9,7 +9,7 @@ namespace gras { - %ignore Factory::register_make; + %ignore Factory::register_factory; %ignore Factory::make; } @@ -31,17 +31,17 @@ namespace gras #TODO we need to register this into the real factory _py_factory = dict() -def register_make(name, fcn): +def register_factory(path, fcn): #TODO we need to register this into the real factory - _py_factory[name] = fcn + _py_factory[path] = fcn -def make(name, *args, **kwargs): +def make(path, *args, **kwargs): #first try the local to python py factory #TODO real factory - if name in _py_factory: return _py_factory[name](*args, **kwargs) + if path in _py_factory: return _py_factory[path](*args, **kwargs) from PMC import PMC_M pmcargs = PMC_M(list(args)) - return Factory._handle_make(name, pmcargs) + return Factory._handle_make(path, pmcargs) %} diff --git a/python/gras/__init__.py b/python/gras/__init__.py index da3567f..884182c 100644 --- a/python/gras/__init__.py +++ b/python/gras/__init__.py @@ -10,7 +10,7 @@ from GRAS_SBuffer import SBufferConfig, SBuffer from GRAS_Tags import Tag, StreamTag, PacketMsg from GRAS_TimeTag import TimeTag from GRAS_Element import Element -from GRAS_Factory import make, register_make +from GRAS_Factory import make, register_factory import GRAS_Block import GRAS_HierBlock import GRAS_TopBlock diff --git a/tests/example_module.py b/tests/example_module.py index fbf0b45..3ef73dd 100644 --- a/tests/example_module.py +++ b/tests/example_module.py @@ -13,4 +13,4 @@ class MyBlock(gras.Block): def get_num(self): return 42 -gras.register_make("/tests/my_block1", MyBlock) +gras.register_factory("/tests/my_block1", MyBlock) diff --git a/tmpl/factory.tmpl.hpp b/tmpl/factory.tmpl.hpp index 148a851..a8f0b5d 100644 --- a/tmpl/factory.tmpl.hpp +++ b/tmpl/factory.tmpl.hpp @@ -17,7 +17,7 @@ namespace gras * - Call make() to create element from global factory. * * Example register a factory function: - * gras::Factory::register_make("/proj/my_block", &make_my_block); + * gras::Factory::register_factory("/proj/my_block", &make_my_block); * * Example call into the factory: * gras::Element *my_block = gras::Factory::make("/proj/my_block", arg0, arg1); @@ -27,7 +27,7 @@ struct GRAS_API Factory /******************************************************************* * Private registration hooks ******************************************************************/ - static void _register_make(const std::string &, void *); + static void _register_factory(const std::string &, void *); static Element *_handle_make(const std::string &, const PMCC &); }; @@ -36,7 +36,7 @@ struct GRAS_API Factory **********************************************************************/ #for $NARGS in range($MAX_ARGS) template <typename ReturnType, $expand('typename A%d', $NARGS)> -static void register_make(const std::string &name, ReturnType(*fcn)($expand('const A%d &', $NARGS))); +static void register_factory(const std::string &path, ReturnType(*fcn)($expand('const A%d &', $NARGS))); #end for /*********************************************************************** @@ -44,7 +44,7 @@ static void register_make(const std::string &name, ReturnType(*fcn)($expand('con **********************************************************************/ #for $NARGS in range($MAX_ARGS) template <$expand('typename A%d', $NARGS)> -static Element *make(const std::string &name, $expand('const A%d &', $NARGS)); +static Element *make(const std::string &path, $expand('const A%d &', $NARGS)); #end for } @@ -54,9 +54,9 @@ static Element *make(const std::string &name, $expand('const A%d &', $NARGS)); * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY(name, fcn) \ +#define GRAS_REGISTER_FACTORY(path, fcn) \ GRAS_STATIC_BLOCK(fcn) \ - {gras::register_make(name, &fcn);} + {gras::register_factory(path, &fcn);} #for $NARGS in range($MAX_ARGS) /*! @@ -66,10 +66,10 @@ static Element *make(const std::string &name, $expand('const A%d &', $NARGS)); * Declare this macro at the global scope in a cpp file. * The block will register at static initialization time. */ -#define GRAS_REGISTER_FACTORY$(NARGS)(name, type, $expand('A%d', $NARGS)) \ +#define GRAS_REGISTER_FACTORY$(NARGS)(path, type, $expand('A%d', $NARGS)) \ static gras::Element *make_ $('##') type($expand('const A%d &a%d', $NARGS)) \ { return new type($expand('a%d', $NARGS)); } \ - GRAS_REGISTER_FACTORY(name, make_$('##')type) + GRAS_REGISTER_FACTORY(path, make_$('##')type) #end for #include <gras/detail/factory.hpp> diff --git a/tmpl/factory_detail.tmpl.hpp b/tmpl/factory_detail.tmpl.hpp index 8712db4..660a690 100644 --- a/tmpl/factory_detail.tmpl.hpp +++ b/tmpl/factory_detail.tmpl.hpp @@ -38,10 +38,10 @@ struct FactoryRegistryEntryImpl$(NARGS) : FactoryRegistryEntry }; template <typename ReturnType, $expand('typename A%d', $NARGS)> -void register_make(const std::string &name, ReturnType(*fcn)($expand('const A%d &', $NARGS))) +void register_factory(const std::string &path, ReturnType(*fcn)($expand('const A%d &', $NARGS))) { void *r = new FactoryRegistryEntryImpl$(NARGS)<ReturnType, $expand('A%d', $NARGS)>(fcn); - Factory::_register_make(name, r); + Factory::_register_factory(path, r); } #end for @@ -50,13 +50,13 @@ void register_make(const std::string &name, ReturnType(*fcn)($expand('const A%d **********************************************************************/ #for $NARGS in range($MAX_ARGS) template <$expand('typename A%d', $NARGS)> -Element *make(const std::string &name, $expand('const A%d &a%d', $NARGS)) +Element *make(const std::string &path, $expand('const A%d &a%d', $NARGS)) { PMCList args($NARGS); #for $i in range($NARGS): args[$i] = PMC_M(a$i); #end for - return Factory::_handle_make(name, PMC_M(args)); + return Factory::_handle_make(path, PMC_M(args)); } #end for |