1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * This file contains support for director classes that proxy
8 * method calls from C++ to Ocaml extensions.
10 * ----------------------------------------------------------------------------- */
17 /* base class for director exceptions */
18 class DirectorException {
22 DirectorException(const char* msg="") {
24 const char *getMessage() const {
25 return swig_msg.c_str();
27 virtual ~DirectorException() {}
30 /* type mismatch in the return value from a python method call */
31 class DirectorTypeMismatchException : public Swig::DirectorException {
33 DirectorTypeMismatchException(const char* msg="") {
37 /* any python exception that occurs during a director method call */
38 class DirectorMethodException : public Swig::DirectorException {};
40 /* attempt to call a pure virtual method via a director method */
41 class DirectorPureVirtualException : public Swig::DirectorException {
43 DirectorPureVirtualException(const char* msg="") {
46 static void raise(const char *msg) {
47 throw DirectorPureVirtualException(msg);
51 /* simple thread abstraction for pthreads on win32 */
54 #if defined(_WIN32) || defined(__WIN32__)
55 #define pthread_mutex_lock EnterCriticalSection
56 #define pthread_mutex_unlock LeaveCriticalSection
57 #define pthread_mutex_t CRITICAL_SECTION
58 #define MUTEX_INIT(var) CRITICAL_SECTION var
61 #define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
65 /* director base class */
68 /* pointer to the wrapped ocaml object */
70 /* flag indicating whether the object is owned by ocaml or c++ */
71 mutable bool swig_disown_flag;
74 /* wrap a ocaml object, optionally taking ownership */
75 Director(CAML_VALUE self) : swig_self(self), swig_disown_flag(false) {
76 register_global_root(&swig_self);
79 /* discard our reference at destruction */
81 remove_global_root(&swig_self);
83 // Disown is safe here because we're just divorcing a reference that
87 /* return a pointer to the wrapped ocaml object */
88 CAML_VALUE swig_get_self() const {
92 /* acquire ownership of the wrapped ocaml object (the sense of "disown"
94 void swig_disown() const {
95 if (!swig_disown_flag) {
96 swig_disown_flag=true;
97 callback(*caml_named_value("caml_obj_disown"),swig_self);
103 #endif /* __cplusplus */