__DIRECTOR__ renamed Swig::Director

SWIG_DIRECTOR_EXCEPTION renamed Swig::DirectorException (similarly for derived classes)


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5138 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2003-09-22 20:13:42 +00:00
commit f569dd135d
20 changed files with 507 additions and 496 deletions

View file

@ -2007,7 +2007,7 @@ public:
For each class that has directors enabled, SWIG generates a new class For each class that has directors enabled, SWIG generates a new class
that derives from both the class in question and a special that derives from both the class in question and a special
<tt>__DIRECTOR__</tt> class. These new classes, referred to as director <tt>Swig::Director</tt> class. These new classes, referred to as director
classes, can be loosely thought of as the C++ equivalent of the Python classes, can be loosely thought of as the C++ equivalent of the Python
proxy classes. The director classes store a pointer to their underlying proxy classes. The director classes store a pointer to their underlying
Python object and handle various issues related to object ownership. Python object and handle various issues related to object ownership.
@ -2015,7 +2015,7 @@ Indeed, this is quite similar to the "this" and "thisown" members of the
Python proxy classes. Python proxy classes.
<p> <p>
For simplicity let's ignore the <tt>__DIRECTOR__</tt> class and refer to the For simplicity let's ignore the <tt>Swig::Director</tt> class and refer to the
original C++ class as the director's base class. By default, a director original C++ class as the director's base class. By default, a director
class extends all virtual methods in the inheritance chain of its base class extends all virtual methods in the inheritance chain of its base
class (see the preceding section for how to modify this behavior). class (see the preceding section for how to modify this behavior).
@ -2150,7 +2150,7 @@ suffice in most cases:
<pre> <pre>
%feature("director:except") { %feature("director:except") {
if ($error != NULL) { if ($error != NULL) {
throw SWIG_DIRECTOR_METHOD_EXCEPTION(); throw Swig::DirectorMethodException();
} }
} }
</pre> </pre>
@ -2160,7 +2160,7 @@ This code will check the Python error state after each method call from
a director into Python, and throw a C++ exception if an error occured. a director into Python, and throw a C++ exception if an error occured.
This exception can be caught in C++ to implement an error handler. This exception can be caught in C++ to implement an error handler.
Currently no information about the Python error is stored in the Currently no information about the Python error is stored in the
SWIG_DIRECTOR_METHOD_EXCEPTION object, but this will likely change in Swig::DirectorMethodException object, but this will likely change in
the future. the future.
<p> <p>
@ -2176,15 +2176,15 @@ suitable exception handler:
<pre> <pre>
%exception { %exception {
try { $action } try { $action }
catch (SWIG_DIRECTOR_EXCEPTION &e) { SWIG_fail; } catch (Swig::DirectorException &e) { SWIG_fail; }
} }
</pre> </pre>
</blockquote> </blockquote>
The class SWIG_DIRECTOR_EXCEPTION used in this example is actually a The class Swig::DirectorException used in this example is actually a
base class of SWIG_DIRECTOR_METHOD_EXCEPTION, so it will trap this base class of Swig::DirectorMethodException, so it will trap this
exception. Because the Python error state is still set when exception. Because the Python error state is still set when
SWIG_DIRECTOR_METHOD_EXCEPTION is thrown, Python will register the Swig::DirectorMethodException is thrown, Python will register the
exception as soon as the C wrapper function returns. exception as soon as the C wrapper function returns.
<a name="n37"></a><H3>19.5.5 Overhead and code bloat</H3> <a name="n37"></a><H3>19.5.5 Overhead and code bloat</H3>

View file

@ -1210,7 +1210,7 @@ directive to indicate what action should be taken when a Ruby exception is raise
The following code should suffice in most cases: The following code should suffice in most cases:
<blockquote><pre>%feature("director:except") { <blockquote><pre>%feature("director:except") {
throw SWIG_DIRECTOR_METHOD_EXCEPTION($error); throw Swig::DirectorMethodException($error);
} }
</pre></blockquote> </pre></blockquote>
@ -3090,4 +3090,4 @@ for more details).
<address>SWIG 1.3 - Last Modified : $Date$</address> <address>SWIG 1.3 - Last Modified : $Date$</address>
</body> </body>
</html> </html>

View file

