// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and // distribute this software is granted provided this copyright notice appears // in all copies. This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // The author gratefully acknowleges the support of Dragon Systems, Inc., in // producing this work. // // This file was generated for %d-argument constructors by gen_init_function.python #ifndef INIT_FUNCTION_DWA052000_H_ # define INIT_FUNCTION_DWA052000_H_ # include "pyconfig.h" # include "functions.h" # include "signatures.h" # include namespace python { namespace detail { // parameter_traits - so far, this is a way to pass a const T& when we can be // sure T is not a reference type, and a raw T otherwise. This should be // rolled into boost::call_traits. Ordinarily, parameter_traits would be // written: // // template struct parameter_traits // { // typedef const T& const_reference; // }; // // template struct parameter_traits // { // typedef T& const_reference; // }; // // template <> struct parameter_traits // { // typedef void const_reference; // }; // // ...but since we can't partially specialize on reference types, we need this // long-winded but equivalent incantation. // const_ref_selector -- an implementation detail of parameter_traits (below). This uses // the usual "poor man's partial specialization" hack for MSVC. template struct const_ref_selector { template struct const_ref { typedef const T& type; }; }; template <> struct const_ref_selector { template struct const_ref { typedef T type; }; }; # ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable: 4181) # endif // BOOST_MSVC template struct parameter_traits { private: typedef const_ref_selector::value> selector; public: typedef typename selector::template const_ref::type const_reference; }; # ifdef BOOST_MSVC # pragma warning(pop) # endif // BOOST_MSVC // Full spcialization for void template <> struct parameter_traits { typedef void const_reference; }; template class reference_parameter { typedef typename parameter_traits::const_reference const_reference; public: reference_parameter(const_reference value) : value(value) {} operator const_reference() { return value; } private: const_reference value; }; class extension_instance; class instance_holder_base; class init; template struct init0; template struct init1; template struct init2; template struct init3; template struct init4; template struct init5; template struct init_function { static init* create(signature0) { return new init0; } template static init* create(signature1) { return new init1::const_reference>; } template static init* create(signature2) { return new init2::const_reference, detail::parameter_traits::const_reference>; } template static init* create(signature3) { return new init3::const_reference, detail::parameter_traits::const_reference, detail::parameter_traits::const_reference>; } template static init* create(signature4) { return new init4::const_reference, detail::parameter_traits::const_reference, detail::parameter_traits::const_reference, detail::parameter_traits::const_reference>; } template static init* create(signature5) { return new init5::const_reference, detail::parameter_traits::const_reference, detail::parameter_traits::const_reference, detail::parameter_traits::const_reference, detail::parameter_traits::const_reference>; } }; class init : public function { private: // override function hook PyObject* do_call(PyObject* args, PyObject* keywords) const; private: virtual instance_holder_base* create_holder(extension_instance* self, PyObject* tail_args, PyObject* keywords) const = 0; string description_as_string() const; string argument_types_as_string(tuple args) const; }; template struct init0 : init { virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { if (!PyArg_ParseTuple(args, const_cast(""))) throw argument_error(); return new T(self ); } PyObject* description() const { return function_signature(python::type()); } string function_name() const { static const bool is_plain = BOOST_PYTHON_IS_PLAIN(T); string result(python_type_name_selector::get(python::type())); result += ".__init__"; return result; } }; template struct init1 : init { virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { PyObject* a1; if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) throw argument_error(); return new T(self, python::detail::reference_parameter(from_python(a1, type())) ); } PyObject* description() const { return function_signature(python::type(), python::type()); } string function_name() const { static const bool is_plain = BOOST_PYTHON_IS_PLAIN(T); string result(python_type_name_selector::get(python::type())); result += ".__init__"; return result; } }; template struct init2 : init { virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { PyObject* a1; PyObject* a2; if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) throw argument_error(); return new T(self, python::detail::reference_parameter(from_python(a1, type())), python::detail::reference_parameter(from_python(a2, type())) ); } PyObject* description() const { return function_signature(python::type(), python::type(), python::type()); } string function_name() const { static const bool is_plain = BOOST_PYTHON_IS_PLAIN(T); string result(python_type_name_selector::get(python::type())); result += ".__init__"; return result; } }; template struct init3 : init { virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { PyObject* a1; PyObject* a2; PyObject* a3; if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) throw argument_error(); return new T(self, python::detail::reference_parameter(from_python(a1, type())), python::detail::reference_parameter(from_python(a2, type())), python::detail::reference_parameter(from_python(a3, type())) ); } PyObject* description() const { return function_signature(python::type(), python::type(), python::type(), python::type()); } string function_name() const { static const bool is_plain = BOOST_PYTHON_IS_PLAIN(T); string result(python_type_name_selector::get(python::type())); result += ".__init__"; return result; } }; template struct init4 : init { virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { PyObject* a1; PyObject* a2; PyObject* a3; PyObject* a4; if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) throw argument_error(); return new T(self, python::detail::reference_parameter(from_python(a1, type())), python::detail::reference_parameter(from_python(a2, type())), python::detail::reference_parameter(from_python(a3, type())), python::detail::reference_parameter(from_python(a4, type())) ); } PyObject* description() const { return function_signature(python::type(), python::type(), python::type(), python::type(), python::type()); } string function_name() const { static const bool is_plain = BOOST_PYTHON_IS_PLAIN(T); string result(python_type_name_selector::get(python::type())); result += ".__init__"; return result; } }; template struct init5 : init { virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { PyObject* a1; PyObject* a2; PyObject* a3; PyObject* a4; PyObject* a5; if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) throw argument_error(); return new T(self, python::detail::reference_parameter(from_python(a1, type())), python::detail::reference_parameter(from_python(a2, type())), python::detail::reference_parameter(from_python(a3, type())), python::detail::reference_parameter(from_python(a4, type())), python::detail::reference_parameter(from_python(a5, type())) ); } PyObject* description() const { return function_signature(python::type(), python::type(), python::type(), python::type(), python::type(), python::type()); } string function_name() const { static const bool is_plain = BOOST_PYTHON_IS_PLAIN(T); string result(python_type_name_selector::get(python::type())); result += ".__init__"; return result; } }; }} // namespace python::detail #endif // INIT_FUNCTION_DWA052000_H_