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 | |
---|
8 | # include <boost/python/detail/prefix.hpp> |
---|
9 | # include <boost/python/args_fwd.hpp> |
---|
10 | # include <boost/python/handle.hpp> |
---|
11 | # include <boost/function/function2.hpp> |
---|
12 | # include <boost/python/object_core.hpp> |
---|
13 | # include <boost/python/object/py_function.hpp> |
---|
14 | |
---|
15 | namespace boost { namespace python { namespace objects { |
---|
16 | |
---|
17 | struct BOOST_PYTHON_DECL function : PyObject |
---|
18 | { |
---|
19 | function( |
---|
20 | py_function const& |
---|
21 | , python::detail::keyword const* names_and_defaults |
---|
22 | , unsigned num_keywords); |
---|
23 | |
---|
24 | ~function(); |
---|
25 | |
---|
26 | PyObject* call(PyObject*, PyObject*) const; |
---|
27 | |
---|
28 | // Add an attribute to the name_space with the given name. If it is |
---|
29 | // a function object (this class), and an existing function is |
---|
30 | // already there, add it as an overload. |
---|
31 | static void add_to_namespace( |
---|
32 | object const& name_space, char const* name, object const& attribute); |
---|
33 | |
---|
34 | static void add_to_namespace( |
---|
35 | object const& name_space, char const* name, object const& attribute, char const* doc); |
---|
36 | |
---|
37 | object const& doc() const; |
---|
38 | void doc(object const& x); |
---|
39 | |
---|
40 | object const& name() const; |
---|
41 | |
---|
42 | private: // helper functions |
---|
43 | object signature(bool show_return_type=false) const; |
---|
44 | object signatures(bool show_return_type=false) const; |
---|
45 | void argument_error(PyObject* args, PyObject* keywords) const; |
---|
46 | void add_overload(handle<function> const&); |
---|
47 | |
---|
48 | private: // data members |
---|
49 | py_function m_fn; |
---|
50 | handle<function> m_overloads; |
---|
51 | object m_name; |
---|
52 | object m_namespace; |
---|
53 | object m_doc; |
---|
54 | object m_arg_names; |
---|
55 | unsigned m_nkeyword_values; |
---|
56 | }; |
---|
57 | |
---|
58 | // |
---|
59 | // implementations |
---|
60 | // |
---|
61 | inline object const& function::doc() const |
---|
62 | { |
---|
63 | return this->m_doc; |
---|
64 | } |
---|
65 | |
---|
66 | inline void function::doc(object const& x) |
---|
67 | { |
---|
68 | this->m_doc = x; |
---|
69 | } |
---|
70 | |
---|
71 | inline object const& function::name() const |
---|
72 | { |
---|
73 | return this->m_name; |
---|
74 | } |
---|
75 | |
---|
76 | }}} // namespace boost::python::objects |
---|
77 | |
---|
78 | #endif // FUNCTION_DWA20011214_HPP |
---|