function.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright David Abrahams 2001.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef FUNCTION_DWA20011214_HPP
  6. # define FUNCTION_DWA20011214_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/args_fwd.hpp>
  9. # include <boost/python/handle.hpp>
  10. # include <boost/function/function2.hpp>
  11. # include <boost/python/object_core.hpp>
  12. # include <boost/python/object/py_function.hpp>
  13. namespace boost { namespace python { namespace objects {
  14. struct BOOST_PYTHON_DECL function : PyObject
  15. {
  16. function(
  17. py_function const&
  18. , python::detail::keyword const* names_and_defaults
  19. , unsigned num_keywords);
  20. ~function();
  21. PyObject* call(PyObject*, PyObject*) const;
  22. // Add an attribute to the name_space with the given name. If it is
  23. // a function object (this class), and an existing function is
  24. // already there, add it as an overload.
  25. static void add_to_namespace(
  26. object const& name_space, char const* name, object const& attribute);
  27. static void add_to_namespace(
  28. object const& name_space, char const* name, object const& attribute, char const* doc);
  29. object const& doc() const;
  30. void doc(object const& x);
  31. object const& name() const;
  32. object const& get_namespace() const { return m_namespace; }
  33. private: // helper functions
  34. object signature(bool show_return_type=false) const;
  35. object signatures(bool show_return_type=false) const;
  36. void argument_error(PyObject* args, PyObject* keywords) const;
  37. void add_overload(handle<function> const&);
  38. private: // data members
  39. py_function m_fn;
  40. handle<function> m_overloads;
  41. object m_name;
  42. object m_namespace;
  43. object m_doc;
  44. object m_arg_names;
  45. unsigned m_nkeyword_values;
  46. friend class function_doc_signature_generator;
  47. };
  48. //
  49. // implementations
  50. //
  51. inline object const& function::doc() const
  52. {
  53. return this->m_doc;
  54. }
  55. inline void function::doc(object const& x)
  56. {
  57. this->m_doc = x;
  58. }
  59. inline object const& function::name() const
  60. {
  61. return this->m_name;
  62. }
  63. }}} // namespace boost::python::objects
  64. #endif // FUNCTION_DWA20011214_HPP