@ -18,8 +18,10 @@ Foo *launder(Foo *f) {
// in target languages that do not support directors. // in target languages that do not support directors.
#ifndef SWIG_DIRECTORS #ifndef SWIG_DIRECTORS
class SWIG_DIRECTOR_EXCEPTION {}; namespace Swig {
class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION {}; class DirectorException {};
class DirectorMethodException: public Swig::DirectorException {};
}
#ifndef SWIG_fail #ifndef SWIG_fail
#define SWIG_fail #define SWIG_fail
#endif #endif
@ -33,13 +35,13 @@ class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION {};
%feature("director:except") { %feature("director:except") {
if ($error != NULL) { if ($error != NULL) {
throw SWIG_DIRECTOR_METHOD_EXCEPTION(); throw Swig::DirectorMethodException();
} }
} }
%exception { %exception {
try { $action } try { $action }
catch (SWIG_DIRECTOR_EXCEPTION &e) { SWIG_fail; } catch (Swig::DirectorException &e) { SWIG_fail; }
} }
#endif #endif
@ -47,12 +49,12 @@ class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION {};
#ifdef SWIGRUBY #ifdef SWIGRUBY
%feature("director:except") { %feature("director:except") {
throw SWIG_DIRECTOR_METHOD_EXCEPTION($error); throw Swig::DirectorMethodException($error);
} }
%exception { %exception {
try { $action } try { $action }
catch (SWIG_DIRECTOR_EXCEPTION &e) { rb_exc_raise(e.getError()); } catch (Swig::DirectorException &e) { rb_exc_raise(e.getError()); }
} }
#endif #endif

View file

@ -6,64 +6,63 @@
* *
* Author : Scott Michel (scottm@aero.org) * Author : Scott Michel (scottm@aero.org)
* *
* N.B.: This file was * This file was adapted from the python director.swg, written by
adapted from the python director.swg, written by
* Mark Rose (mrose@stm.lbl.gov) * Mark Rose (mrose@stm.lbl.gov)
************************************************************************/ ************************************************************************/
#ifdef __cplusplus #ifdef __cplusplus
/* director base class */ namespace Swig {
class __DIRECTOR__ { /* director base class */
private: class Director {
/* pointer to java virtual machine */ private:
JavaVM *__jvm; /* pointer to java virtual machine */
JavaVM *__jvm;
protected: protected:
/* pointer to the wrapped java object */ /* pointer to the wrapped java object */
jobject __self; jobject __self;
/* Acquire Java VM environment from Java VM */ /* Acquire Java VM environment from Java VM */
JNIEnv *__acquire_jenv() const { JNIEnv *__acquire_jenv() const {
JNIEnv *env; JNIEnv *env;
__jvm->AttachCurrentThread((void **) &env, NULL); __jvm->AttachCurrentThread((void **) &env, NULL);
return env; return env;
} }
public: public:
__DIRECTOR__(JNIEnv *jenv): Director(JNIEnv *jenv):
__jvm((JavaVM *) NULL), __jvm((JavaVM *) NULL),
__self(NULL) __self(NULL) {
{ /* Acquire the Java VM pointer */
/* Acquire the Java VM pointer */ jenv->GetJavaVM(&__jvm);
jenv->GetJavaVM(&__jvm); }
}
/* Remove the Java object global lock at destruction */ /* Remove the Java object global lock at destruction */
virtual ~__DIRECTOR__() virtual ~Director() {
{ if (__self) {
if (__self) { JNIEnv *jenv;
JNIEnv *jenv; jmethodID disconn_meth;
jmethodID disconn_meth;
jenv = __acquire_jenv();
disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(__self), "__director_disconnect", "()V");
if (disconn_meth)
jenv->CallVoidMethod(__self, disconn_meth);
jenv->DeleteGlobalRef(__self);
__self = (jobject) NULL;
}
}
/* Set __self and get Java global reference on object */
inline void __set_self(JNIEnv *jenv, jobject jself)
{
__self = jenv->NewGlobalRef(jself);
}
/* return a pointer to the wrapped java object */ jenv = __acquire_jenv();
inline jobject __get_self() const disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(__self), "__director_disconnect", "()V");
{ return __self; } if (disconn_meth)
}; jenv->CallVoidMethod(__self, disconn_meth);
jenv->DeleteGlobalRef(__self);
__self = (jobject) NULL;
}
}
/* Set __self and get Java global reference on object */
inline void __set_self(JNIEnv *jenv, jobject jself) {
__self = jenv->NewGlobalRef(jself);
}
/* return a pointer to the wrapped java object */
inline jobject __get_self() const {
return __self;
}
};
}
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -15,125 +15,128 @@
#include <string> #include <string>
/* simple thread abstraction for pthreads or win32 */ namespace Swig {
/* simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__ #ifdef __THREAD__
#define __PTHREAD__ #define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__) #if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection #define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection #define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION #define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var #define MUTEX_INIT(var) CRITICAL_SECTION var
#else
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to the wrapped ocaml object */
CAML_VALUE _self;
/* flag indicating whether the object is owned by ocaml or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
__DIRECTOR__::_up = 0;
__DIRECTOR__::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#else #else
void __clear_up() const { #include <pthread.h>
__DIRECTOR__::_up = 0; #define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
} #endif
#endif #endif
public: /* director base class */
/* wrap a ocaml object, optionally taking ownership */ class Director {
__DIRECTOR__(CAML_VALUE self, int disown): _self(self), _disown(disown) { private:
/* pointer to the wrapped ocaml object */
CAML_VALUE _self;
/* flag indicating whether the object is owned by ocaml or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
Swig::Director::_up = 0;
Swig::Director::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#else
void __clear_up() const {
Swig::Director::_up = 0;
}
#endif
public:
/* wrap a ocaml object, optionally taking ownership */
Director(CAML_VALUE self, int disown): _self(self), _disown(disown) {
register_global_root(&_self); register_global_root(&_self);
} }
/* discard our reference at destruction */ /* discard our reference at destruction */
virtual ~__DIRECTOR__() { virtual ~Director() {
remove_global_root(&_self); remove_global_root(&_self);
__disown(); __disown();
// Disown is safe here because we're just divorcing a reference that // Disown is safe here because we're just divorcing a reference that
// points to us. // points to us.
} }
/* return a pointer to the wrapped ocaml object */
CAML_VALUE __get_self() const {
return callback(*caml_named_value("caml_director_get_self"),_self);
}
/* get the _up flag to determine if the method call should be routed /* return a pointer to the wrapped ocaml object */
* to the c++ base class or through the wrapped ocaml object CAML_VALUE __get_self() const {
*/ return callback(*caml_named_value("caml_director_get_self"),_self);
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped ocaml object
*/
#ifdef __PTHREAD__ #ifdef __PTHREAD__
int __get_up() const { int __get_up() const {
if (__DIRECTOR__::_mutex_active) { if (Swig::Director::_mutex_active) {
if (pthread_equal(__DIRECTOR__::_mutex_thread, pthread_self())) { if (pthread_equal(Swig::Director::_mutex_thread, pthread_self())) {
int up = _up; int up = _up;
__clear_up(); __clear_up();
return up; return up;
} }
} }
return 0; return 0;
} }
#else #else
int __get_up() const { int __get_up() const {
int up = _up; int up = _up;
_up = 0; _up = 0;
return up; return up;
} }
#endif #endif
/* set the _up flag if the next method call should be directed to /* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped ocaml object * the c++ base class rather than the wrapped ocaml object
*/ */
#ifdef __PTHREAD__ #ifdef __PTHREAD__
void __set_up() const { void __set_up() const {
pthread_mutex_lock(&__DIRECTOR__::_mutex_up); pthread_mutex_lock(&Swig::Director::_mutex_up);
__DIRECTOR__::_mutex_thread = pthread_self(); Swig::Director::_mutex_thread = pthread_self();
__DIRECTOR__::_mutex_active = 1; Swig::Director::_mutex_active = 1;
__DIRECTOR__::_up = 1; Swig::Director::_up = 1;
} }
#else #else
void __set_up() const { void __set_up() const {
__DIRECTOR__::_up = 1; Swig::Director::_up = 1;
} }
#endif #endif
/* acquire ownership of the wrapped ocaml object (the sense of "disown"
* is from ocaml) */
void __disown() const {
if (!_disown) {
_disown=1;
callback(*caml_named_value("caml_obj_disown"),_self);
}
}
};
int __DIRECTOR__::_up = 0; /* acquire ownership of the wrapped ocaml object (the sense of "disown"
* is from ocaml) */
void __disown() const {
if (!_disown) {
_disown=1;
callback(*caml_named_value("caml_obj_disown"),_self);
}
}
};
int Swig::Director::_up = 0;
#ifdef __PTHREAD__ #ifdef __PTHREAD__
MUTEX_INIT(__DIRECTOR__::_mutex_up); MUTEX_INIT(Swig::Director::_mutex_up);
pthread_t __DIRECTOR__::_mutex_thread; pthread_t Swig::Director::_mutex_thread;
int __DIRECTOR__::_mutex_active = 0; int Swig::Director::_mutex_active = 0;
#endif #endif
}
#endif /* __cplusplus */ #endif /* __cplusplus */
%} %}

View file

@ -43,7 +43,7 @@ namespace std {
if ($input.type == T_STRING) if ($input.type == T_STRING)
$result = std::string(STR0($input.u.string)); $result = std::string(STR0($input.u.string));
else else
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected"); throw Swig::DirectorTypeMismatchException("string expected");
} }
%typemap(directorout) const string & (std::string temp) { %typemap(directorout) const string & (std::string temp) {
@ -51,7 +51,7 @@ namespace std {
temp = std::string(STR0($input.u.string)); temp = std::string(STR0($input.u.string));
$result = &temp; $result = &temp;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected"); throw Swig::DirectorTypeMismatchException("string expected");
} }
} }

View file

