1
#ifndef SWIG_DIRECTOR_PYTHON_HEADER_
2
#define SWIG_DIRECTOR_PYTHON_HEADER_
3
/***********************************************************************
6
* This file contains support for director classes that proxy
7
* method calls from C++ to Python extensions.
9
* Author : Mark Rose (mrose@stm.lbl.gov)
10
************************************************************************/
17
struct swig_type_info;
20
#ifdef SWIG_DIRECTOR_STATIC
21
/* Force anonymous (static) namespace */
26
/* base class for director exceptions */
27
class DirectorException {
31
DirectorException(const char* msg="") {
33
const char *getMessage() const {
34
return swig_msg.c_str();
36
virtual ~DirectorException();
40
/* type mismatch in the return value from a python method call */
41
class DirectorTypeMismatchException : public Swig::DirectorException {
43
DirectorTypeMismatchException(const char* msg="") {
44
swig_msg = "Swig director type mismatch: ";
46
PyErr_SetString(PyExc_TypeError, getMessage());
50
/* any python exception that occurs during a director method call */
51
class DirectorMethodException : public Swig::DirectorException {};
53
/* attempt to call a pure virtual method via a director method */
54
class DirectorPureVirtualException : public Swig::DirectorException {};
57
/* simple thread abstraction for pthreads on win32 */
60
#if defined(_WIN32) || defined(__WIN32__)
61
#define pthread_mutex_lock EnterCriticalSection
62
#define pthread_mutex_unlock LeaveCriticalSection
63
#define pthread_mutex_t CRITICAL_SECTION
64
#define MUTEX_INIT(var) CRITICAL_SECTION var
67
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
72
/* director base class */
75
/* pointer to the wrapped python object */
77
/* flag indicating whether the object is owned by python or c++ */
78
mutable bool swig_disown_flag;
79
/* shared flag for breaking recursive director calls */
83
/* locks for sharing the swig_up flag in a threaded environment */
84
static pthread_mutex_t swig_mutex_up;
85
static bool swig_mutex_active;
86
static pthread_t swig_mutex_thread;
89
/* decrement the reference count of the wrapped python object */
90
void swig_decref() const {
91
if (swig_disown_flag) {
96
/* reset the swig_up flag once the routing direction has been determined */
98
void swig_clear_up() const {
99
Swig::Director::swig_up = false;
100
Swig::Director::swig_mutex_active = false;
101
pthread_mutex_unlock(&swig_mutex_up);
104
void swig_clear_up() const {
105
Swig::Director::swig_up = false;
110
/* wrap a python object, optionally taking ownership */
111
Director(PyObject* self) : swig_self(self), swig_disown_flag(false) {
115
/* discard our reference at destruction */
118
/* return a pointer to the wrapped python object */
119
PyObject *swig_get_self() const {
123
/* get the swig_up flag to determine if the method call should be routed
124
* to the c++ base class or through the wrapped python object
127
bool swig_get_up() const {
128
if (Swig::Director::swig_mutex_active) {
129
if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
138
bool swig_get_up() const {
145
/* set the swig_up flag if the next method call should be directed to
146
* the c++ base class rather than the wrapped python object
149
void swig_set_up() const {
150
pthread_mutex_lock(&Swig::Director::swig_mutex_up);
151
Swig::Director::swig_mutex_thread = pthread_self();
152
Swig::Director::swig_mutex_active = true;
153
Swig::Director::swig_up = true;
156
void swig_set_up() const {
157
Swig::Director::swig_up = true;
161
/* acquire ownership of the wrapped python object (the sense of "disown"
163
void swig_disown() const {
164
if (!swig_disown_flag) {
165
swig_disown_flag=true;
170
/* increase the reference count of the wrapped python object */
171
void swig_incref() const {
172
if (swig_disown_flag) {
173
Py_INCREF(swig_self);
177
/* methods to implement pseudo protected director members */
178
virtual bool swig_get_inner(const char* name) const {
182
virtual void swig_set_inner(const char* name, bool val) const {
188
#endif /* __cplusplus */