// This file is distributed under the BSD License. // See "license.txt" for details. // Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com #include #ifndef BOOST_PP_IS_ITERATING #ifndef CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_ #define CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_ #include #include #include #define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) #define BOOST_PP_FILENAME_1 #include BOOST_PP_ITERATE() # endif namespace chaiscript { /// \brief Generates a constructor function for use with ChaiScript /// /// \tparam T The signature of the constructor to generate. In the form of: ClassType (ParamType1, ParamType2, ...) /// /// Example: /// \code /// chaiscript::ChaiScript chai; /// // Create a new function that creates a MyClass object using the (int, float) constructor /// // and call that function "MyClass" so that it appears as a normal constructor to the user. /// chai.add(constructor(), "MyClass"); /// \endcode template Proxy_Function constructor() { T *f = 0; return (dispatch::detail::build_constructor_(f)); } } #else # define n BOOST_PP_ITERATION() namespace chaiscript { namespace dispatch { namespace detail { /** * A constructor function, used for creating a new object * of a given type with a given set of params */ template std::shared_ptr constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) { return std::shared_ptr(new Class( BOOST_PP_ENUM_PARAMS(n, p) )); } /** * Helper function for build a constructor function * example: * dispatchengine.register_function(build_constructor, "MyClass"); * \todo See if it is possible to make this not be a variadic function */ template Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param))) { typedef std::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); return Proxy_Function(new Proxy_Function_Impl(boost::function(&(constructor_)))); } } } } #undef n #endif