@ -11,166 +11,168 @@
#include <string> #include <string>
/* base class for director exceptions */ namespace Swig {
class SWIG_DIRECTOR_EXCEPTION { /* base class for director exceptions */
protected: class DirectorException {
std::string _msg; protected:
public: std::string _msg;
SWIG_DIRECTOR_EXCEPTION(const char* msg="") { public:
} DirectorException(const char* msg="") {
const char *getMessage() { return _msg.c_str(); } }
virtual ~SWIG_DIRECTOR_EXCEPTION() { } const char *getMessage() {
}; return _msg.c_str();
}
virtual ~DirectorException() {}
};
/* type mismatch in the return value from a python method call */ /* type mismatch in the return value from a python method call */
class SWIG_DIRECTOR_TYPE_MISMATCH: public SWIG_DIRECTOR_EXCEPTION { class DirectorTypeMismatchException : public Swig::DirectorException {
public: public:
SWIG_DIRECTOR_TYPE_MISMATCH(const char* msg="") { DirectorTypeMismatchException(const char* msg="") {
_msg = "Swig director type mismatch: "; _msg = "Swig director type mismatch: ";
_msg += msg; _msg += msg;
PyErr_SetString(PyExc_TypeError, msg); PyErr_SetString(PyExc_TypeError, msg);
} }
}; };
/* any python exception that occurs during a director method call */ /* any python exception that occurs during a director method call */
class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION { }; class DirectorMethodException : public Swig::DirectorException {};
/* attempt to call a pure virtual method via a director method */ /* attempt to call a pure virtual method via a director method */
class SWIG_DIRECTOR_PURE_VIRTUAL_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION { }; class DirectorPureVirtualException : public Swig::DirectorException {};
/* simple thread abstraction for pthreads or win32 */ /* simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__ #ifdef __THREAD__
#define __PTHREAD__ #define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__) #if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection #define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection #define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION #define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var #define MUTEX_INIT(var) CRITICAL_SECTION var
#else
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to the wrapped python object */
PyObject* _self;
/* flag indicating whether the object is owned by python or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* decrement the reference count of the wrapped python object */
void __decref() const {
if (_disown) {
Py_DECREF(_self);
}
}
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
__DIRECTOR__::_up = 0;
__DIRECTOR__::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#else #else
void __clear_up() const { #include <pthread.h>
__DIRECTOR__::_up = 0; #define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
} #endif
#endif #endif
public:
/* wrap a python object, optionally taking ownership */
__DIRECTOR__(PyObject* self, int disown): _self(self), _disown(disown) {
__incref();
}
/* discard our reference at destruction */ /* director base class */
virtual ~__DIRECTOR__() { class Director {
__decref(); private:
} /* pointer to the wrapped python object */
PyObject* _self;
/* return a pointer to the wrapped python object */ /* flag indicating whether the object is owned by python or c++ */
PyObject *__get_self() const { mutable int _disown;
return _self; /* shared flag for breaking recursive director calls */
} static int _up;
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped python object
*/
#ifdef __PTHREAD__ #ifdef __PTHREAD__
int __get_up() const { /* locks for sharing the _up flag in a threaded environment */
if (__DIRECTOR__::_mutex_active) { static pthread_mutex_t _mutex_up;
if (pthread_equal(__DIRECTOR__::_mutex_thread, pthread_self())) { static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* decrement the reference count of the wrapped python object */
void __decref() const {
if (_disown) {
Py_DECREF(_self);
}
}
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
Swig::Director::_up = 0;
Swig::Director::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#else
void __clear_up() const {
Swig::Director::_up = 0;
}
#endif
public:
/* wrap a python object, optionally taking ownership */
Director(PyObject* self, int disown): _self(self), _disown(disown) {
__incref();
}
/* discard our reference at destruction */
virtual ~Director() {
__decref();
}
/* return a pointer to the wrapped python object */
PyObject *__get_self() const {
return _self;
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped python object
*/
#ifdef __PTHREAD__
int __get_up() const {
if (Swig::Director::_mutex_active) {
if (pthread_equal(Swig::Director::_mutex_thread, pthread_self())) {
int up = _up;
__clear_up();
return up;
}
}
return 0;
}
#else
int __get_up() const {
int up = _up; int up = _up;
__clear_up(); _up = 0;
return up; return up;
} }
}
return 0;
}
#else
int __get_up() const {
int up = _up;
_up = 0;
return up;
}
#endif
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped python object
*/
#ifdef __PTHREAD__
void __set_up() const {
pthread_mutex_lock(&__DIRECTOR__::_mutex_up);
__DIRECTOR__::_mutex_thread = pthread_self();
__DIRECTOR__::_mutex_active = 1;
__DIRECTOR__::_up = 1;
}
#else
void __set_up() const {
__DIRECTOR__::_up = 1;
}
#endif #endif
/* acquire ownership of the wrapped python object (the sense of "disown" /* set the _up flag if the next method call should be directed to
* is from python) */ * the c++ base class rather than the wrapped python object
void __disown() const { */
if (!_disown) { #ifdef __PTHREAD__
_disown=1; void __set_up() const {
__incref(); pthread_mutex_lock(&Swig::Director::_mutex_up);
} Swig::Director::_mutex_thread = pthread_self();
} Swig::Director::_mutex_active = 1;
Swig::Director::_up = 1;
}
#else
void __set_up() const {
Swig::Director::_up = 1;
}
#endif
/* increase the reference count of the wrapped python object */ /* acquire ownership of the wrapped python object (the sense of "disown"
void __incref() const { * is from python) */
if (_disown) { void __disown() const {
Py_INCREF(_self); if (!_disown) {
} _disown=1;
} __incref();
}
}
}; /* increase the reference count of the wrapped python object */
void __incref() const {
if (_disown) {
Py_INCREF(_self);
}
}
namespace { };
int __DIRECTOR__::_up = 0;
int Swig::Director::_up = 0;
#ifdef __PTHREAD__ #ifdef __PTHREAD__
MUTEX_INIT(__DIRECTOR__::_mutex_up); MUTEX_INIT(Swig::Director::_mutex_up);
pthread_t __DIRECTOR__::_mutex_thread; pthread_t Swig::Director::_mutex_thread;
int __DIRECTOR__::_mutex_active = 0; int Swig::Director::_mutex_active = 0;
#endif #endif
} }

View file

