// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. #ifndef INCLUDED_GRAS_FACTORY_HPP #define INCLUDED_GRAS_FACTORY_HPP #include #include #include #include /*! * Register a block's factory function: * 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) \ GRAS_STATIC_BLOCK(fcn) \ {gras::Factory::register_make(name, &fcn);} namespace gras { /*! * Element factory: * - Register factory functions into the global factory. * - Call make() to create element from global factory. * * Example register a factory function: * gras::Factory::register_make("/proj/my_block", &make_my_block); * * Example call into the factory: * gras::Element *my_block = gras::Factory::make("/proj/my_block", arg0, arg1); */ struct GRAS_API Factory { /******************************************************************* * Register API - don't look here, template magic, not helpful ******************************************************************/ template static void register_make(const std::string &name, ReturnType(*fcn)()); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &)); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &)); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &)); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &)); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)); template static void register_make(const std::string &name, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)); template 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 &)); template 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 &)); template 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 &)); /******************************************************************* * Make API - don't look here, template magic, not helpful ******************************************************************/; inline static Element *make(const std::string &name); template static Element *make(const std::string &name, const A0 &); template static Element *make(const std::string &name, const A0 &, const A1 &); template static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &); template static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &); template static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &); template static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &); template static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &); template static Element *make(const std::string &name, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &); template 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 &); template 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 &); /******************************************************************* * Private registration hooks ******************************************************************/ static void _register_make(const std::string &, void *); static Element *_handle_make(const std::string &, const PMCC &); }; } #include #endif /*INCLUDED_GRAS_FACTORY_HPP*/