-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathmodule.cpp
More file actions
61 lines (49 loc) · 1.6 KB
/
module.cpp
File metadata and controls
61 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// (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.
#include <boost/python/module.hpp>
namespace boost { namespace python {
namespace {
ref name_holder;
}
bool module_base::initializing()
{
return name_holder.get() != 0;
}
string module_base::name()
{
// If this fails, you haven't created a module object
assert(initializing());
return string(name_holder);
}
module_base::module_base(const char* name)
: m_module(Py_InitModule(const_cast<char*>(name), initial_methods))
{
// If this fails, you've created more than 1 module object in your module
assert(name_holder.get() == 0);
name_holder = ref(PyObject_GetAttrString(m_module, const_cast<char*>("__name__")));
}
module_base::~module_base()
{
name_holder.reset();
}
void module_base::add(PyObject* x, const char* name)
{
add(ref(x), name);
}
void module_base::add(ref x, const char* name)
{
// Use function::add_to_namespace to achieve overloading if
// appropriate.
objects::function::add_to_namespace(m_module, name, x.get());
}
void module_base::add(PyTypeObject* x, const char* name /*= 0*/)
{
this->add((PyObject*)x, name ? name : x->tp_name);
}
PyMethodDef module_base::initial_methods[] = { { 0, 0, 0, 0 } };
}} // namespace boost::python