@ -467,7 +467,7 @@
/* no can do... see python.cxx /* no can do... see python.cxx
%typemap(directorin) DIRECTORTYPE * { %typemap(directorin) DIRECTORTYPE * {
{ {
__DIRECTOR__$1_ltype proxy = dynamic_cast<__DIRECTOR__$1_ltype>($1_name); SwigDirector::$1_ltype proxy = dynamic_cast<SwigDirector::$1_ltype>($1_name);
if (!proxy) { if (!proxy) {
$input = SWIG_NewPointerObj((void *) $1_name, $1_descriptor, 0); $input = SWIG_NewPointerObj((void *) $1_name, $1_descriptor, 0);
} else { } else {
@ -493,10 +493,10 @@
%define DIRECTOROUT_TYPEMAP(type, converter) %define DIRECTOROUT_TYPEMAP(type, converter)
%typemap(directorargout) type *DIRECTOROUT %typemap(directorargout) type *DIRECTOROUT
"*$result = (type) converter($input); "*$result = (type) converter($input);
if (PyErr_Occurred()) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Error converting Python object using converter\");"; if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using converter\");";
%typemap(directorout) type %typemap(directorout) type
"$result = (type) converter($input); "$result = (type) converter($input);
if (PyErr_Occurred()) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Error converting Python object using converter\");"; if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using converter\");";
%typemap(directorout) type &DIRECTOROUT = type %typemap(directorout) type &DIRECTOROUT = type
%enddef %enddef
@ -519,14 +519,14 @@ DIRECTOROUT_TYPEMAP(std::size_t, PyInt_AsLong);
/* Object returned by value. Convert from a pointer */ /* Object returned by value. Convert from a pointer */
%typemap(directorout) SWIGTYPE ($&ltype argp) %typemap(directorout) SWIGTYPE ($&ltype argp)
"if ((SWIG_ConvertPtr($input,(void **) &argp, $&descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\"); $result = *argp;"; "if ((SWIG_ConvertPtr($input,(void **) &argp, $&descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\"); $result = *argp;";
%typemap(directorout) SWIGTYPE *, %typemap(directorout) SWIGTYPE *,
SWIGTYPE &, SWIGTYPE &,
SWIGTYPE [] SWIGTYPE []
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");"; "if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");"; %typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";

View file

@ -78,14 +78,14 @@ SwigComplex_AsComplexDouble(PyObject *o)
%typemap(directorout) Complex { %typemap(directorout) Complex {
$result = SwigComplex_As< Complex >($input); $result = SwigComplex_As< Complex >($input);
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type"); throw Swig::DirectorTypeMismatchException("Expecting a complex or compatible type");
} }
} }
%typemap(directorout) const complex<T>& (Complex temp) { %typemap(directorout) const complex<T>& (Complex temp) {
temp = SwigComplex_As< Complex >($input); temp = SwigComplex_As< Complex >($input);
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type"); throw Swig::DirectorTypeMismatchException("Expecting a complex or compatible type");
} }
$result = &temp; $result = &temp;
} }

View file

@ -62,7 +62,7 @@ namespace std {
$result = std::string(PyString_AsString($input), $result = std::string(PyString_AsString($input),
PyString_Size($input)); PyString_Size($input));
else else
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected"); throw Swig::DirectorTypeMismatchException("string expected");
} }
%typemap(directorout) const string & (std::string temp) { %typemap(directorout) const string & (std::string temp) {
@ -71,7 +71,7 @@ namespace std {
PyString_Size($input)); PyString_Size($input));
$result = &temp; $result = &temp;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected"); throw Swig::DirectorTypeMismatchException("string expected");
} }
} }

View file

