#ifndef SWIG_DIRECTOR_PYTHON_HEADER_
#define SWIG_DIRECTOR_PYTHON_HEADER_
/***********************************************************************
* This file contains support for director classes that proxy
* method calls from C++ to Python extensions.
* Author : Mark Rose (mrose@stm.lbl.gov)
************************************************************************/
Use -DSWIG_DIRECTOR_NOUEH if you prefer to avoid the use of the
Undefined Exception Handler provided by swift
#ifndef SWIG_DIRECTOR_NOUEH
#ifndef SWIG_DIRECTOR_UEH
#define SWIG_DIRECTOR_UEH
Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
'Swig' namespace. This could be usefull for multi-modules projects.
#ifdef SWIG_DIRECTOR_STATIC
/* Force anonymous (static) namespace */
Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of the
native C++ RTTI and dynamic_cast<>. But be aware that directors
could stop working when using this option.
#ifdef SWIG_DIRECTOR_NORTTI
When we don't use the native C++ RTTI, we implement a minimal one
# ifndef SWIG_DIRECTOR_RTDIR
# define SWIG_DIRECTOR_RTDIR
SWIGINTERN std::map<void*,Director*>& get_rtdir_map() {
static std::map<void*,Director*> rtdir_map;
SWIGINTERNINLINE void set_rtdir(void *vptr, Director *rtdir) {
get_rtdir_map()[vptr] = rtdir;
SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
std::map<void*,Director*>::const_iterator pos = get_rtdir_map().find(vptr);
Director *rtdir = (pos != get_rtdir_map().end()) ? pos->second : 0;
# endif /* SWIG_DIRECTOR_RTDIR */
# define SWIG_DIRECTOR_CAST(Arg) Swig::get_rtdir(static_cast<void*>(Arg))
# define SWIG_DIRECTOR_RGTR(Arg1, Arg2) Swig::set_rtdir(static_cast<void*>(Arg1), Arg2)
# define SWIG_DIRECTOR_CAST(Arg) dynamic_cast<Swig::Director*>(Arg)
# define SWIG_DIRECTOR_RGTR(Arg1, Arg2)
#endif /* SWIG_DIRECTOR_NORTTI */
/* base class for director exceptions */
class DirectorException {
DirectorException(const char* hdr ="", const char* msg ="")
PyErr_SetString(PyExc_TypeError, getMessage());
SWIG_Python_AddErrMesg(getMessage(), 1);
const char *getMessage() const {
static void raise(const char* msg = "")
throw DirectorException(msg);
class UnknownExceptionHandler
std::unexpected_handler old;
UnknownExceptionHandler(std::unexpected_handler nh = handler)
old = std::set_unexpected(nh);
~UnknownExceptionHandler()
std::set_unexpected(old);
/* type mismatch in the return value from a python method call */
class DirectorTypeMismatchException : public Swig::DirectorException {
DirectorTypeMismatchException(const char* msg="")
: Swig::DirectorException("Swig director type mismatch: ", msg) {
static void raise(const char* msg = "")
throw DirectorTypeMismatchException(msg);
/* any python exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException {
DirectorMethodException(const char* msg = "")
: DirectorException("Swig director python method error: ", msg)
static void raise(const char* msg = "")
throw DirectorMethodException(msg);
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException
DirectorPureVirtualException(const char* msg = "")
: DirectorException("Swig director pure virtal method called: ", msg)
static void raise(const char* msg = "")
throw DirectorPureVirtualException(msg);
/* simple thread abstraction for pthreads on win32 */
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
/* director base class */
/* pointer to the wrapped python object */
/* flag indicating whether the object is owned by python or c++ */
mutable bool swig_disown_flag;
/* shared flag for breaking recursive director calls */
/* locks for sharing the swig_up flag in a threaded environment */
static pthread_mutex_t swig_mutex_up;
static bool swig_mutex_active;
static pthread_t swig_mutex_thread;
/* decrement the reference count of the wrapped python object */
void swig_decref() const {
/* reset the swig_up flag once the routing direction has been determined */
void swig_clear_up() const {
Swig::Director::swig_up = false;
Swig::Director::swig_mutex_active = false;
pthread_mutex_unlock(&swig_mutex_up);
void swig_clear_up() const {
Swig::Director::swig_up = false;
/* wrap a python object, optionally taking ownership */
Director(PyObject* self) : swig_self(self), swig_disown_flag(false) {
/* discard our reference at destruction */
/* return a pointer to the wrapped python object */
PyObject *swig_get_self() const {
/* get the swig_up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped python object
bool swig_get_up() const {
if (Swig::Director::swig_mutex_active) {
if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
bool swig_get_up() const {
/* set the swig_up flag if the next method call should be directed to
* the c++ base class rather than the wrapped python object
void swig_set_up() const {
pthread_mutex_lock(&Swig::Director::swig_mutex_up);
Swig::Director::swig_mutex_thread = pthread_self();
Swig::Director::swig_mutex_active = true;
Swig::Director::swig_up = true;
void swig_set_up() const {
Swig::Director::swig_up = true;
/* acquire ownership of the wrapped python object (the sense of "disown"
void swig_disown() const {
/* increase the reference count of the wrapped python object */
void swig_incref() const {
/* methods to implement pseudo protected director members */
virtual bool swig_get_inner(const char* /* name */) const {
virtual void swig_set_inner(const char* /* name */, bool /* val */) const {