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