@ -121,15 +121,14 @@ namespace std {
Py_DECREF(o); Py_DECREF(o);
} else { } else {
Py_DECREF(o); Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH( throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
"vector<" #T "> expected");
} }
} }
} else if (SWIG_ConvertPtr($input,(void **) &v, } else if (SWIG_ConvertPtr($input,(void **) &v,
$&descriptor,1) != -1){ $&descriptor,1) != -1){
$result = *v; $result = *v;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
%typemap(in) const vector<T>& (std::vector<T> temp, %typemap(in) const vector<T>& (std::vector<T> temp,
@ -183,14 +182,14 @@ namespace std {
Py_DECREF(o); Py_DECREF(o);
} else { } else {
Py_DECREF(o); Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
} else if (SWIG_ConvertPtr($input,(void **) &v, } else if (SWIG_ConvertPtr($input,(void **) &v,
$descriptor,1) != -1){ $descriptor,1) != -1){
$result = v; $result = v;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
%typemap(out) vector<T> { %typemap(out) vector<T> {
@ -403,14 +402,14 @@ namespace std {
Py_DECREF(o); Py_DECREF(o);
} else { } else {
Py_DECREF(o); Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
} }
} }
} else if (SWIG_ConvertPtr($input,(void **) &v, } else if (SWIG_ConvertPtr($input,(void **) &v,
$&descriptor,1) != -1){ $&descriptor,1) != -1){
$result = *v; $result = *v;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
} }
} }
%typemap(in) const vector<T*>& (std::vector<T*> temp, %typemap(in) const vector<T*>& (std::vector<T*> temp,
@ -464,14 +463,14 @@ namespace std {
Py_DECREF(o); Py_DECREF(o);
} else { } else {
Py_DECREF(o); Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
} }
} }
} else if (SWIG_ConvertPtr($input,(void **) &v, } else if (SWIG_ConvertPtr($input,(void **) &v,
$descriptor,1) != -1){ $descriptor,1) != -1){
$result = v; $result = v;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
} }
} }
%typemap(out) vector<T*> { %typemap(out) vector<T*> {
@ -678,14 +677,14 @@ namespace std {
Py_DECREF(o); Py_DECREF(o);
} else { } else {
Py_DECREF(o); Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
} else if (SWIG_ConvertPtr($input,(void **) &v, } else if (SWIG_ConvertPtr($input,(void **) &v,
$&descriptor,1) != -1){ $&descriptor,1) != -1){
$result = *v; $result = *v;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
%typemap(in) const vector<T>& (std::vector<T> temp, %typemap(in) const vector<T>& (std::vector<T> temp,
@ -735,14 +734,14 @@ namespace std {
Py_DECREF(o); Py_DECREF(o);
} else { } else {
Py_DECREF(o); Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
} else if (SWIG_ConvertPtr($input,(void **) &v, } else if (SWIG_ConvertPtr($input,(void **) &v,
$descriptor,1) != -1){ $descriptor,1) != -1){
$result = v; $result = v;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
} }
} }
%typemap(out) vector<T> { %typemap(out) vector<T> {

View file

@ -13,160 +13,166 @@
#include <string> #include <string>
struct swig_body_args namespace Swig {
{ struct body_args {
VALUE recv; VALUE recv;
ID id; ID id;
int argc; int argc;
VALUE *argv; VALUE *argv;
}; };
/* Base class for director exceptions */ /* Base class for director exceptions */
class SWIG_DIRECTOR_EXCEPTION { class DirectorException {
protected: protected:
VALUE _error; VALUE _error;
protected: protected:
SWIG_DIRECTOR_EXCEPTION(VALUE error=Qnil) : _error(error) {} DirectorException(VALUE error=Qnil) : _error(error) {}
public: public:
VALUE getType() const { return CLASS_OF(_error); } VALUE getType() const {
VALUE getError() const { return _error; } return CLASS_OF(_error);
virtual ~SWIG_DIRECTOR_EXCEPTION() {} }
}; VALUE getError() const {
return _error;
}
virtual ~DirectorException() {}
};
/* Type mismatch in the return value from a Ruby method call */ /* Type mismatch in the return value from a Ruby method call */
class SWIG_DIRECTOR_TYPE_MISMATCH : public SWIG_DIRECTOR_EXCEPTION { class DirectorTypeMismatchException : public Swig::DirectorException {
public: public:
SWIG_DIRECTOR_TYPE_MISMATCH(const char *msg="") { DirectorTypeMismatchException(const char *msg="") {
VALUE str = rb_str_new2("Swig director type mismatch: "); VALUE str = rb_str_new2("Swig director type mismatch: ");
rb_str_concat(str, rb_str_new2(msg)); rb_str_concat(str, rb_str_new2(msg));
_error = rb_exc_new3(rb_eTypeError, str); _error = rb_exc_new3(rb_eTypeError, str);
} }
}; };
/* Any Ruby exception that occurs during a director method call */ /* Any Ruby exception that occurs during a director method call */
class SWIG_DIRECTOR_METHOD_EXCEPTION : public SWIG_DIRECTOR_EXCEPTION { class DirectorMethodException : public Swig::DirectorException {
public: public:
SWIG_DIRECTOR_METHOD_EXCEPTION(VALUE error) :SWIG_DIRECTOR_EXCEPTION(error) {} DirectorMethodException(VALUE error) : Swig::DirectorException(error) {}
}; };
/* Attempted to call a pure virtual method via a director method */ /* Attempted to call a pure virtual method via a director method */
class SWIG_DIRECTOR_PURE_VIRTUAL_EXCEPTION : public SWIG_DIRECTOR_EXCEPTION {}; class DirectorPureVirtualException : public Swig::DirectorException {};
/* Simple thread abstraction for pthreads or win32 */ /* Simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__ #ifdef __THREAD__
#define __PTHREAD__ #define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__) #if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection #define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection #define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION #define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var #define MUTEX_INIT(var) CRITICAL_SECTION var
#else
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to the wrapped Ruby object */
VALUE _self;
/* flag indicating whether the object is owned by Ruby or c++ */
mutable bool _disown;
/* shared flag for breaking recursive director calls */
static bool _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static bool _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
__DIRECTOR__::_up = false;
__DIRECTOR__::_mutex_active = false;
pthread_mutex_unlock(&_mutex_up);
}
#else #else
void __clear_up() const { #include <pthread.h>
__DIRECTOR__::_up = false; #define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
} #endif
#endif #endif
public: /* director base class */
/* wrap a Ruby object, optionally taking ownership */ class Director {
__DIRECTOR__(VALUE self, bool disown) : _self(self), _disown(disown) { private:
} /* pointer to the wrapped Ruby object */
VALUE _self;
/* flag indicating whether the object is owned by Ruby or c++ */
mutable bool _disown;
/* shared flag for breaking recursive director calls */
static bool _up;
/* discard our reference at destruction */
virtual ~__DIRECTOR__() {
}
/* return a pointer to the wrapped Ruby object */
VALUE __get_self() const {
return _self;
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped Ruby object
*/
#ifdef __PTHREAD__ #ifdef __PTHREAD__
bool __get_up() const { /* locks for sharing the _up flag in a threaded environment */
if (__DIRECTOR__::_mutex_active) { static pthread_mutex_t _mutex_up;
if (pthread_equal(__DIRECTOR__::_mutex_thread, pthread_self())) { static bool _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
Swig::Director::_up = false;
Swig::Director::_mutex_active = false;
pthread_mutex_unlock(&_mutex_up);
}
#else
void __clear_up() const {
Swig::Director::_up = false;
}
#endif
public:
/* wrap a Ruby object, optionally taking ownership */
Director(VALUE self, bool disown) : _self(self), _disown(disown) {
}
/* discard our reference at destruction */
virtual ~Director() {
}
/* return a pointer to the wrapped Ruby object */
VALUE __get_self() const {
return _self;
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped Ruby object
*/
#ifdef __PTHREAD__
bool __get_up() const {
if (Swig::Director::_mutex_active) {
if (pthread_equal(Swig::Director::_mutex_thread, pthread_self())) {
bool up = _up;
__clear_up();
return up;
}
}
return false;
}
#else
bool __get_up() const {
bool up = _up; bool up = _up;
__clear_up(); _up = false;
return up; return up;
} }
}
return false;
}
#else
bool __get_up() const {
bool up = _up;
_up = false;
return up;
}
#endif #endif
/* set the _up flag if the next method call should be directed to /* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped Ruby object * the c++ base class rather than the wrapped Ruby object
*/ */
#ifdef __PTHREAD__ #ifdef __PTHREAD__
void __set_up() const { void __set_up() const {
pthread_mutex_lock(&__DIRECTOR__::_mutex_up); pthread_mutex_lock(&Swig::Director::_mutex_up);
__DIRECTOR__::_mutex_thread = pthread_self(); Swig::Director::_mutex_thread = pthread_self();
__DIRECTOR__::_mutex_active = true; Swig::Director::_mutex_active = true;
__DIRECTOR__::_up = true; Swig::Director::_up = true;
} }
#else #else
void __set_up() const { void __set_up() const {
__DIRECTOR__::_up = true; Swig::Director::_up = true;
} }
#endif #endif
/* acquire ownership of the wrapped Ruby object (the sense of "disown" /* acquire ownership of the wrapped Ruby object (the sense of "disown"
* is from Ruby) */ * is from Ruby) */
void __disown() const { void __disown() const {
if (!_disown) { if (!_disown) {
_disown = true; _disown = true;
} }
} }
}; };
bool __DIRECTOR__::_up = false; bool Swig::Director::_up = false;
#ifdef __PTHREAD__ #ifdef __PTHREAD__
MUTEX_INIT(__DIRECTOR__::_mutex_up); MUTEX_INIT(Swig::Director::_mutex_up);
pthread_t __DIRECTOR__::_mutex_thread; pthread_t Swig::Director::_mutex_thread;
int __DIRECTOR__::_mutex_active = false; int Swig::Director::_mutex_active = false;
#endif #endif
}
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -425,7 +425,7 @@
/* no can do... see python.cxx /* no can do... see python.cxx
%typemap(directorin) DIRECTORTYPE * { %typemap(directorin) DIRECTORTYPE * {
{ {
__DIRECTOR__$1_ltype proxy = dynamic_cast<__DIRECTOR__$1_ltype>($1_name); SwigDirector::$1_ltype proxy = dynamic_cast<SwigDirector::$1_ltype>($1_name);
if (!proxy) { if (!proxy) {
$input = SWIG_NewPointerObj((void *) $1_name, $1_descriptor, 0); $input = SWIG_NewPointerObj((void *) $1_name, $1_descriptor, 0);
} else { } else {
@ -474,9 +474,9 @@ DIRECTOROUT_TYPEMAP(bool, RTEST);
%typemap(directorout) SWIGTYPE *, %typemap(directorout) SWIGTYPE *,
SWIGTYPE &, SWIGTYPE &,
SWIGTYPE [] SWIGTYPE []
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");"; "if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");"; %typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
/* --------------------------------------------------------------------- /* ---------------------------------------------------------------------
* typedef & typemaps for VALUE (passed through unmodified and unchecked) * typedef & typemaps for VALUE (passed through unmodified and unchecked)

View file

@ -62,7 +62,7 @@ namespace std {
if (TYPE($input) == T_STRING) if (TYPE($input) == T_STRING)
$result = std::string(StringValuePtr($input)); $result = std::string(StringValuePtr($input));
else else
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected"); throw Swig::DirectorTypeMismatchException("string expected");
} }
%typemap(directorout) const string & (std::string temp) { %typemap(directorout) const string & (std::string temp) {
@ -70,7 +70,7 @@ namespace std {
temp = std::string(StringValuePtr($input)); temp = std::string(StringValuePtr($input));
$result = &temp; $result = &temp;
} else { } else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected"); throw Swig::DirectorTypeMismatchException("string expected");
} }
} }

View file

@ -350,7 +350,7 @@ class JAVA : public Language {
Swig_banner(f_directors_h); Swig_banner(f_directors_h);
Printf(f_directors_h, "#ifndef __%s_WRAP_H__\n", module); Printf(f_directors_h, "#ifndef __%s_WRAP_H__\n", module);
Printf(f_directors_h, "#define __%s_WRAP_H__\n\n", module); Printf(f_directors_h, "#define __%s_WRAP_H__\n\n", module);
Printf(f_directors_h, "class __DIRECTOR__;\n\n"); Printf(f_directors_h, "class Swig::Director;\n\n");
Printf(f_directors, "\n\n"); Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, "/* ---------------------------------------------------\n");
@ -3157,7 +3157,7 @@ class JAVA : public Language {
String *target = method_decl(decl, classname, parms, 0, 0); String *target = method_decl(decl, classname, parms, 0, 0);
String *call = Swig_csuperclass_call(0, basetype, superparms); String *call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, __DIRECTOR__(jenv) {", classname, target, call); Printf(w->def, "%s::%s: %s, Swig::Director(jenv) {", classname, target, call);
Printf(w->code, "/* NOP */\n"); Printf(w->code, "/* NOP */\n");
Printf(w->code, "}\n"); Printf(w->code, "}\n");
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
@ -3191,7 +3191,7 @@ class JAVA : public Language {
classname = Swig_class_name(n); classname = Swig_class_name(n);
{ {
Wrapper *w = NewWrapper(); Wrapper *w = NewWrapper();
Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(JNIEnv *jenv): __DIRECTOR__(jenv) {", Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(JNIEnv *jenv): Swig::Director(jenv) {",
classname, classname); classname, classname);
Printf(w->code, "}\n"); Printf(w->code, "}\n");
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);

View file

@ -1453,7 +1453,7 @@ int Language::classDirectorDisown(Node *n) {
type = NewString("void"); type = NewString("void");
String *action = NewString(""); String *action = NewString("");
Printv(action, "{\n", Printv(action, "{\n",
"__DIRECTOR__ *director = dynamic_cast<__DIRECTOR__*>(arg1);\n", "Swig::Director *director = dynamic_cast<Swig::Director *>(arg1);\n",
"if (director) director->__disown();\n", "if (director) director->__disown();\n",
"}\n", "}\n",
NULL); NULL);

View file

@ -337,7 +337,7 @@ public:
/* Swig_director_declaration() /* Swig_director_declaration()
* *
* Generate the full director class declaration, complete with base classes. * Generate the full director class declaration, complete with base classes.
* e.g. "class __DIRECTOR__myclass: public myclass, public __DIRECTOR__ {" * e.g. "class __DIRECTOR__myclass: public myclass, public Swig::Director {"
* *
*/ */
@ -346,7 +346,7 @@ public:
String *directorname = NewStringf("__DIRECTOR__%s", classname); String *directorname = NewStringf("__DIRECTOR__%s", classname);
String *base = Getattr(n, "classtype"); String *base = Getattr(n, "classtype");
String *declaration = Swig_class_declaration(n, directorname); String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, ": public %s, public __DIRECTOR__ {\n", base); Printf(declaration, ": public %s, public Swig::Director {\n", base);
Delete(classname); Delete(classname);
Delete(directorname); Delete(directorname);
return declaration; return declaration;
@ -848,8 +848,8 @@ public:
if (CPlusPlus && directorsEnabled()) { if (CPlusPlus && directorsEnabled()) {
if (!is_smart_pointer()) { if (!is_smart_pointer()) {
if (/*directorbase &&*/ hasVirtual && !constructor && isVirtual) { if (/*directorbase &&*/ hasVirtual && !constructor && isVirtual) {
Wrapper_add_local(f, "director", "__DIRECTOR__ *director = 0"); Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = dynamic_cast<__DIRECTOR__*>(arg1);\n"); Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
Printf(f->code, "if (director && (director->__get_self()==argv[0])) director->__set_up();\n"); Printf(f->code, "if (director && (director->__get_self()==argv[0])) director->__set_up();\n");
} }
} }
@ -1627,9 +1627,9 @@ public:
String *mangle = SwigType_manglestr(ptype); String *mangle = SwigType_manglestr(ptype);
if (target) { if (target) {
String *director = NewStringf("director_%s", mangle); String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "__DIRECTOR__ *", director, "= 0", NIL); Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL); Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL);
Printf(wrap_args, "%s = dynamic_cast<__DIRECTOR__*>(%s);\n", director, nonconst); Printf(wrap_args, "%s = dynamic_cast<Swig::Director *>(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director); Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(wrap_args, "} else {\n"); Printf(wrap_args, "} else {\n");
@ -1838,7 +1838,7 @@ public:
0, 0); 0, 0);
call = Swig_csuperclass_call(0, basetype, superparms); call = Swig_csuperclass_call(0, basetype, superparms);
Printf( w->def, Printf( w->def,
"%s::%s: %s, __DIRECTOR__(self, __disown) { }", "%s::%s: %s, Swig::Director(self, __disown) { }",
classname, target, call ); classname, target, call );
Delete(target); Delete(target);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
@ -1871,7 +1871,7 @@ public:
classname = Swig_class_name(n); classname = Swig_class_name(n);
{ {
Wrapper *w = NewWrapper(); Wrapper *w = NewWrapper();
Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(CAML_VALUE self, int __disown): __DIRECTOR__(self, __disown) { }", classname, classname); Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(CAML_VALUE self, int __disown): Swig::Director(self, __disown) { }", classname, classname);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
DelWrapper(w); DelWrapper(w);
} }

View file

@ -78,7 +78,7 @@ String *Swig_class_name(Node *n) {
/* Swig_director_declaration() /* Swig_director_declaration()
* *
* Generate the full director class declaration, complete with base classes. * Generate the full director class declaration, complete with base classes.
* e.g. "class __DIRECTOR__myclass: public myclass, public __DIRECTOR__ {" * e.g. "class __DIRECTOR__myclass: public myclass, public Swig::Director {"
* *
*/ */
@ -87,7 +87,7 @@ String *Swig_director_declaration(Node *n) {
String *directorname = NewStringf("__DIRECTOR__%s", classname); String *directorname = NewStringf("__DIRECTOR__%s", classname);
String *base = Getattr(n, "classtype"); String *base = Getattr(n, "classtype");
String *declaration = Swig_class_declaration(n, directorname); String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, ": public %s, public __DIRECTOR__ {\n", base); Printf(declaration, ": public %s, public Swig::Director {\n", base);
Delete(classname); Delete(classname);
Delete(directorname); Delete(directorname);
return declaration; return declaration;
@ -451,7 +451,7 @@ public:
Swig_banner(f_directors_h); Swig_banner(f_directors_h);
Printf(f_directors_h, "#ifndef __%s_WRAP_H__\n", module); Printf(f_directors_h, "#ifndef __%s_WRAP_H__\n", module);
Printf(f_directors_h, "#define __%s_WRAP_H__\n\n", module); Printf(f_directors_h, "#define __%s_WRAP_H__\n\n", module);
Printf(f_directors_h, "class __DIRECTOR__;\n\n"); Printf(f_directors_h, "class Swig::Director;\n\n");
Swig_insert_file("director.swg", f_directors); Swig_insert_file("director.swg", f_directors);
Printf(f_directors, "\n\n"); Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, "/* ---------------------------------------------------\n");
@ -870,8 +870,8 @@ public:
if (directorsEnabled()) { if (directorsEnabled()) {
if (!is_smart_pointer()) { if (!is_smart_pointer()) {
if (/*directorbase &&*/ !constructor && !destructor && isVirtual) { if (/*directorbase &&*/ !constructor && !destructor && isVirtual) {
Wrapper_add_local(f, "director", "__DIRECTOR__ *director = 0"); Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = dynamic_cast<__DIRECTOR__*>(arg1);\n"); Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
Printf(f->code, "if (director && (director->__get_self()==obj0)) director->__set_up();\n"); Printf(f->code, "if (director && (director->__get_self()==obj0)) director->__set_up();\n");
} }
} }
@ -923,8 +923,8 @@ public:
if (target) unwrap = 1; if (target) unwrap = 1;
} }
if (unwrap) { if (unwrap) {
Wrapper_add_local(f, "resultdirector", "__DIRECTOR__ *resultdirector = 0"); Wrapper_add_local(f, "resultdirector", "Swig::Director *resultdirector = 0");
Printf(f->code, "resultdirector = dynamic_cast<__DIRECTOR__*>(result);\n"); Printf(f->code, "resultdirector = dynamic_cast<Swig::Director *>(result);\n");
Printf(f->code, "if (resultdirector) {\n"); Printf(f->code, "if (resultdirector) {\n");
Printf(f->code, " resultobj = resultdirector->__get_self();\n"); Printf(f->code, " resultobj = resultdirector->__get_self();\n");
Printf(f->code, " Py_INCREF(resultobj);\n"); Printf(f->code, " Py_INCREF(resultobj);\n");
@ -1413,9 +1413,9 @@ public:
String *mangle = SwigType_manglestr(ptype); String *mangle = SwigType_manglestr(ptype);
if (target) { if (target) {
String *director = NewStringf("director_%s", mangle); String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "__DIRECTOR__ *", director, "= 0", NIL); Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "PyObject *", source, "= 0", NIL); Wrapper_add_localv(w, source, "PyObject *", source, "= 0", NIL);
Printf(wrap_args, "%s = dynamic_cast<__DIRECTOR__*>(%s);\n", director, nonconst); Printf(wrap_args, "%s = dynamic_cast<Swig::Director *>(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director); Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(wrap_args, "} else {\n"); Printf(wrap_args, "} else {\n");
@ -1458,7 +1458,7 @@ public:
/* direct call to superclass if _up is set */ /* direct call to superclass if _up is set */
Printf(w->code, "if (__get_up()) {\n"); Printf(w->code, "if (__get_up()) {\n");
if (pure_virtual) { if (pure_virtual) {
Printf(w->code, "throw SWIG_DIRECTOR_PURE_VIRTUAL_EXCEPTION();\n"); Printf(w->code, "throw Swig::DirectorPureVirtualException();\n");
} else { } else {
if (is_void) { if (is_void) {
Printf(w->code, "%s;\n", Swig_method_call(super,l)); Printf(w->code, "%s;\n", Swig_method_call(super,l));
@ -1509,7 +1509,7 @@ public:
if (outputs > 1) { if (outputs > 1) {
Wrapper_add_local(w, "output", "PyObject *output"); Wrapper_add_local(w, "output", "PyObject *output");
Printf(w->code, "if (!PyTuple_Check(result)) {\n"); Printf(w->code, "if (!PyTuple_Check(result)) {\n");
Printf(w->code, "throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Python method failed to return a tuple.\");\n"); Printf(w->code, "throw Swig::DirectorTypeMismatchException(\"Python method failed to return a tuple.\");\n");
Printf(w->code, "}\n"); Printf(w->code, "}\n");
} }
@ -1636,7 +1636,7 @@ public:
String *basetype = Getattr(parent, "classtype"); String *basetype = Getattr(parent, "classtype");
String *target = method_decl(decl, classname, parms, 0, 0); String *target = method_decl(decl, classname, parms, 0, 0);
call = Swig_csuperclass_call(0, basetype, superparms); call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, __DIRECTOR__(self, __disown) { }", classname, target, call); Printf(w->def, "%s::%s: %s, Swig::Director(self, __disown) { }", classname, target, call);
Delete(target); Delete(target);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
Delete(call); Delete(call);
@ -1666,7 +1666,7 @@ public:
classname = Swig_class_name(n); classname = Swig_class_name(n);
{ {
Wrapper *w = NewWrapper(); Wrapper *w = NewWrapper();
Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(PyObject* self, int __disown): __DIRECTOR__(self, __disown) { }", classname, classname); Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(PyObject* self, int __disown): Swig::Director(self, __disown) { }", classname, classname);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
DelWrapper(w); DelWrapper(w);
} }

View file

@ -81,7 +81,7 @@ static String *Swig_class_name(Node *n) {
/* Swig_director_declaration() /* Swig_director_declaration()
* *
* Generate the full director class declaration, complete with base classes. * Generate the full director class declaration, complete with base classes.
* e.g. "class __DIRECTOR__myclass: public myclass, public __DIRECTOR__ {" * e.g. "class __DIRECTOR__myclass: public myclass, public Swig::Director {"
* *
*/ */
@ -90,7 +90,7 @@ static String *Swig_director_declaration(Node *n) {
String *directorname = NewStringf("__DIRECTOR__%s", classname); String *directorname = NewStringf("__DIRECTOR__%s", classname);
String *base = Getattr(n, "classtype"); String *base = Getattr(n, "classtype");
String *declaration = Swig_class_declaration(n, directorname); String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, " : public %s, public __DIRECTOR__ {\n", base); Printf(declaration, " : public %s, public Swig::Director {\n", base);
Delete(classname); Delete(classname);
Delete(directorname); Delete(directorname);
return declaration; return declaration;
@ -672,7 +672,7 @@ public:
Swig_banner(f_directors_h); Swig_banner(f_directors_h);
Printf(f_directors_h, "#ifndef __%s_WRAP_H__\n", module); Printf(f_directors_h, "#ifndef __%s_WRAP_H__\n", module);
Printf(f_directors_h, "#define __%s_WRAP_H__\n\n", module); Printf(f_directors_h, "#define __%s_WRAP_H__\n\n", module);
Printf(f_directors_h, "class __DIRECTOR__;\n\n"); Printf(f_directors_h, "class Swig::Director;\n\n");
Swig_insert_file("director.swg", f_directors); Swig_insert_file("director.swg", f_directors);
Printf(f_directors, "\n\n"); Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, "/* ---------------------------------------------------\n");
@ -1259,8 +1259,8 @@ public:
if (directorsEnabled()) { if (directorsEnabled()) {
if (!is_smart_pointer()) { if (!is_smart_pointer()) {
if (/*directorbase &&*/ !constructor && !destructor && isVirtual) { if (/*directorbase &&*/ !constructor && !destructor && isVirtual) {
Wrapper_add_local(f, "director", "__DIRECTOR__ *director = 0"); Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = dynamic_cast<__DIRECTOR__*>(arg1);\n"); Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
Printf(f->code, "if (director && (director->__get_self() == self)) director->__set_up();\n"); Printf(f->code, "if (director && (director->__get_self() == self)) director->__set_up();\n");
} }
} }
@ -1312,8 +1312,8 @@ public:
if (target) unwrap = true; if (target) unwrap = true;
} }
if (unwrap) { if (unwrap) {
Wrapper_add_local(f, "resultdirector", "__DIRECTOR__ *resultdirector = 0"); Wrapper_add_local(f, "resultdirector", "Swig::Director *resultdirector = 0");
Printf(f->code, "resultdirector = dynamic_cast<__DIRECTOR__*>(result);\n"); Printf(f->code, "resultdirector = dynamic_cast<Swig::Director *>(result);\n");
Printf(f->code, "if (resultdirector) {\n"); Printf(f->code, "if (resultdirector) {\n");
Printf(f->code, " vresult = resultdirector->__get_self();\n"); Printf(f->code, " vresult = resultdirector->__get_self();\n");
Printf(f->code, "} else {\n"); Printf(f->code, "} else {\n");
@ -2100,7 +2100,7 @@ public:
String *basetype = Getattr(parent, "classtype"); String *basetype = Getattr(parent, "classtype");
String *target = method_decl(decl, classname, parms, 0, 0); String *target = method_decl(decl, classname, parms, 0, 0);
call = Swig_csuperclass_call(0, basetype, superparms); call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, __DIRECTOR__(self, __disown) { }", classname, target, call); Printf(w->def, "%s::%s: %s, Swig::Director(self, __disown) { }", classname, target, call);
Delete(target); Delete(target);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
Delete(call); Delete(call);
@ -2126,7 +2126,7 @@ public:
Wrapper *w; Wrapper *w;
classname = Swig_class_name(n); classname = Swig_class_name(n);
w = NewWrapper(); w = NewWrapper();
Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(VALUE self, bool __disown) : __DIRECTOR__(self, __disown) { }", classname, classname); Printf(w->def, "__DIRECTOR__%s::__DIRECTOR__%s(VALUE self, bool __disown) : Swig::Director(self, __disown) { }", classname, classname);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
DelWrapper(w); DelWrapper(w);
Printf(f_directors_h, " __DIRECTOR__%s(VALUE self, bool __disown = true);\n", classname); Printf(f_directors_h, " __DIRECTOR__%s(VALUE self, bool __disown = true);\n", classname);
@ -2165,7 +2165,7 @@ public:
// Function body // Function body
Printf(body->def, "VALUE %s(VALUE data) {\n", bodyName); Printf(body->def, "VALUE %s(VALUE data) {\n", bodyName);
Wrapper_add_localv(body, "args", "swig_body_args *", "args", "= reinterpret_cast<swig_body_args *>(data)", NIL); Wrapper_add_localv(body, "args", "Swig::body_args *", "args", "= reinterpret_cast<Swig::body_args *>(data)", NIL);
Wrapper_add_localv(body, "result", "VALUE", "result", "= Qnil", NIL); Wrapper_add_localv(body, "result", "VALUE", "result", "= Qnil", NIL);
Printf(body->code, "%s++;\n", depthCountName, NIL); Printf(body->code, "%s++;\n", depthCountName, NIL);
Printv(body->code, "result = rb_funcall2(args->recv, args->id, args->argc, args->argv);\n", NIL); Printv(body->code, "result = rb_funcall2(args->recv, args->id, args->argc, args->argv);\n", NIL);
@ -2183,7 +2183,7 @@ public:
Printv(rescue->code, "}", NIL); Printv(rescue->code, "}", NIL);
// Main code // Main code
Wrapper_add_localv(w, "args", "swig_body_args", "args", NIL); Wrapper_add_localv(w, "args", "Swig::body_args", "args", NIL);
Printv(w->code, "args.recv = __get_self();\n", NIL); Printv(w->code, "args.recv = __get_self();\n", NIL);
Printf(w->code, "args.id = rb_intern(\"%s\");\n", methodName); Printf(w->code, "args.id = rb_intern(\"%s\");\n", methodName);
Printf(w->code, "args.argc = %d;\n", argc); Printf(w->code, "args.argc = %d;\n", argc);
@ -2374,9 +2374,9 @@ public:
String *mangle = SwigType_manglestr(parameterType); String *mangle = SwigType_manglestr(parameterType);
if (target) { if (target) {
String *director = NewStringf("director_%s", mangle); String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "__DIRECTOR__ *", director, "= 0", NIL); Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL); Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL);
Printf(wrap_args, "%s = dynamic_cast<__DIRECTOR__*>(%s);\n", director, nonconst); Printf(wrap_args, "%s = dynamic_cast<Swig::Director *>(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director); Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(wrap_args, "} else {\n"); Printf(wrap_args, "} else {\n");
@ -2417,7 +2417,7 @@ public:
/* direct call to superclass if _up is set */ /* direct call to superclass if _up is set */
Printf(w->code, "if (__get_up()) {\n"); Printf(w->code, "if (__get_up()) {\n");
if (pure_virtual) { if (pure_virtual) {
Printf(w->code, "throw SWIG_DIRECTOR_PURE_VIRTUAL_EXCEPTION();\n"); Printf(w->code, "throw Swig::DirectorPureVirtualException();\n");
} else { } else {
if (is_void) { if (is_void) {
Printf(w->code, "%s;\n", Swig_method_call(super,l)); Printf(w->code, "%s;\n", Swig_method_call(super,l));
@ -2448,7 +2448,7 @@ public:
if (outputs > 1) { if (outputs > 1) {
Wrapper_add_local(w, "output", "VALUE output"); Wrapper_add_local(w, "output", "VALUE output");
Printf(w->code, "if (TYPE(result) != T_ARRAY) {\n"); Printf(w->code, "if (TYPE(result) != T_ARRAY) {\n");
Printf(w->code, "throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Ruby method failed to return an array.\");\n"); Printf(w->code, "throw Swig::DirectorTypeMismatchException(\"Ruby method failed to return an array.\");\n");
Printf(w->code, "}\n"); Printf(w->code, "}\n");
} }

View file

@ -715,7 +715,7 @@ Swig_ConstructorToFunction(Node *n, String *classname,
* create a director instance (there's no way to create a normal * create a director instance (there's no way to create a normal
* instance). if any of the pure virtual methods haven't been * instance). if any of the pure virtual methods haven't been
* implemented in the target language, calls to those methods will * implemented in the target language, calls to those methods will
* generate SWIG_DIRECTOR_PURE_VIRTUAL exceptions. * generate Swig::DirectorPureVirtualException exceptions.
*/ */
Printv(action, Swig_cresult(type, "result", director_call), NIL); Printv(action, Swig_cresult(type, "result", director_call), NIL);
} else { } else {